Arduino-esp32: The Watchdog got triggered. (!?)

Created on 12 Dec 2017  路  18Comments  路  Source: espressif/arduino-esp32

I got here an ESP32 performing some sensor tasks, which was left alone, working for two or three days. Some minutes ago, I tried to refresh the webpage that the ESP32 serves and it wasn't working anymore.

I did open the COM in order to read the Serial output, just in case, and I got:

Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 0)
Tasks currently running:
CPU 0: wifi
CPU 1: loopTask

being periodically sent at about 5 seconds interval.

The Arduino code is running inside the ESP32, since I got a gas sensor and whenever I trigger it, the Arduino code enables a Relay which I can hear / see turning on ... but the ESP32 has lost wifi connection and it is not returning (Although my code watches for WiFi.status() and if disconnected tries to reconnect).

This may probably be a bug, even at IDF level. I am sorry I do not know what made it trigger, nor have a way of posting any more data.

I got the latest Arduino framework in use.

I can implement whatever mechanism you may propose in order to catch it better the next time this happens, If it does.

Regards,

Enrique.

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 18 comments

This suggests you have one or two loops that are not servicing the watchdog by calling delay() periodically with some millisecond value. Since the ESP32 is on a real time OS, it is monitoring for this sort of thing and your threads needs to share their time.

@lonerzzz Thanks for the explanation, I do understand it but I fail to notice WHERE to apply it.

Let me explain: I do not touch CPU 0 at all. I always thought CPU 0 was Arduino's realm for running its internal routines related to wifi / bt / housekeeping, while my code runs on CPU 1.

I can somewhat relate to my understanding since my code seems to keep working (my sensors trigger a beeper and a relay) (CORE 1) while the ESP32 is "WIFI dead" (CORE 0) throwing out that "Task watchdog got triggered" error through serial port.

Where may I place a delay that actually helps CORE 0, if my code does not touch such core ?

My code certainly has lots of DELAY() in different parts of it. For instance my routine which "waits for WIFI connection" is a loop with a delay(500) repeated 10 times while checking WiFi.status().

Regards,

Enrique

It just happened again ...

@euquiq Sometimes activities in one task/thread can halt activity in the other. It is not a matter of you adding delay on a core that you are using, but you have to understand any calls that you make which might cause activity on the other core. On the ESP32, that could be a troublesome wireless call for example. What you want to determine is if you have long running, CPU intensive activities within your code. You could, for example, have the loop calling delay() regularly but also have a method in that loop that monopolizes the processor for some period of time long enough to trigger the watchdog. In that case, you would need a delay within the method that you are calling. Hope that helps.

@lonerzzz Thanks again for your explanation. I am closely inspecting my code. I am closing this issue, since as you comment, it surely is some exotic situation from my wifi network / my code which incurs into such behavior on core 0. If I get to clarify something worth mentioning, of course I will report back so it may help others. Regards, Enrique.

Did you ever find the answer to this issue, I have just updated the espidf and arduino code and now getting this watchdog issue.

Reason I post here, is its exactly 5 seconds as per your initial post...thats too much of a coincidence ?

Thanks

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"

@akshar001 Hello,

Thanks for the tip, nevertheless in the scope of the arduino-esp32 environment what do you mean by continuous rtos function, are we talking about the main loop of the arduino program or the task affected to core 0 in my case (BLE scan is affected to core 0)?

Note that I have several users reporting the initial error message:

IDLE (CPU 0)
Tasks currently running:
CPU 0: wifi
CPU 1: IDLE
Task watchdog got triggered. The following tasks did not reset the watchdog in time:

Regards

@1technophile what i meant by any rtos task which runs without a delay,loop is actually a rtos task which is implemented in esp32 arduino so by just putting it into a loop can solve your problem.(there is no problem of core)

@akshar001, thanks for the info we will test your solution

@1technophile what i meant by any rtos task which runs without a delay,loop is actually a rtos task which is implemented in esp32 arduino so by just putting it into a loop can solve your problem.(there is no problem of core)

@me-no-dev @1technophile @akshar001
UPDATE 1: The warning disappear when I put these three lines of code inside void loop() {}. I'm currently testing if the board will reset or shutdown anytime soon. The ESP-32 board that I'm currently using is the LOLIN D32 Pro. Thanks!

@me-no-dev @1technophile @akshar001
I changed my code in a way that I don't need to write while (true) or for (;;) inside the core 0 function, and, this way, I just need to put delay(1) inside the method that handles core 0 loop. This way, I don't need these three lines of code that @akshar001 provided. This is how I did it:

void feedGPS()
{
  while (SerialGPS.available() >= 0)
  {
    if (SerialGPS.available() == 0)
    {
      //Serial.println(F("D"));
      //vTaskDelay(10); // wrapper for delay()
      delay(1);
    }
    else
    {
      char c = SerialGPS.read();
      GPSobj.encode(c);
      //Serial.write(c);
    }
  }
}

@1technophile what i meant by any rtos task which runs without a delay,loop is actually a rtos task which is implemented in esp32 arduino so by just putting it into a loop can solve your problem.(there is no problem of core)

@me-no-dev @1technophile @akshar001
UPDATE 1: The warning disappear when I put these three lines of code inside void loop() {}. I'm currently testing if the board will reset or shutdown anytime soon. The ESP-32 board that I'm currently using is the LOLIN D32 Pro. Thanks!

This was 22days ago, can you please share the result of the test, I am using nodemcu 32s and currently experiencing watchdog reset, I used @1technophile's solution and recently uploaded the code to esp32s. I would like to know before hand as to what happend with your tests. Ty

@1technophile what i meant by any rtos task which runs without a delay,loop is actually a rtos task which is implemented in esp32 arduino so by just putting it into a loop can solve your problem.(there is no problem of core)

@me-no-dev @1technophile @akshar001
UPDATE 1: The warning disappear when I put these three lines of code inside void loop() {}. I'm currently testing if the board will reset or shutdown anytime soon. The ESP-32 board that I'm currently using is the LOLIN D32 Pro. Thanks!

This was 22days ago, can you please share the result of the test, I am using nodemcu 32s and currently experiencing watchdog reset, I used @1technophile's solution and recently uploaded the code to esp32s. I would like to know before hand as to what happend with your tests. Ty

Anyone who still want to avoid that error should try
adding these three line to your continuous rtos function (void loop or any other task that you have added),

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"

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"

I wrote what you write and I create infinitive loops in one task. Task Watchdog didn't trigger. So If I write your code, the watch dog never triggered. It is not good I think.

disabling the TWDT is not a solution. Doing so you may not get the watchdog triggered error message and your ESP wouldn't restart but your lower priority tasks will still starve for CPU time and things wouldn't work the way you want it to.

@Eiyvor in most of the scenario i am running till now, it works well. You are right by the way it is not a solution. but recent workaround. because problem is from esp inner firmware and we do not have full source code of them

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"

I wrote what you write and I create infinitive loops in one task. Task Watchdog didn't trigger. So If I write your code, the watch dog never triggered. It is not good I think.

Can you share me a code here. It depends on how you put it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickChungVietNam picture NickChungVietNam  路  3Comments

zuqualla picture zuqualla  路  4Comments

mpatafio picture mpatafio  路  4Comments

AsafFisher picture AsafFisher  路  4Comments

jhowkis picture jhowkis  路  3Comments