ESP32 watchdog timers (WDT)

Introduction

While we already learned to feed the ESP8266 watchdog timer appropriately (see My ESP crashes running some code. How to troubleshoot it? — ESP8266 Arduino Core 2.5.0 documentation). In this spirit, we should also learn about the ESP32.

Please note that knowing about the WDT subsystem really helps when running into runtime problems you might diagnose as weird behavior, so this is equally important as https://community.hiveeyes.org/t/protect-code-when-accessing-shared-resources/1551/.

Overview

The ESP-IDF has support for two types of watchdogs: The Interrupt Watchdog Timer and the Task Watchdog Timer (TWDT). The Interrupt Watchdog Timer and the TWDT can both be enabled using make menuconfig , however the TWDT can also be enabled during runtime. The Interrupt Watchdog is responsible for detecting instances where FreeRTOS task switching is blocked for a prolonged period of time. The TWDT is responsible for detecting instances of tasks running without yielding for a prolonged period.

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/wdts.html

See also:

Observations

How the watchdogs will behave on ESP32 in respect to Arduino is still in flux, as you can see when following some comments from upstream at Task watchdog got triggered. The following tasks did not feed the watchdog in time · Issue #595 · espressif/arduino-esp32 · GitHub and beyond.

GitHub issues

Sep 2, 2017 [me-no-dev]

I don’t know what is going on here, but I can tell you that I will not add vTaskDelay(10) after each loop. For you to trigger WDT in the loop, you have to be running as IDF component and have WDT enabled for the Idle task on Core1. Those are disabled for Arduino in order to give to most Arduino-like behavior under FreeRTOS. You can add vTaskDelay(10) to your loop if you need it and achieve the same result.

10ms between each loop is ages in processor time ;) 2.4 million wasted CPU cycles, to be exact. Nothing else is running on Core1 ;)

goto

Dec 28, 2018 [me-no-dev]

Arduino does have access to all IDF things, but is built with WDT disabled for Core 1 (where loop runs). This is made on purpose to allow code written for other platforms to run on ESP32 without constantly causing resets. If you want to trigger WDT, then spin a task on core 0

goto

Jan 5, 2019 [me-no-dev]

WDT is now enabled to reset the board (by default on Core0 only, but can be enabled for Core1 or the loop task also). Update your Arduino and try again ;)

goto

Only recently, CONFIG_TASK_WDT_PANIC=y became the default per


References

For the Arduino universe see: