From ccf67497c7ebff2af11de2f7c22f4511ef6580df Mon Sep 17 00:00:00 2001 From: Marcio Ribeiro Date: Wed, 16 Sep 2026 14:56:15 -0300 Subject: [PATCH] arch/risc-v/espressif: keep RTC backup data in DRAM without RTC memory SoCs such as the ESP32-C2 have no RTC retention memory, so RTC_DATA_ATTR cannot be used for the persistent RTC time. Place the backup data in DRAM on those chips, where the saved time does not survive deep sleep. Assisted-by: Claude:claude-opus-5 Signed-off-by: Marcio Ribeiro --- arch/risc-v/src/common/espressif/esp_rtc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/common/espressif/esp_rtc.c b/arch/risc-v/src/common/espressif/esp_rtc.c index 16c10abe401..fdddd98c764 100644 --- a/arch/risc-v/src/common/espressif/esp_rtc.c +++ b/arch/risc-v/src/common/espressif/esp_rtc.c @@ -164,9 +164,15 @@ static bool g_hr_timer_enabled = false; #endif /* CONFIG_RTC_DRIVER */ -/* Saved data for persistent RTC time */ +/* Saved data for persistent RTC time. Chips without RTC retention memory + * keep it in DRAM, so the saved time does not survive deep sleep. + */ +#ifdef SOC_RTC_MEM_SUPPORTED static RTC_DATA_ATTR struct esp_rtc_backup_s g_rtc_saved_data; +#else +static struct esp_rtc_backup_s g_rtc_saved_data; +#endif static struct esp_rtc_backup_s *g_rtc_save; /**************************************************************************** @@ -326,6 +332,7 @@ static int esp_rtc_rdtime(struct rtc_lowerhalf_s *lower, if (gmtime_r(&timer, (struct tm *)rtctime) == 0) { int errcode = get_errno(); + DEBUGASSERT(errcode > 0); rtcerr("gmtime_r failed: %d\n", errcode); @@ -949,6 +956,7 @@ int esp_rtc_driverinit(void) struct rtc_lowerhalf_s *lower = (struct rtc_lowerhalf_s *)&g_rtc_lowerhalf; int ret = rtc_initialize(0, lower); + if (ret < 0) { return ret;