ESP32: Memory retained on Reset
Posted: Mon Aug 04, 2025 11:14 am
Hi,
I like to store a value in memory that is retained after a reset. The value is used to distinguish between a power-on reset and a (manual) hardware reset. The succession of multiple resets is taken by the application to enter a special configuration mode.
Something like https://github.com/datacute/DoubleResetDetector , but then for ESP32.
For this, the variable attribute __NOINIT_ATTR and RTC_NOINIT_ATTR are available.
However, after some testing, I found that the variables stored at a .noinit segment only keep value after a software restart
but [b]contain some pseudo random data after HW reset[/b].
The question is why is that?
What is different in program startup from HW-reset to an SW-reset?
I expect this Static RAM to retain its value when it remains powered.
Or is there some bootloader activity that overwrites those particular memory parts?
------
[code]
__NOINIT_ATTR uint32_t noinit_DetectFlag1; // @ 0x3FFC3D94, After reset 0x0DD08974 , overwritten by bootloader(?)
RTC_NOINIT_ATTR uint32_t noinit_DetectorFlag2; // @ 0x50000208, After reset 0x6B326EA9 , overwritten by bootloader(?)
[/code]
Running on ESP32 (Wroom32)
platform = espressif32
framework = arduino
board = nodemcu
I like to store a value in memory that is retained after a reset. The value is used to distinguish between a power-on reset and a (manual) hardware reset. The succession of multiple resets is taken by the application to enter a special configuration mode.
Something like https://github.com/datacute/DoubleResetDetector , but then for ESP32.
For this, the variable attribute __NOINIT_ATTR and RTC_NOINIT_ATTR are available.
However, after some testing, I found that the variables stored at a .noinit segment only keep value after a software restart
but [b]contain some pseudo random data after HW reset[/b].
The question is why is that?
What is different in program startup from HW-reset to an SW-reset?
I expect this Static RAM to retain its value when it remains powered.
Or is there some bootloader activity that overwrites those particular memory parts?
------
[code]
__NOINIT_ATTR uint32_t noinit_DetectFlag1; // @ 0x3FFC3D94, After reset 0x0DD08974 , overwritten by bootloader(?)
RTC_NOINIT_ATTR uint32_t noinit_DetectorFlag2; // @ 0x50000208, After reset 0x6B326EA9 , overwritten by bootloader(?)
[/code]
Running on ESP32 (Wroom32)
platform = espressif32
framework = arduino
board = nodemcu