ESP32-S3: How to set wake_stub from within wake stub (and go to deep sleep)

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

ESP32-S3: How to set wake_stub from within wake stub (and go to deep sleep)

Postby PeteDD » Sat Nov 25, 2023 9:14 pm

I am having trouble finding code that works for ESP32-S3 to set the wake-stub, from within a wake-stub, and then re-enter deep sleep. I could really use a little help with the exact code (including the necessary includes). I have struggled with this for many days now.

The code that I have working for the ESP32 does not work for the ESP32-S3. On the ESP32-S3, the next wake just does a reboot to setup() (in arduino framework)

Code: Select all

   // THIS CODE WORKS ON ESP32 BUT NOT ON ESP32-S3
   // Set the pointer of the wake stub function.
    REG_WRITE(RTC_ENTRY_ADDR_REG, (uint32_t)&wake_stub);
    // Go to sleep.
    CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
    SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
    // A few CPU cycles may be necessary for the sleep to start...
    while (true) {
        ;
    }
I have found an example for the ESP32-S3 here https://github.com/espressif/esp-idf/bl ... ake_stub.c but it uses set_rtc_memory_crc which I cannot find (or what I find, I can't get to run).

The TRM https://www.espressif.com/sites/default ... ual_en.pdf in section 10.6: RTC Boot, on page 565 provides the following, but I just don't understand how exactly to write the code. (I've only been programming uProcessors since the days of the Intel 8080, but this is stumping me).

Could someone help? Please and Thank You.

Code: Select all

The wakeup time from Deep-sleep mode is much longer, compared to Light-sleep and Modem-sleep modes,
because the ROMs and RAMs are both powered down in this case, and the CPU needs more time for SPI
booting (data-copying from the flash). However, it’s worth noting that both RTC fast memory and RTC slow
memory remain powered up in the Deep-sleep mode. Therefore, users can store codes (so called “deep sleep
wake stub” of up to 8 KB) either in RTC fast memory or RTC slow memory, which doesn’t require the
above-mentioned SPI booting, thus speeding up the wakeup process.
Method one: Boot using RTC slow memory
1. Set RTC_CNTL_PROCPU_STAT_VECTOR_SEL to 0.
2. Send the chip into sleep.
3. After the CPU is powered up, the reset vector starts resetting from 0x50000000 instead of 0x40000400,
which does not involve any SPI booting. The codes stored in RTC slow memory starts running immediately
after the CPU reset. The code stored in the RTC slow memory only needs to be partially initialized in a C
environment.
Method two: Boot using RTC fast memory
1. Set RTC_CNTL_PROCPU_STAT_VECTOR_SEL to 1.
2. Calculate CRC for the RTC fast memory, and save the result in RTC_CNTL_RTC_STORE7_REG[31:0].
3. Set RTC_CNTL_RTC_STORE6_REG[31:0] to the entry address of RTC fast memory.
4. Send the chip into sleep.
5. ROM unpacking and some of the initialization starts after the CPU is powered up. After that, the CRC for
the RTC fast memory will be calculated again. If the result matches with register
RTC_CNTL_RTC_STORE7_REG[31:0], the CPU jumps to the entry address.
The boot flow is shown in Figure 10-11.
My wake stub is currently configured to load into RTC fast memory, using the "first method" from the ESP32-S3 Programming Guide, Deep Sleep Wake Stubs, Loading Into RTC Memory https://docs.espressif.com/projects/esp ... rtc-memory

Code: Select all

static void RTC_IRAM_ATTR wake_stub()
{
}
So... I should be using "Method two: Boot using RTC fast memory" from the TCM excerpt above. Turning those steps into code is eluding me

PeteDD
Posts: 45
Joined: Sat Sep 24, 2022 5:22 pm

Re: ESP32-S3: How to set wake_stub from within wake stub (and go to deep sleep)

Postby PeteDD » Tue Nov 28, 2023 11:41 pm

Well, I guess I stumped everyone once again...

Still like to know how folks did this before ESP-IDF 5.1...

I was able to load the ESP-IDF 5.1 with Arduino 3.0 today even though it is not released yet (see how I was able to do that here: [see how I was able to do that here:]https://github.com/espressif/arduino-esp32/issues/8924 [/url] and get things working.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 84 guests