Watchdog resets on ESP8266

I'm working with a Lolin D1 Mini (a genuine Lolin, not some cheap imitation), and for this project I really don't want it to restart if it freezes up. I want it to fail, and not try again. So based on info found several places, I tried using this code:

void setup() {
ESP.wdtDisable();                               // software watchdog
 *((volatile uint32_t*) 0x60000900) &= ~(1);   // hardware watchdog
while(1);
}

void loop() {
}

It's supposed to disable both the software and hardware watchdogs. At first, I thought it was working, but waiting long enough, I get reset text on the serial monitor every 73 seconds:

[at 115200 baud]

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v000409a0
~ld

[then at 74880 baud]

rf cal sector: 1020
freq trace enable 0
rf[112] :

Can anyone shed any light on what's going on? If it matters, I have the latest ESP8266 core, which I believe is v1.3.0.

easy way to do that is by calling a function that resets the wdt

while(1) yield();

Interesting. What you get with system_get_rst_info() ?

I think this goes beyond my pay grade. I can't get it to compile. It's either not declared in this scope, or if I make it ESP.system_get_rst_info(), it says "'class EspClass' has no member named 'system_get_rst_info'". Do you have a code example showing what you want me to try?

Latest or 1.3.0?
I haven't been playing with 8266 for years, but if you have latest core, I think you can simply try:
Serial.println(ESP.getResetReason());

There must be something in your code that freezes it.
Better to fix the cause than use a band-aid.

I had cases where the ESP crashed at some point in the code.
A yield() in the right spot usually fixed it.
Leo..

There are two watchdogs timers on the ESP8266, hardware and software. Hopefully the following helps.

Software Watchdog (SW WDT)

One of these will reset it. yield(); or delay(0); or esp_yield();

Hardware Watchdog (HW WDT)

  • Built into the Tensilica LX106 CPU.

  • Much shorter timeout (around 0.8 seconds).

  • Triggered when CPU interrupts cannot run or the system is locked with interrupts disabled.

  • Not fed by delay() directly.

  • Fed by the internal OS tick and by returning control to the idle task.

You can trip the Hardware WDT by:

  • Disabling interrupts too long

  • Running very long ISRs

  • Locking the CPU with no yield AND no interrupt service happening

  • doing while() that does not come true will trip it.

I remembered it wrong. It's v3.1.2.

I get this result after 73 seconds:


--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x4020106a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffe40 end: 3fffffd0 offset: 0160
3fffffa0:  00000000 0011001f 00000000 feefeffe  
3fffffb0:  feefeffe feefeffe 3ffee650 40201abc  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100ce5  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3424, room 16 
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x2b
csum 0x2b
v00041e80
~ld
⸮⸮⸮⸮g⸮{⸮⸮g|⸮d⸮d`#⸮e⸮|s⸮$⸮n⸮⸮g⸮

And this is the code that produced that:

#include <ESP.h>

void setup() {
  Serial.begin(115200);
  Serial.println(ESP.getResetReason());
  ESP.wdtDisable();
    *((volatile uint32_t*) 0x60000900) &= ~(1);
  while(1) {
  }
}

void loop() {
}

So apparently, ESP.wdtDisable() does not disable the wdt.

Not sure what you're trying to do but does this crash?

Well, it doesn't exactly crash, but it reboots every 73 seconds. The lines above it are supposed to disable the software and hardware watchdogs, and they do stop the shorter watchdog reboots, but not the 73 second one.

The while loop is just to test whether the watchdogs have been disabled. If they were, there would be no crash or reboot. I know you're supposed to leave them alone, and do enough yield()s to keep the watchdogs fed. I can answer for my code, but have no idea what the various libraries are doing. I just need to be sure it won't reboot, so I was hoping I could just disable the watchdogs. But it looks like that's not possible. So I'll need to do a yield loop or something.

Looks like there is 3rd watchdog that you can't control on arduino.

Hardware approach, kill switch?

Could you disable WiFi all together ? I mean it anyway won't work properly if the scheduled tasks aren't performed, and there is a chance the reset is caused by the WiFi hardware / software

I tried wifi-off, but it didn't make any difference.

Well, Perplexity reports that this is a known problem with the ESP8266, but no solution has been found. So it looks like I just need to go back to yielding a lot, and hope for the best.

The ESP8266 is EOL.
You should have moved to the ESP32 range a while ago.
The ESP32-C3 (single core) is a direct replacement for the now obsolete 8266 chip.
My favorite is the Seeed XIAO range.
Leo..

I don't think it's EOL. It's still manufactured by Expressif, and still supported. But I agree that the ESP32 is the way to go. It's just that I didn't have any of those on hand, but did have three ESP8266s in the junque box.

Correct, 3-4 years to go.
The 8266 was introduced on 2014, with 15years support.

Maybe only once a minute, that is not really a lot.

As far as i know they have stopped developing the Arduino core.
Amazing product though, quite a game changer, also for it's price.

ESP32 has support till 2034 ?

As an aside

What's the deal with the final set of parentheses?

  uint32_t x;
  x = -1;
  x &= ~(1);
  Serial.println(x, HEX);
  x = -1;
  x &= ~1;
  Serial.println(x, HEX);

Same results.

I don't know. I just copied the line from a source that said it would work to disable the hardware watchdog. I don't understand the line at all, except that it supposedly writes something to a register.