RTCWDT_RTC_RESET on light sleep

User avatar
CamargoF
Posts: 7
Joined: Fri Mar 19, 2021 1:31 am
Location: Brazil

RTCWDT_RTC_RESET on light sleep

Postby CamargoF » Sat Sep 21, 2024 4:04 pm

Hi folks,

I have developed a product that runs on the ESP32-S3 very well and is stable. However, when I attempted to save energy by replacing `delay()` with light sleep at the end of my `loop()`, the ESP32-S3 started rebooting, reporting an RTCWDT_RTC_RESET error.

From my research, it seems that the WDT_RTC generates a timeout to prevent the system from sleeping indefinitely due to bad programming, which is helpful. However, I haven’t been able to find a way to adjust the RTC timeout interval or reset the RTC timer.

I've noticed that people have been reporting this issue in forums since 2021, but no solution has been provided.

I would greatly appreciate any assistance.

The code I am using is:
  1.     // Sleeps 20ms on loop(), instead of delay()
  2.     esp_sleep_enable_timer_wakeup(20 * 1000);
  3.  
  4.     // Keep domains active
  5.     esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  6.     esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
  7.     esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_ON);
  8.  
  9.     // Get a nap (20ms light sleep)
  10.     esp_light_sleep_start();
Best regards

Fernando
Best regards,

CamargoF

aliarifat794
Posts: 196
Joined: Sun Jun 23, 2024 6:18 pm

Re: RTCWDT_RTC_RESET on light sleep

Postby aliarifat794 » Sun Sep 22, 2024 9:13 am

Please review the power domain settings to check if the system's memory and peripherals are correctly powered during light sleep.

User avatar
CamargoF
Posts: 7
Joined: Fri Mar 19, 2021 1:31 am
Location: Brazil

Re: RTCWDT_RTC_RESET on light sleep

Postby CamargoF » Sun Sep 22, 2024 5:27 pm

As I mentioned before, the product was running without any problem, until I tried to activate the light sleep.
The power supply looks fine.
I was not able to detect any glitch.
Best regards,

CamargoF

User avatar
CamargoF
Posts: 7
Joined: Fri Mar 19, 2021 1:31 am
Location: Brazil

Re: RTCWDT_RTC_RESET on light sleep

Postby CamargoF » Mon Sep 23, 2024 1:09 am

I tried to add the call for light sleep, from ESP-IDF, but also fails.
  1. #include <esp_sleep.h>
  2.  
  3. #ifndef  RTC_WDT_STG_SEL_OFF
  4. #   define RTC_WDT_STG_SEL_OFF             0
  5. #endif
  6.  
  7. #ifndef  RTC_WDT_STG_SEL_INT
  8. #   define RTC_WDT_STG_SEL_INT             1
  9. #endif
  10.  
  11. #ifndef  RTC_WDT_STG_SEL_RESET_CPU
  12. #   define RTC_WDT_STG_SEL_RESET_CPU       2
  13. #endif
  14.  
  15. #ifndef  RTC_WDT_STG_SEL_RESET_SYSTEM
  16. #   define RTC_WDT_STG_SEL_RESET_SYSTEM    3
  17. #endif
  18.  
  19. #ifndef  RTC_WDT_STG_SEL_RESET_RTC
  20. #   define RTC_WDT_STG_SEL_RESET_RTC       4
  21. #endif
  22.  
  23. #include "rtc_wdt.h"                           // from ..\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc
  24.  
  25.  
  26.  
  27. void watchdogResetRTCWDT() {
  28.   // rtc_wdt_feed() = linha 130 de C:\Users\Projetos\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc\rtc_wdt.h
  29.   // rtc_wdt_feed(); // FAILED
  30.  
  31.   // Trying to access the register directly
  32.   // Extract from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
  33.   REG_SET_BIT(RTC_CNTL_WDTFEED_REG, RTC_CNTL_WDT_FEED);
  34.   // FAILED}
  35.  
  36. /*
  37.  * @brief   Disable the RTC watchdog (RTCWDG).
  38.  */
  39. void watchdogEndRTCWDT() {
  40.   // rtc_wdt_disable() = line 123 of ...\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc\rtc_wdt.h
  41.   // rtc_wdt_disable(); // FAILED
  42.  
  43.   // WRITE_PERI_REG(RTC_CNTL_RTC_WDTCONFIG0_REG, 0);
  44.  
  45.   // Trying to access the register directly
  46.   // Extract from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
  47.   REG_SET_BIT(RTC_CNTL_WDTFEED_REG, RTC_CNTL_WDT_FEED);
  48.   myRtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_OFF);
  49.   myRtc_wdt_set_stage(RTC_WDT_STAGE1, RTC_WDT_STAGE_ACTION_OFF);
  50.   myRtc_wdt_set_stage(RTC_WDT_STAGE2, RTC_WDT_STAGE_ACTION_OFF);
  51.   myRtc_wdt_set_stage(RTC_WDT_STAGE3, RTC_WDT_STAGE_ACTION_OFF);
  52.   REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN);
  53.   REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_EN);
  54. }
  55.  
  56. /**
  57.  * @brief   Copied rtc_wdt_set_stage() from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
  58.  */
  59. esp_err_t myRtc_wdt_set_stage(rtc_wdt_stage_t stage, rtc_wdt_stage_action_t stage_sel)
  60. {
  61.     if (stage > 3 || stage_sel > 4) {
  62.         return ESP_ERR_INVALID_ARG;
  63.     }
  64.     if (stage == RTC_WDT_STAGE0) {
  65.         REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG0, stage_sel);
  66.     } else if (stage == RTC_WDT_STAGE1) {
  67.         REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG1, stage_sel);
  68.     } else if (stage == RTC_WDT_STAGE2) {
  69.         REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG2, stage_sel);
  70.     } else {
  71.         REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG3, stage_sel);
  72.     }
  73.  
  74.     return ESP_OK;
  75. }
  76.  
Even calling watchdogResetRTCWDT() or watchdogEndRTCWDT() before esp_light_sleep_start(), the RTCWDT_RESET continues.

I have no other idea about what to do. I appreciate any help.

Best regards,

Fernando
Best regards,

CamargoF

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

Re: RTCWDT_RTC_RESET on light sleep

Postby boarchuz » Mon Sep 23, 2024 4:02 am

Can you increase the sleep time (eg. 5s) to determine if it's having issues while asleep or upon wakeup?

Can you share more of your code, especially immediately after esp_light_sleep_start?

Can you add some tracing on the very next line after esp_light_sleep_start? Ideally simple like toggling a GPIO but serial output might work.

Are you certain there's no other serial output? Even if you increase logging level?

Who is online

Users browsing this forum: No registered users and 69 guests