diff --git a/library.properties b/library.properties index ebd907a..81d6f9a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit SleepyDog Library -version=1.6.4 +version=1.6.5 author=Adafruit maintainer=Adafruit sentence=Arduino library to use the watchdog timer for system reset and low power sleep. diff --git a/utility/WatchdogESP32.cpp b/utility/WatchdogESP32.cpp index 006fc34..2b983eb 100644 --- a/utility/WatchdogESP32.cpp +++ b/utility/WatchdogESP32.cpp @@ -16,12 +16,24 @@ int WatchdogESP32::enable(int maxPeriodMS) { if (maxPeriodMS < 0) return 0; - // ESP32 expects TWDT in seconds +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) + // Initialize the wdt configuration for ESP-IDF v5.x and above + esp_task_wdt_config_t wdt_config = { + .timeout_ms = (uint32_t)maxPeriodMS, + .idle_core_mask = 0, // Subscribe to the idle task on the APP CPU + .trigger_panic = true, + }; + // TWDT already initialized by the RTOS, reconfigure it + esp_err_t err = esp_task_wdt_reconfigure(&wdt_config); +#else + // IDF V4.x and below expect TWDT in seconds uint32_t maxPeriod = maxPeriodMS / 1000; // Enable the TWDT and execute the esp32 panic handler when TWDT times out esp_err_t err = esp_task_wdt_init(maxPeriod, true); +#endif + if (err != ESP_OK) - return 0; // Initialization failed due to lack of memory + return 0; // Failed to initialize TWDT // NULL to subscribe the current running task to the TWDT err = esp_task_wdt_add(NULL);