Copyright ©

Mongoose OS Forum


ESP32 not retaining RTC_DATA_ATTR variables when waking from deep sleep

JeanLouisJeanLouis Canada
edited October 6 in Mongoose OS

I have an ESP32 Huzzah32 dev board that I am experimenting with deep sleep functionality. The module can be put to sleep and successfully wakes on button press, but the variables stored as RTC_DATA_ATTR get reset every time the device wakes from sleep. In particular, I am implementing a counter to track how many times a button is clicked to detect whether the user single-clicked or double-clicked to wake the device from sleep (so different actions can be performed for each case), but the counter always gets reset to 0 even though the docs state that it should remember its state.

Also, the wake_reason is always returned as ESP_DEEP_SLEEP_WAKEUP_UNDEFINED, so somehow the fact that it is being woken by a button press (which should return ESP_DEEP_SLEEP_WAKEUP_EXT0 or ESP_DEEP_SLEEP_WAKEUP_EXT1) is being ignored. I suspect this is related to the problem I have of the RTC_DATA_ATTR being reset too.


  • SOLVED: According to the technical support at Espressif, this is due to a hardware bug with the Rev 0 ESP-32 modules, or more specifically, the flash memory. They don't start up fast enough, which causes a "flash read err, 1000" when waking from deep sleep, which then triggers a "TG0WDT_SYS_RESET". The workaround is to introduce a delay when waking from deep sleep by setting the following:


    WARNING: When setting this, make sure there is one, and ONLY one, blank space at the beginning of the line. It took me forever to figure this out. See other thread here:

Sign In or Register to comment.