Watchdog timer in ESP32 board manager v3.0.x

alanesq
Posts: 86
Joined: Thu Dec 14, 2017 8:38 pm

Watchdog timer in ESP32 board manager v3.0.x

Postby alanesq » Fri Jun 07, 2024 7:47 am

I have discovered that my sketches using the ESP32 watchdog timer no longer work. After some time I have believe I have figured out the fix for this and passing it on in case of help to anyone else (or if anyone has a better solution?)
also v3.0.0 seems to use a lot more memory so I have had to change my partition scheme to "minimal spiffs" for many of my sketches.

The old code I was using was:

Code: Select all

            esp_task_wdt_init(WDT_TIMEOUT, true);                      //enable panic so ESP32 restarts
            esp_task_wdt_add(NULL);                                    //add current thread to WDT watch
The new code I am using is:

Code: Select all

   
   #define WDT_TIMEOUT 10
    // ESP32 Watchdog timer -    Note: esp32 board manager v3.x.x requires different code
      #if defined ESP32
        esp_task_wdt_deinit();                  // ensure a watchdog is not already configured
        #if defined(ESP_ARDUINO_VERSION_MAJOR) && ESP_ARDUINO_VERSION_MAJOR == 3  
          // v3 board manager detected
          // Create and initialize the watchdog timer(WDT) configuration structure
            esp_task_wdt_config_t wdt_config = {
                .timeout_ms = WDT_TIMEOUT * 1000, // Convert seconds to milliseconds
                .idle_core_mask = 1 << 0,         // Monitor core 1 only
                .trigger_panic = true             // Enable panic
            };
          // Initialize the WDT with the configuration structure
            esp_task_wdt_init(&wdt_config);       // Pass the pointer to the configuration structure
            esp_task_wdt_add(NULL);               // Add current thread to WDT watch    
            esp_task_wdt_reset();                 // reset timer
        #else
          // pre v3 board manager assumed
            esp_task_wdt_init(WDT_TIMEOUT, true);                      //enable panic so ESP32 restarts
            esp_task_wdt_add(NULL);                                    //add current thread to WDT watch   
        #endif
      #endif[
/code]
Last edited by alanesq on Mon Jul 08, 2024 10:09 am, edited 1 time in total.

lbernstone
Posts: 831
Joined: Mon Jul 22, 2019 3:20 pm

Re: Watchdog timer in ESP32 board manager v3.0.x

Postby lbernstone » Fri Jun 07, 2024 9:07 pm

It sounds like you are building the sdk libraries yourself?
There are a couple entries in sdkconfig that control this:

Code: Select all

CONFIG_ESP_TASK_WDT_EN=y
CONFIG_ESP_TASK_WDT_INIT=y

alanesq
Posts: 86
Joined: Thu Dec 14, 2017 8:38 pm

Re: Watchdog timer in ESP32 board manager v3.0.x

Postby alanesq » Sat Jun 08, 2024 5:51 am

Thanks, Is there a way of setting this in the sketch as I want my sketches to work for people whichever version they have installed?

Who is online

Users browsing this forum: No registered users and 31 guests