You need to yield to FreeRTOS periodically which will also reset the watchdog timer. If you have a simple main loop application (e.g. you are only using one RTOS task) then this is a way to do that, but with the catch you have to release operation for the RTOS tick time (default 10mS):
if (ResetWdtPrescaller1ms <= 0)
{
ResetWdtPrescaller1ms = 500;
vTaskDelay(10 / portTICK_PERIOD_MS); //Delay for 10mS (min possible to default portTICK_PERIOD_MS = 10 (10ms per FreeRTOS tick)
}
If you don’t want to stall your main loop for 10mS every time then you can do this instead:
#include "esp_task_wdt.h"
//Before your main loop:
esp_task_wdt_add(NULL); // Register this task with the task watchdog. NULL=current task
//Inside your main loop:
//----- EXIT TO THE IDLE TASK PERIODICALLY -----
//Ensures the IDLE task watchdog will be reset and any other OS background tasks will be actioned
if (ResetWdtPrescaller1ms <= 0)
{
ResetWdtPrescaller1ms = 500;
esp_task_wdt_reset(); //Reset the watchdog without sleeping
taskYIELD(); //Optionally yield so others can run, with minimal delay
}
