ESP32C2 data retention between deep-sleep resets

mirco.franchetti
Posts: 2
Joined: Fri Jul 16, 2021 6:15 am

ESP32C2 data retention between deep-sleep resets

Postby mirco.franchetti » Wed Jan 28, 2026 10:53 am

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.

ESP-Marius
Espressif staff
Espressif staff
Posts: 78
Joined: Wed Oct 23, 2019 1:49 am

Re: ESP32C2 data retention between deep-sleep resets

Postby ESP-Marius » Fri Jan 30, 2026 2:01 am

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.

boarchuz
Posts: 656
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32C2 data retention between deep-sleep resets

Postby boarchuz » Fri Jan 30, 2026 2:13 am

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.

ESP-Marius
Espressif staff
Espressif staff
Posts: 78
Joined: Wed Oct 23, 2019 1:49 am

Re: ESP32C2 data retention between deep-sleep resets

Postby ESP-Marius » Fri Jan 30, 2026 2:45 am

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!

mirco.franchetti
Posts: 2
Joined: Fri Jul 16, 2021 6:15 am

Re: ESP32C2 data retention between deep-sleep resets

Postby mirco.franchetti » Fri Jan 30, 2026 7:10 am

Thank you!

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 11 guests