Prepare for ESP32 WDT (#21383)

* Prepare for ESP32 WDT

* make `sleep()` reset WDT
This commit is contained in:
s-hadinger 2024-05-12 21:12:08 +02:00 committed by GitHub
parent 15a5ef30c4
commit 2865630309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 34 additions and 1 deletions

View File

@ -36,6 +36,7 @@ build_flags = ${esp_defaults.build_flags}
-Wl,--wrap=panicHandler -Wl,--wrap=xt_unhandled_exception
-Wl,--wrap=_Z11analogWritehi ; `analogWrite(unsigned char, int)` use the Tasmota version of analogWrite for deeper integration and phase control
-Wl,--wrap=ledcReadFreq ; `uint32_t ledcReadFreq(uint8_t chan)`
-Wl,--wrap=delay ; void delay(uint32_t ms)
lib_ignore =
HTTPUpdateServer
USB

View File

@ -1122,6 +1122,8 @@ https://rya.nc/tasmota-fingerprint.html"
#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 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
#ifdef SOC_TOUCH_VERSION_1 // ESP32

View File

@ -411,6 +411,10 @@ void setup(void) {
#endif // CONFIG_IDF_TARGET_ESP32
#endif // ESP32
#ifdef USE_ESP32_WDT
enableLoopWDT(); // enabled WDT Watchdog on Arduino `loop()` - must return before 5s or called `feedLoopWDT();` - included in `yield()`
#endif // USE_ESP32_WDT
RtcPreInit();
SettingsInit();

View File

@ -21,6 +21,30 @@ extern "C" {
extern struct rst_info resetInfo;
}
/*********************************************************************************************\
* ESP32 Watchdog
\*********************************************************************************************/
#ifdef ESP32
// Watchdog - yield() resets the watchdog
#ifdef USE_ESP32_WDT
extern "C"
void yield(void) {
vPortYield(); // was originally in `__yield`
feedLoopWDT();
}
// patching delay(uint32_t ms)
extern "C" void __real_delay(uint32_t ms);
extern "C" void __wrap_delay(uint32_t ms) {
__real_delay(ms);
feedLoopWDT();
}
#endif // USE_ESP32_WDT
#endif // ESP32
/*********************************************************************************************\
* Watchdog extension (https://github.com/esp8266/Arduino/issues/1532)
\*********************************************************************************************/

View File

@ -110,6 +110,7 @@ void BrTimeoutStart(void) {
if (0 == berry.timeout) {
berry.timeout = 1; // rare case when value accidentally computes to zero
}
yield();
}
void BrTimeoutYield(void) {

View File

@ -404,7 +404,8 @@ extern "C" {
// ESP object
int32_t l_yield(bvm *vm);
int32_t l_yield(bvm *vm) {
return be_call_c_func(vm, (void*) &BrTimeoutYield, NULL, "-");
BrTimeoutYield();
be_return_nil(vm);
}
// Berry: tasmota.scale_uint(int * 5) -> int