Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for ESP32 IDF v5.x+ #48

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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