esp8266 / esp8266/Arduino

eraseConfig() causes crashes

Open
#6,063 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

#### Platform

- Hardware: WROOM02
- Core Version: 2.5.0
- Development Env: Arduino
- Operating System: Mac

### Settings in IDE

- Module: [Generic ESP8266]
- Flash Mode: [dio]
- Flash Size: [2MB]
- lwip Variant: [v2 Higher Bandwidth]
- Reset Method: [nodemcu]
- Flash Frequency: [80Mhz]
- CPU Frequency: [160MHz]
- Upload Using: [SERIAL]
- Upload Speed: [other] (serial upload only)

### Problem Description

After working on an issue related to https://github.com/esp8266/Arduino/issues/2186#issuecomment-486503752, I added an eraseConfig() into my code. After doing that, I started to see some weird behavior. One instance, the ESP will crash. This post is a result of working on understanding why it crashes and the very simple MCVE produces crashes in various ways. Any insight as to why is welcomed.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

```

//SDK:3.0.0-dev(c0f7b44)/Core:2.5.0=20500000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1/BearSSL:6778687

#include

void setup() {
Serial.begin(115200);
Serial.println();

//This eraseConfig causes the sketch to crash
ESP.eraseConfig();

//Including this mode line (while leaving out this setup's disconnect line)
//makes ESP crash once and then give crazy heap numbers
//WiFi.mode(WIFI_STA);

//Including this disconnect causes the heap values to be crazy
WiFi.disconnect();
}

void loop() {

//Try connecting to a non existent access point
WiFi.begin("nonexistentssid", "nonexistentpassword");
delay(2000);

//Leaving out this disconnect prevents crashing
WiFi.disconnect();

Serial.printf_P(PSTR("%d %d/%d/%d/%d\r\n"),
millis(),
ESP.getFreeHeap(),
ESP.getHeapFragmentation(),
ESP.getMaxFreeBlockSize(),
ESP.getFreeContStack()
);

}
```

### Debug Messages
Notice the getFreeHeap values in the last lines.

```
3724 51600/3/50408/3008
6229 51600/3/50408/3008
8737 51600/3/50408/3008
11251 51600/3/50408/3008

Exception (28):
epc1=0x4000df2f epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000033 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffb50 end: 3fffffc0 offset: 01a0
3ffffcf0: 40216e8b 4000444e 00002035 402263e6
3ffffd00: 00000033 00000010 402177a5 3ffecdbc
3ffffd10: 3ffef20c 00000000 3ffe8638 3ffef954
3ffffd20: 3ffef20c 402176cd 3ffecdbc 001ff000
3ffffd30: 3ffe8638 0000022b 0000022b 401005b8
3ffffd40: 3ffef2ad 3ffef6ac 0000000f 3ffed4fc
3ffffd50: 3ffe8638 3ffe8638 00000033 40219643
3ffffd60: 3ffed4b0 40219214 4021b884 3ffed4b0
3ffffd70: 40218d90 4022c93b 3ffef20c 000001ff
3ffffd80: 00000001 00000001 3ffffd90 4022c8d2 <
3ffffd90: 4021924f 3ffed5a8 3ffed5a8 00000020
3ffffda0: 4021b1cc 00000024 00000072 aa55aa55
3ffffdb0: 3ffece40 4021b190 3ffecdbc 00000012
3ffffdc0: 40219204 402191d8 3ffece40 00000012
3ffffdd0: 402191a3 3ffecdbc 00000012 4022cff3
3ffffde0: 40219754 3ffecdbc 00000000 4021b884
3ffffdf0: 40219181 3ffecf38 00000002 00000000
3ffffe00: 4021b63d 0000010f 3ffe856c 00000000
3ffffe10: 00000013 0000010f 3ffecfd8 4021b491
3ffffe20: 4021b49c 3ffe84dc 3ffe856c 00000003
3ffffe30: 4022d624 3ffe84dc 3ffe856c 3ffe856c
3ffffe40: 3ffef6ac 40202961 3ffe857c 40202897
3ffffe50: 332f3800 656e6f6e 74736978 70746e65
3ffffe60: 77737361 0064726f 3ffee32c 00000000
3ffffe70: 00000000 3ffee32c feefeffe feefeffe
3ffffe80: 3fffff50 3fffff20 00000008 0000c990
3ffffe90: 401050f8 00332155 3ffee494 00000000
3ffffea0: 3ffedcf0 3ffee494 3ffe8508 3ffee494
3ffffeb0: ffffff00 00ffffff 3ffffed0 40202bd0
3ffffec0: 4022d600 656e6f6e 74736978 73746e65
3ffffed0: 00646973 31352031 2f303036 30352f33
3ffffee0: 2f383034 656e6f6e 74736978 70746e65
3ffffef0: 77737361 0064726f 3ffee32c 00000000
3fffff00: 00000000 3ffee32c feefeffe feefeffe
3fffff10: 3fffff50 3fffff20 00000008 0000c990
3fffff20: 00000000 00000000 00002bf3 0000c981
3fffff30: 00000002 0000c401 4bc6a7f0 0000c990
3fffff40: 00000004 00000000 3ffee2f8 00000001
3fffff50: 40202a03 000007d0 000007d0 3ffee438
3fffff60: 3fffdad0 00000000 3ffee2f8 40202512
3fffff70: 00000bc0 001ff000 3ffee32c 40202d24
3fffff80: 00002bf3 0000001c 3ffee32c 40202b46
3fffff90: 00000000 00000000 00000001 3ffee438
3fffffa0: 3fffdad0 00000000 3ffee408 40203408
3fffffb0: feefeffe feefeffe 3ffe8508 40100a59
<<

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.