[SOLVED] RTC Memory Corruption after Deep Sleep

chrismerck
Posts: 76
Joined: Tue May 29, 2018 8:00 pm

[SOLVED] RTC Memory Corruption after Deep Sleep

Postby chrismerck » Mon Feb 25, 2019 9:46 pm

We've observed a strange behavior on 2 units of ESP32 dev kits where the RTC memory becomes corrupted after deep sleep.

We are still working to isolate the problem, and hope to provide an example project that shows the issue, but for now I just want to share what we are seeing:

Code: Select all

/* application writes to RTC memory */
*((uint32_t*)(0x50001FF0))=0x1badbabe
ESP_LOGI(TAG, "before: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "before: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "before: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "before: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));

/* deep sleep reset */
esp_deep_sleep(1000 /* 1 ms */);

/* now, from the bootloader */
ESP_LOGI(TAG, "after: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "after: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "after: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
ESP_LOGI(TAG, "after: 0x%" PRIx32, *((uint32_t*)(0x50001FF0)));
We get 0x1badbabe printed "before", as expected. But "after" is sometimes corrupted as 0x1bad3abe or similar.

The 4x "after" prints all print the same value. So it seems that the memory is getting corrupted through the reset, rather than being unreliably read. -- But there may be some caching involved?

We use RTC memory to signal a change in bootloader behavior to jump to the OTA image rather than the factory image --- so the corruption causes a bootloop!
Last edited by chrismerck on Wed Feb 27, 2019 7:39 pm, edited 1 time in total.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: RTC Memory Corruption after Deep Sleep

Postby ESP_igrr » Tue Feb 26, 2019 2:47 am

Are you calling esp_sleep_pd_config to keep RTC memory powered on in deep sleep? https://docs.espressif.com/projects/esp ... d_option_t

This is not required if you place some data into RTC memory using the linker. However if you are accessing RTC memory by absolute address, deep sleep API can not recognize this and automatically enable RTC memory. If you set log level to debug, esp_deep_sleep function should report which power domains are left in which state.

chrismerck
Posts: 76
Joined: Tue May 29, 2018 8:00 pm

Re: RTC Memory Corruption after Deep Sleep

Postby chrismerck » Wed Feb 27, 2019 7:39 pm

:facepalm: Thanks Igrr. Your quick response saved us a lot of headache!

Increasing the deep sleep time made the situation worse (as expected), and adding the following before deep_sleep totally fixed the issue:

Code: Select all

esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);

Who is online

Users browsing this forum: No registered users and 77 guests