Skip to content

Commit c086c4f

Browse files
authored
Merge pull request #48 from brentru/update-for-esp32-bsp-3
Update for ESP32 IDF v5.x+
2 parents d7e74d4 + e2eeeb9 commit c086c4f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit SleepyDog Library
2-
version=1.6.4
2+
version=1.6.5
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino library to use the watchdog timer for system reset and low power sleep.

utility/WatchdogESP32.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@ int WatchdogESP32::enable(int maxPeriodMS) {
1616
if (maxPeriodMS < 0)
1717
return 0;
1818

19-
// ESP32 expects TWDT in seconds
19+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
20+
// Initialize the wdt configuration for ESP-IDF v5.x and above
21+
esp_task_wdt_config_t wdt_config = {
22+
.timeout_ms = (uint32_t)maxPeriodMS,
23+
.idle_core_mask = 0, // Subscribe to the idle task on the APP CPU
24+
.trigger_panic = true,
25+
};
26+
// TWDT already initialized by the RTOS, reconfigure it
27+
esp_err_t err = esp_task_wdt_reconfigure(&wdt_config);
28+
#else
29+
// IDF V4.x and below expect TWDT in seconds
2030
uint32_t maxPeriod = maxPeriodMS / 1000;
2131
// Enable the TWDT and execute the esp32 panic handler when TWDT times out
2232
esp_err_t err = esp_task_wdt_init(maxPeriod, true);
33+
#endif
34+
2335
if (err != ESP_OK)
24-
return 0; // Initialization failed due to lack of memory
36+
return 0; // Failed to initialize TWDT
2537

2638
// NULL to subscribe the current running task to the TWDT
2739
err = esp_task_wdt_add(NULL);

0 commit comments

Comments
 (0)