Page 1 of 1

How to properly feed WDT

Posted: Thu May 16, 2019 5:12 am
by kimsunk
  1. #include "esp_task_wdt.h"
  2.  
  3. void setup() {
  4.  
  5.   Serial.begin( 1000000 );
  6.   BaseType_t result = xTaskCreatePinnedToCore( handleOtherThings, "handleOtherThings", 20000, NULL, 1, NULL, 0 );
  7. }
  8.  
  9. void handleOtherThings( void* param ) {
  10.  
  11.   while( true ){
  12.    
  13.     esp_task_wdt_reset();
  14.   }
  15. }
  16. void loop() {
  17.   // put your main code here, to run repeatedly:
  18.  
  19. }
I want to use xTaskCreatePinnedToCore function to run two tasks on each core.

However, WDT reset keep triggered.

Nothing changes if I use yield() instead of esp_task_wdt_reset();

However, if i change esp_task_wdt_reset() to vTaskDelay( 10 / portTICK_PERIOD_MS ), then no more WDT reset, but I don't want 10ms delay for my task.

delay(1); also resets WDT timer but I also do not want it be delayed for 1ms.

delay( 0 ); do not reset WDT timer.

delayMicroseconds( 100 ); do not reset WDT timer.

What would be the minimal and proper way to reset WDT timer in ESP32-arduino?

Re: How to properly feed WDT

Posted: Thu May 16, 2019 6:31 am
by boarchuz
I understand that yield() should do the job. I suspect it's actually the loopTask causing your issues.

It's unclear if that's actually your loop() function or if you've cut it down to that for the sake of brevity. If that's actually it, could you try adding vTaskDelay(portMAXDELAY) to it?

Re: How to properly feed WDT

Posted: Thu May 16, 2019 11:19 am
by ESP_Sprite
You misunderstand the purpose of esp_task_wdt_reset(). The esp-idf watchdog actually monitors multiple tasks, the most important one being the idle tasks. If these don't feed the watchdog in time, it means something is using up all the CPU power and for various reasons this is not good. (This is also why vTaskDelay() or yield() work: they allow the idle task to run.) esp_task_wdt_reset() does not reset the watchdog that watches the idle threads; instead, it is used to reset a watchdog that would be watching your thread. As the idle thread watchdog still times out, you still will get warnings.

Re: How to properly feed WDT

Posted: Tue Jul 20, 2021 5:48 am
by ArcHeRRed
Thank you very much :D