Crash with minimal sketch on ESP8266

Whilst making changes to a sketch that has run perfectly for a couple of weeks on 2 different ESP8266 D1 Mini boards, one of which is a genuine LOLIN board, I started to experience crashes after uploading the changed code

As we often ask users to do here I reduced the code to the minimum required to illustrate the problem. Much to my surprise I ended up with this

void setup()
{
  while (1);
}

void loop()
{
}

This crashes consistently. When the sketch crashes the output to the Serial monitor is as follows


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

load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v00040830
~ld

and this is repeated indefinitely

The environment is as follows :
Windows 10
IDE 1.8.13
ESP8266 boards version 3.0.2
Board selected LOLIN(WEMOS) D1 R2 & mini
Same problem with LOLIN(WEMOS) D1 mini (clone) selected

Remove the while() and all is OK

Can anyone see any obvious reason for the problem ?

Does this work? Not got access to an ESP32 to test!

void setup()
{
  while (1)
{
yield();
}
}

void loop()
{
}

My problem is occurring on an ESP8266. The minimal sketch that I posted does not crash on an ESP32

Your sketch does not crash on an ESP8266 (or an ESP32 for that matter)

The ironic thing is that I don't really need the while() in my actual sketch. I only put it in when testing what was happening in setup() with a nested #if/#endif construction testing the processor type and didn't need the rest of the code to run until I knew that my logic was correct

You need to allow the wifi process to run, which is what yield() does. My guess is your loop() takes too long.

[Edit: OK, that's not an 'obvious' reason!]

Do you mean this loop() function in my minimal sketch ?

void loop()
{
}

The theory that the WiFi has to run despite the fact that I am not using it in the example sketch is plausible. It seems that putting almost anything in the blocking while loop, even a delay(1), prevents the problem occurring, although I guess that using yield() is the proper way to do it

I don't know all the details and I might have something wrong but my understanding is that loop() allows wifi to run each time loop() loops. while(1) on its own gets stuck and never allows for wifi, inserting yield() fixes that.

No, in your actual sketch with the problem, in your minimal sketch loop() never runs because you get stuck in while(1) in setup().

The obvious reason would be that you have created an infinite loop without resetting the WDT, but rst cause 2 actually refers to an external reset or wakeup from deep sleep. The rst cause should be 3, so this is a bit of an anomaly, but the board should reset if you create a loop without calling yield() (or delay() which calls yield() in the ESP core) that is longer than about 2.5 seconds.
So that the ESP crashes makes total sense, but the error message appears to be incorrect. I have not used core version 3.0.2 and i have been advised to use 2.7.4 instead of v3.x (or 2.4.2 which i am still using)
Keep in mind that it is best practice to first uninstall the core version(s) that you are using before installing the version that you intend to use, and not have 2 versions side by side.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.