Watchdog timer in ESP32 board manager v3.0.x
Posted: 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:
The new code I am using is:
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
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]