Esp-idf: Task watchdog got triggered - it is fixed with a vTaskDelay of 10ms but is this a bug?

Created on 21 Feb 2018  路  2Comments  路  Source: espressif/esp-idf

Hi,

I have a ESP32-DEVKIT-C running, I wanted to create a simple task:

void io_task(void *parameter) 
{
    while(1) {
        vTaskDelay(2 / portTICK_PERIOD_MS);
    }
}

void app_main(void)
{
    nvs_flash_init();
    xTaskCreate(io_task,"io_task",2048,NULL,1,NULL);
}

Here I got this warning:

Task watchdog got triggered. The following tasks did not reset the watchdog in time:

  • IDLE (CPU 1)
    Tasks currently running:
    CPU 0: IDLE
    CPU 1: io_task

So I tried different strategies like using esp_task_wdt_reset() in the while, but it fails and returns:
ESP_ERR_NOT_FOUND: Error, the current running task has not subscribed to the TWDT

The only way I can make it work is by using:

   while(1) {
        vTaskDelay(10 / portTICK_PERIOD_MS);
    }

But I have no idea why?

Most helpful comment

Anyone who still want to avoid that error should try
adding these three line to your continuous rtos function,

TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;

And add this header

#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"

All 2 comments

Hi @shaoner,

The default tick rate is 100Hz (you can configure this but 100 is a good tradeoff between ISR overhead and responsiveness).

This means portTICK_PERIOD_MS is 10 (10ms per tick). Therefore a 2ms vTaskDelay is a 0 tick delay, ie no delay at all, which is interpreted as "yield to higher priority tasks, otherwise keep running". Therefore io_task will starve lower priority tasks (like IDLE) if it never blocks waiting for something else to happen.

You can disable the task watchdog timer if you're sure that you want this task running on the CPU as much as possible, and don't mind starving lower priority tasks. Bear in mind this may have unexpected consequences (the idle task is used for cleanup of deleted tasks, and the FreeRTOS timer task also runs at low priority).

Alternatively you could set the tick rate to 1000Hz. FreeRTOS will spend more time in context switch interrupts, so you have a few less CPU cycles available for your program, but you'll be able to delay a task for 2ms.

Anyone who still want to avoid that error should try
adding these three line to your continuous rtos function,

TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;

And add this header

#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
Was this page helpful?
0 / 5 - 0 ratings