espressif: preserve alarm.sleep_memory across software resets#10899
espressif: preserve alarm.sleep_memory across software resets#10899lzrd wants to merge 1 commit intoadafruit:10.1.xfrom
Conversation
Change the "sleep memory" linker attribute from RTC_DATA_ATTR to RTC_NOINIT_ATTR. The ESP-IDF bootloader will no longer zero-initialize sleep memory on software reset (microcontroller.reset()), watchdog, or panic resets. Added explicit clearing in alarm_sleep_memory_reset() for reset types where RTC SRAM contents are not known to be intact. Sleep memory now persists across microcontroller.reset(), watchdog, and panic resets. This matches the existing deep-sleep behavior and aligns with what the hardware already supports. Programs that only relied on the existing sleep behavior should be fine. Anyone using the new behavior should validate sleep_memory contents with a magic value and integrity check (e.g. CRC32) before trusting them. Sleep memory may contain stale data from a previous version of code.py after an autoreload or other non-zeroing software reset not planned by the programmer. Fixes adafruit#10896
|
I first made this change against main then rebased to |
|
Thanks for the PR. The PR commit was based on The docs build failed due to a temporary failure. I re-ran it to confirm that was temporary. |
|
After thinking about this some more, I would rather have this as a PR against |
|
I'll go through another build/test cycle to make sure that everything is ok. |
Change the "sleep memory" linker attribute from RTC_DATA_ATTR to RTC_NOINIT_ATTR.
Also, the ESP-IDF bootloader will no longer zero-initialize sleep memory on software reset (microcontroller.reset()), watchdog, or panic resets.
Added explicit clearing in alarm_sleep_memory_reset() for reset types where RTC SRAM contents are not known to be intact.
Sleep memory now persists across microcontroller.reset(), watchdog, and panic resets. This is now the same as existing deep-sleep behavior and aligns with what the hardware supports.
Programs that only relied on the existing sleep behavior should be fine.
Anyone using the new behavior should validate sleep_memory contents with a magic value and integrity check (e.g. CRC32) before trusting them. Sleep memory may contain stale data from a previous version of code.py after an autoreload or other non-zeroing software reset not planned by the programmer.
Behavior Pre- vs. Post- change:
microcontroller.reset()supervisor.reload()Testing
Tested on ESP32-S2 (Adafruit MagTag, 2025 version).
Manual test added at
tests/circuitpython-manual/alarm/sleep_memory_persist.pyThe test writes a CRC32-protected marker and the state of the tests to
alarm.sleep_memory, then verifies that the data survivesmicrocontroller.reset()andsupervisor.reload().Before patch:
reset: FAILAfter patch:
reset: PASS,reload: PASSFixes #10896