Following my previous post regarding enabling WDT on ESP32, the new version of arduino-esp32 3.x comes with some breaking changes for esp_task_wdt_init
. I will show you here how to fix the errors with enabling hardware WDT on ESP32 using Arduino IDE.
The previous code (using arduino-esp32 v2.x) now throws the following errors:
error: invalid conversion from 'int' to 'const esp_task_wdt_config_t*' [-fpermissive]
error: too many arguments to function 'esp_err_t esp_task_wdt_init(const esp_task_wdt_config_t*)'
invalid conversion from 'int' to 'const esp_task_wdt_config_t*' [-fpermissive]
Fixing error “invalid conversion from ‘int’ to ‘const esp_task_wdt_config_t*'”
The reason for this error is that the definition for esp_task_wdt_init
function has changed. The new code should look like this:
#include "esp_task_wdt.h" //3 seconds WDT #define WDT_TIMEOUT 3000 //if 1 core doesn't work, try with 2 #define CONFIG_FREERTOS_NUMBER_OF_CORES 1 esp_task_wdt_config_t twdt_config = { .timeout_ms = WDT_TIMEOUT, .idle_core_mask = (1 << CONFIG_FREERTOS_NUMBER_OF_CORES) - 1, // Bitmask of all cores .trigger_panic = true, }; void setup() { Serial.begin(115200); Serial.println("Configuring WDT..."); esp_task_wdt_deinit(); //wdt is enabled by default, so we need to deinit it first esp_task_wdt_init(&twdt_config); //enable panic so ESP32 restarts esp_task_wdt_add(NULL); //add current thread to WDT watch } int i = 0; int last = millis(); void loop() { // resetting WDT every 2s, 5 times only if (millis() - last >= 2000 && i < 5) { Serial.println("Resetting WDT..."); esp_task_wdt_reset(); last = millis(); i++; if (i == 5) { Serial.println("Stopping WDT reset. CPU should reboot in 3s"); } } }
Also make sure to set CONFIG_FREERTOS_NUMBER_OF_CORES
to the number of cores your ESP32 has (usually 1 or 2).
And the output:
entry 0x400805cc Configuring WDT... Resetting WDT... Resetting WDT... Resetting WDT... Resetting WDT... Resetting WDT... Stopping WDT reset. CPU should reboot in 3s E (12986) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
ESP32 development boards can be bought from AliExpress for just 4$ using this link or the ESP32 module with OLED display for 6$.
I tried this code and it doesn’t work
H/W Adafruit ESP32-S2 Feather
I made only these changes
#define WDT_TIMEOUT 15000
#define CONFIG_FREERTOS_NUMBER_OF_CORES 1
The Watch Dog continues to time out in 3 seconds
I’ve updated the code with the fix, you need to add deinit before init
Hi,
having problems with wtd i found your site. I modified your code but the esp keeps reseting. Can you tell me what the problem is?
#include “esp_task_wdt.h”
//20 seconds WDT
#define WDT_TIMEOUT 20000
#define CONFIG_FREERTOS_NUMBER_OF_CORES 2
esp_task_wdt_config_t twdt_config = {
.timeout_ms = WDT_TIMEOUT,
.idle_core_mask = (1 <= 2000 && i < 3) {
Serial.println("Resetting WDT…");
esp_task_wdt_reset();
last = millis();
i++;
if (i == 3) {
Serial.println("Stopping WDT reset. CPU should reboot in 20s");
}
}
}
Serial Monitor:
Resetting WDT…
Resetting WDT…
Resetting WDT…
Stopping WDT reset. CPU should reboot in 20s
E (22067) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (22067) task_wdt: – loopTask (CPU 1)
E (22067) task_wdt: Tasks currently running:
E (22067) task_wdt: CPU 0: IDLE0
E (22067) task_wdt: CPU 1: loopTask
E (22067) task_wdt: Aborting.
E (22067) task_wdt: Print CPU 1 backtrace
Backtrace: 0x40084285:0x3ffb21f0 0x400842c3:0x3ffb2210 0x400d1ff7:0x3ffb2230 0x400d1657:0x3ffb2250 0x400d3128:0x3ffb2270 0x4008a46d:0x3ffb2290
ELF file SHA256: c29d606fe7b22264
Rebooting…
I’ve updated the code with the fix, you need to add deinit before init