ESP 32 - Watch dogs

A watchdog(WD) is builtin system which resets your system if you are too late to reset the WD system.

Normally used as last safey system to reboot your system if its running wild.

The watchdog is pregrammed to a time 10,100,1000,2000,4000 msec depending on you system

ESP32 watchdog

/*
   JDN
   watchdog
   if you dont feed the dog you will reboot within <watchdog timeout> time [sec]

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

*/
#include <esp_task_wdt.h>
void task1 (void *pParm)
{

  while (1) {
      vTaskDelay(1); // if you comment out vTAskDelay watchtimer will reboot
                     // because you dont tell FreeRTOS you are alive
                     // or disable watchdog on Core0   disableCore0WDT();
  }
}

void setup() {
  Serial.begin(115200);
  delay(1000);

  // change timeout for watchdog esp_task_wdt_init(1, true); // <wd timeout in seconds>,<panic true/false>min 1 sec

  xTaskCreatePinnedToCore(task1, "t0", 2000, NULL,  2, NULL, 0);

  vTaskDelete(NULL); // terminate myself so only task above is running

}

void loop() {}

Documentation

System calls

-  esp_task_wdt_init(WDT_TIMEOUT, true)               enable panic so ESP32 restarts(in sec)
- esp_err_t esp_task_wdt_add(TaskHandle_t handle)     Subscribe a task to the Task Watchdog Timer (TWDT)
- esp_err_t esp_task_wdt_reset(void)                  Reset calling task' the Task Watchdog timer

- esp_err_t esp_task_wdt_delete(TaskHandle_t handle)  Unsubscribes a task from the Task Watchdog Timer (TWDT)
- esp_err_t esp_task_wdt_status(TaskHandle_t handle)  Query whether a task is subscribed to the Task Watchdog Timer (TWDT)
-

System calls - Arduino IDE

Normally you are or should run on core 0, so ues Pinned version of createTask

  • disableCore0WDT();

  • enableCore0WDT();

  • disableCore1WDT();

  • enableCore1WDT();

  • enableLoopWDT();

  • disableLoopWDT();

  • feedLoopWDT();

Arduino HAL/WD code (source)

(click for code)

ESP docu by Jens