Page 1 of 1

ESP32C2 data retention between deep-sleep resets

Posted: Wed Jan 28, 2026 10:53 am
by mirco.franchetti
Hi!

I'm using deep sleep in my ESP32C2 application and I need to keep one measly uint16_t between resets.
RTC_DATA_ATTR seem to not work.
I read the reference manual and there seem to be 8-32bit registers that persist (RTC_CNTL_STORE0..7_REG) but in ESP-IDF's rtc.h I see they are all used by ESP-IDF and I think I'm out of luck.


  1. If I'm wrong, how can i access said registers correctly?
  2. If I'm right, what are my possibilities besides NVS? It's a low power application that could wake more times a day and save this number each time.

Re: ESP32C2 data retention between deep-sleep resets

Posted: Fri Jan 30, 2026 2:01 am
by ESP-Marius
As far as I see you are correct. Those registers dont have any available space you can use without conflicts with IDF functionality.

The other way I could think of is to "abuse" other RTC related registers. One example would be RTC_CNTL_WDTCONFIG4_REG which has the stage 3 hold time for the RTC WDT. It should be kept over sleep, and at the moment I do not think IDF ever use/touch this register. (Just remember to turn of the write protect, RTC_CNTL_WDTWPROTECT_REG, before storing anything here).

There is no guarantee that this register will continue to stay unused or that IDF wont suddenly decide one day to clear the value here when initializing the watchdog, but for now I think it should work. You can try it out. For a personal project something like this would probably work, but I would not recommend doing this for anything serious.

Re: ESP32C2 data retention between deep-sleep resets

Posted: Fri Jan 30, 2026 2:13 am
by boarchuz
FWIW I have long abused the RTC_x_DATE_REG registers on ESP32 without issue. They don't seem to have any purpose and are RW.

Re: ESP32C2 data retention between deep-sleep resets

Posted: Fri Jan 30, 2026 2:45 am
by ESP-Marius
FWIW I have long abused the RTC_x_DATE_REG registers on ESP32 without issue. They don't seem to have any purpose and are RW.
Yeah, that is another good option, but DATE_REGs are also occasionally used for "patching" stuff. So if IDF ever does need another RTC STORE register this is probably the one that will be used. S3 already seems to have done so with RTC_CNTL_SLAVE_PD.

Either way, both will probably work fine, but use with care!

Re: ESP32C2 data retention between deep-sleep resets

Posted: Fri Jan 30, 2026 7:10 am
by mirco.franchetti
Thank you!