ESP32 Task Watchdog Timer Hung Task Detection
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 Task Watchdog Timer Hung Task Detection. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 main loop task hangs and the task watchdog timer does not detect it.
Quick Fix
Wrong
// Running on core 1, but TWDT only monitors core 0
Task hangs on core 1 without detection. System appears frozen.
Right
esp_task_wdt_config_t wdt_config = {
.timeout_ms = 5000,
.idle_core_mask = (1 << 0) | (1 << 1), // Monitor both cores
.trigger_panic = true
};
esp_task_wdt_init(&wdt_config);
// Subscribe current task
esp_task_wdt_add(NULL);
void loop() {
esp_task_wdt_reset(); // Must call within 5 seconds
// main work
}
WDT monitors both cores. Task hang detected and system panics with backtrace.
Prevention
Subscribe all critical tasks with esp_task_wdt_add(NULL). Set idle_core_mask to cover all cores. Use trigger_panic for immediate crash dump. Increase timeout for slow operations. Add per-task WDT for FreeRTOS tasks.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro