Chapter 4. API Guides
idf_component_register if SRCS is also specified (in fact, SRCS is ignored if SRC_DIRS is speci-
fied).
Flashing from make
make flash and similar targets still work to build and flash. However, project sdkconfig no longer specifies
serial port and baud rate. Environment variables can be used to override these. See
more details.
4.5 Deep Sleep Wake Stubs
ESP32-S2 supports running a "deep sleep wake stub" when coming out of deep sleep. This function runs immediately
as soon as the chip wakes up - before any normal initialisation, bootloader, or ESP-IDF code has run. After the wake
stub runs, the SoC can go back to sleep or continue to start ESP-IDF normally.
Deep sleep wake stub code is loaded into "RTC Fast Memory"and any data which it uses must also be loaded into
RTC memory. RTC memory regions hold their contents during deep sleep.
4.5.1 Rules for Wake Stubs
Wake stub code must be carefully written:
• As the SoC has freshly woken from sleep, most of the peripherals are in reset states. The SPI flash is unmapped.
• The wake stub code can only call functions implemented in ROM or loaded into RTC Fast Memory (see below.)
• The wake stub code can only access data loaded in RTC memory. All other RAM will be unintiailised and
have random contents. The wake stub can use other RAM for temporary storage, but the contents will be
overwritten when the SoC goes back to sleep or starts ESP-IDF.
• RTC memory must include any read-only data (.rodata) used by the stub.
• Data in RTC memory is initialised whenever the SoC restarts, except when waking from deep sleep. When
waking from deep sleep, the values which were present before going to sleep are kept.
• Wake stub code is a part of the main esp-idf app. During normal running of esp-idf, functions can call the
wake stub functions or access RTC memory. It is as if these were regular parts of the app.
4.5.2 Implementing A Stub
The wake stub in esp-idf is called esp_wake_deep_sleep(). This function runs whenever the SoC wakes from
deep sleep. There is a default version of this function provided in esp-idf, but the default function is weak-linked so
if your app contains a function named esp_wake_deep_sleep() then this will override the default.
If supplying a custom wake stub, the first thing it does should be to call esp_default_wake_deep_sleep().
It is not necessary to implement esp_wake_deep_sleep() in your app in order to use deep sleep. It is only
necessary if you want to have special behaviour immediately on wake.
If you want to swap between different deep sleep stubs at runtime, it is also possible to do this by calling
the esp_set_deep_sleep_wake_stub() function. This is not necessary if you only use the default
esp_wake_deep_sleep() function.
All of these functions are declared in the esp_sleep.h header under components/esp32s2.
4.5.3 Loading Code Into RTC Memory
Wake stub code must be resident in RTC Fast Memory. This can be done in one of two ways.
The first way is to use the RTC_IRAM_ATTR attribute to place a function into RTC memory:
Espressif Systems
1299
Submit Document Feedback
Flashing with ninja or make
Release v4.4
for
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers