Skip to content

Commit

Permalink
Enable ESP watchdog by default
Browse files Browse the repository at this point in the history
Use the ESP watchdog to detect hanging ESP and reset the firmware.
Can be disable by defining WLED_WATCHDOG_TIMOUT 0
Default timeout is 3 seconds on ESP32 and 8 seconds on ESP2688
  • Loading branch information
poelzi committed May 5, 2022
1 parent 099d2fd commit 213e3e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ void WLED::loop()
loops++;
#endif // WLED_DEBUG
toki.resetTick();

#if WLED_WATCHDOG_TIMEOUT > 0
// we finished our mainloop, reset the watchdog timer
#ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset();
#else
ESP.wdtFeed();
#endif
#endif
}

void WLED::setup()
Expand All @@ -302,6 +311,22 @@ void WLED::setup()
DEBUG_PRINT(F("heap "));
DEBUG_PRINTLN(ESP.getFreeHeap());

#if WLED_WATCHDOG_TIMEOUT > 0
#ifdef ARDUINO_ARCH_ESP32
esp_err_t watchdog = esp_task_wdt_init(WLED_WATCHDOG_TIMEOUT, true);
DEBUG_PRINT(F("Enable watchdog "));
if (watchdog == ESP_OK) {
DEBUG_PRINTLN(F(" OK"));
} else {
DEBUG_PRINTLN(watchdog);
}
esp_task_wdt_add(NULL);
#else
// any timeout possible ?
ESP.wdtEnable(WLED_WATCHDOG_TIMEOUT * 1000);
#endif
#endif

#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
if (psramFound()) {
// GPIO16/GPIO17 reserved for SPI RAM
Expand Down
7 changes: 7 additions & 0 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
// filesystem specific debugging
//#define WLED_DEBUG_FS

#ifndef WLED_WATCHDOG_TIMEOUT
// 3 seconds should be enough to detect a lockup
// define WLED_WATCHDOG_TIMEOUT=0 to disable watchdog
#define WLED_WATCHDOG_TIMEOUT 3
#endif

//optionally disable brownout detector on ESP32.
//This is generally a terrible idea, but improves boot success on boards with a 3.3v regulator + cap setup that can't provide 400mA peaks
//#define WLED_DISABLE_BROWNOUT_DET
Expand Down Expand Up @@ -78,6 +84,7 @@
#else
#include <LittleFS.h>
#endif
#include "esp_task_wdt.h"
#endif

#include "src/dependencies/network/Network.h"
Expand Down

0 comments on commit 213e3e9

Please sign in to comment.