Skip to content

Commit

Permalink
Merge pull request #48 from brentru/update-for-esp32-bsp-3
Browse files Browse the repository at this point in the history
Update for ESP32 IDF v5.x+
  • Loading branch information
brentru authored Oct 20, 2023
2 parents d7e74d4 + e2eeeb9 commit c086c4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit SleepyDog Library
version=1.6.4
version=1.6.5
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library to use the watchdog timer for system reset and low power sleep.
Expand Down
16 changes: 14 additions & 2 deletions utility/WatchdogESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c086c4f

Please sign in to comment.