Watchdog

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Watchdog

Postby bkgoodman » Fri Feb 17, 2017 12:55 pm

I am trying to enable a watchdog which will reboot the board in the event of a massive problem, lockup, etc.

This seems to not be implemented in the Arduino libraries, so am try to implement it myself. Since the manual says:
Only the RWDT can trigger the system reset
I assume I have to do this from the RTC WDT. The ESP32 Technical Reference Manual says:
The RWDT registers are part of the RTC submodule and are described in the RTC Registers section.
...but the RTC section does not make reference to any watchdog stuff at all.

THe `soc/rtc_cntl_reg.h` file seems to make reference to some registers which are similar to the timer watchdog registers, like RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FEED, etc - but these registers are *not* discussed in the ESP32 Technical Reference Manual. In fact, the actual registers reference in these includes seem to fit into a "hole" in those described in the RTC section.

Furhtermore, the only usage I could find of them anywhere, in any project were bootloaders which merely "disabled" the watchdog by clearing a bit in CONFIG0 - as the manual says:
After booting, the register TIMERS_WDT_FLASHBOOT_MOD_EN should be cleared to stop the flash boot protection procedure for the MWDT, and RTC_CNTL_WDT_FLASHBOOT_MOD_EN should be cleared to do the same for the RWDT. After this, the MWDT and RWDT can be configured by software.
So - questions:

1. "How do I do this?""
2. Are these registers documented?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Watchdog

Postby kolban » Fri Feb 17, 2017 4:02 pm

Hopefully you won't have to drop down to the CPU registers level. My understanding is that within your Arduino code you can make calls to the ESP-IDF framework. Within that framework there are APIs for controlling watchdog processing. See here for the docs:

http://esp-idf.readthedocs.io/en/latest ... /wdts.html

Hopefully you will be able to leverage these functions in your Arduino scripts.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Watchdog

Postby WiFive » Fri Feb 17, 2017 5:44 pm

He wants to use rtc watchdog to have some separation. Unfortunately there is not much rtc documentation or source code available yet.

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Re: Watchdog

Postby bkgoodman » Mon Feb 20, 2017 3:11 pm

I tried another hack that worked for a while - I ran a wire from a GPIO to a reset, and made a timer/alarm/interrupt to fire the pin after a given point of time. It did the job - but I ran into two problems:

1. At one point the LWIP stack hit an exception, and it hung in the "Guru Meditation".

2. At another point on reboot it got "Flash read err, 1000 Falling back tp built-in command interpreter". Even hitting the RESET button wouldn't get out of this, but power cycle did.

So - any idea how to deal with any of these?

seatosummit
Posts: 3
Joined: Mon Jun 18, 2018 10:58 pm

Re: Watchdog

Postby seatosummit » Tue Jun 19, 2018 11:31 pm

Hi All-

Has there been any progress on this issue?

I have come across a scenario in which a Core Reset is insufficient in scope and I need to call a System Reset (RTC included). There appear to be 3 reset sources that are of this type:

Chip Power On Reset
RWDT System Reset
Brown Out Reset


I believe that the only source we can invoke in software is RWDT System Reset. This is a reset triggered via the Real Time Clock watchdog, which is the only watchdog that has the authority to reset at this scope if I understand correctly.

How would I go about creating a task that is watched by RWDT?

Thanks,
Austin

DCSTRATO
Posts: 1
Joined: Fri Jul 13, 2018 6:12 am

Re: Watchdog

Postby DCSTRATO » Fri Jul 13, 2018 6:55 am

It is a bit of a hack, but I have had success with building a separate watchdog task to check every 5 seconds to see if wdt has not been reset within the last 8 seconds. These times are just arbitrary. I have had to use this to restart a website monitor if the connected server restarts or loses connection, as the lwip_connect_r function call inside WiFiClient::connect seems to just lockup when this happens. But anything that causes your code to not get to call setWD inside of the defined WDtimeout in ms (on the next 5 sec interval) will cause the ESP.restart();

Declare a global unsigned long variable wdt and then call setWD() very often inside of your code.

Make the call to setWD and the xTaskCreatePinnnedToCore the last two lines in setup(). Hope this helps.

Code: Select all

 
 setWD();
 xTaskCreatePinnedToCore(watchDog, "watchdog", 512, NULL, 1, NULL, 0);

Code: Select all

unsigned long wdt;

void setWD() {
  wdt = millis();
}

void watchDog(void *pvParameters)
{
 #define WDtimeout 8000
  unsigned long wdc = millis();
  while (1) {
    if ((millis() - wdc) > 5000) {
      if ((millis() - wdt) > WDtimeout)  ESP.restart();
      wdc = millis();
    }
  }
}

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: Watchdog

Postby ESP_Dazz » Mon Jul 16, 2018 8:17 am

The RTC WDT is very similar in design to the MWDT in the timer groups having different stages and the ability to associate different actions (interrupt, CPU reset, system reset) to each stage. Currently the RTC WDT are used to guard against the panic handler from hanging. See esp_panic_wdt_start() and esp_panic_wdt_stop() in panic.c for a short example on how to use it. You can also look at the interrupt watch dog and task watch dog source code as the MWDT configuration will be similar to RTC WDT.

Mohit@life9sys.com
Posts: 2
Joined: Fri Sep 11, 2020 9:29 am

Re: Watchdog

Postby Mohit@life9sys.com » Fri Sep 11, 2020 9:33 am

In case we have defined an infinite loop in our code, can the reset of watchdog happen from within this infinite loop.

Who is online

Users browsing this forum: Baidu [Spider] and 33 guests