Skip to content

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.
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

### How is TWDT different from IWDT?

TWDT monitors FreeRTOS task execution. IWDT monitors interrupt latency. TWDT timeout is configurable per task. IWDT timeout is typically 500ms.

Do I need to subscribe to TWDT?

Yes. Call esp_task_wdt_add(NULL) in each task to monitor. Unsubscribed tasks are not watched and can hang without detection.

What happens on TWDT timeout?

If trigger_panic is true: system panics with backtrace. If false: prints warning and continues. Use panic for production debugging.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro