Skip to content

Commit

Permalink
Enabled watchdog for ESP32 and variants (#21422)
Browse files Browse the repository at this point in the history
* Enabled watchdog for ESP32 and variants

* Ensure compilation for sageboot

* Fix compilation

* Fix compilation for RISCV
  • Loading branch information
s-hadinger authored May 16, 2024
1 parent 6ba5938 commit b9bd558
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.

## [14.0.0.1]
### Added

- Enabled watchdog for ESP32 and variants

### Breaking Changed

Expand Down
7 changes: 7 additions & 0 deletions include/esp32x_fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@
#define SPI_MOSI_DLEN_REG(x) SPI_MS_DLEN_REG(x)

#endif // TARGET

// This trick makes sure that 'lto' optimizer does not inline `delay()
// so we can override it with `-Wl,--wrap=delay` linker directive
#ifdef __cplusplus
extern "C"
#endif // _cplusplus
void delay(__UINT32_TYPE__ ms) __attribute__((noinline)) __attribute__ ((noclone));
2 changes: 1 addition & 1 deletion lib/libesp32/HttpClientLight/src/TasUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ size_t TasUpdateClass::writeStream(Stream &data) {
return written;
written += toRead;

delay(1); // Fix solo WDT
yield(); // Ensure WDT does not trigger
}
return written;
}
Expand Down
2 changes: 2 additions & 0 deletions tasmota/include/tasmota_configurations_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
#define USE_WEBCLIENT
#define USE_WEBCLIENT_HTTPS

#undef USE_ESP32_WDT // disable watchdog on SAFEBOOT until more testing is done

#if CONFIG_IDF_TARGET_ESP32
#if CONFIG_FREERTOS_UNICORE
#undef USE_MQTT_TLS
Expand Down
2 changes: 1 addition & 1 deletion tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@

#ifdef ESP32

// #define USE_ESP32_WDT // Enable Watchdog for ESP32, trigger a restart if loop has not responded for 5s, and if `yield();` was not called
#define USE_ESP32_WDT // Enable Watchdog for ESP32, trigger a restart if loop has not responded for 5s, and if `yield();` was not called

#define SET_ESP32_STACK_SIZE (8 * 1024) // Set the stack size for Tasmota. The default value is 8192 for Arduino, some builds might need to increase it

Expand Down
12 changes: 8 additions & 4 deletions tasmota/tasmota_support/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ extern struct rst_info resetInfo;
\*********************************************************************************************/
#ifdef ESP32
// Watchdog - yield() resets the watchdog
#ifdef USE_ESP32_WDT

extern "C" void __yield(void); // original function from Arduino Core
extern "C"
void yield(void) {
vPortYield(); // was originally in `__yield`
__yield();
feedLoopWDT();
}

// patching delay(uint32_t ms)
extern "C" void __real_delay(uint32_t ms);
extern "C" void __real_delay(uint32_t ms); // original function from Arduino Core

extern "C" void __wrap_delay(uint32_t ms) {
#ifdef USE_ESP32_WDT
if (ms) { feedLoopWDT(); }
__real_delay(ms);
feedLoopWDT();
#else
__real_delay(ms);
#endif
}

#endif // USE_ESP32_WDT
#endif // ESP32

/*********************************************************************************************\
Expand Down
5 changes: 5 additions & 0 deletions tasmota/tasmota_support/support_crash_recorder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ void CmndWDT(void)
}

// This will trigger the os watch after OSWATCH_RESET_TIME (=120) seconds
// or normal WDT on ESP32
void CmndBlockedLoop(void)
{
while (1) {
#ifdef ESP32
delay(10000); // 10s on ESP32 so that the normal WDT fires after 5s. There is no OSWATCH_RESET_TIME on ESP32
#else
delay(1000);
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_54_lvgl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void lv_flush_callback(lv_display_t *disp, const lv_area_t *area, uint8_t *color
if (lvgl_glue->screenshot != nullptr) {
// save pixels to file
int32_t btw = (width * height * LV_COLOR_DEPTH + 7) / 8;
yield(); // ensure WDT does not fire
while (btw > 0) {
if (btw > 0) { // if we had a previous error (ex disk full) don't try to write anymore
int32_t ret = lvgl_glue->screenshot->write((const uint8_t*) color_p, btw);
Expand Down

0 comments on commit b9bd558

Please sign in to comment.