Skip to content

Commit

Permalink
Fix ESP.eraseConfig() when using Core 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Mar 7, 2019
1 parent 83195fd commit 3488736
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ bool settingsRestoreJson(JsonObject& data);
// -----------------------------------------------------------------------------
char * ltrim(char * s);
void nice_delay(unsigned long ms);
void inline eraseSDKConfig();

#define ARRAYINIT(type, name, ...) type name[] = {__VA_ARGS__};

Expand Down
2 changes: 1 addition & 1 deletion code/espurna/terminal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void _terminalInitCommand() {
terminalOK();
resetReason(CUSTOM_RESET_TERMINAL);
_eepromCommit();
ESP.eraseConfig();
eraseSDKConfig();
*((int*) 0) = 0; // see https://github.com/esp8266/Arduino/issues/1494
});

Expand Down
17 changes: 17 additions & 0 deletions code/espurna/utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,23 @@ bool checkNeedsReset() {
return _reset_reason > 0;
}

// Use fixed method for Core 2.3.0, because it erases only 2 out of 4 SDK-reserved sectors
// Fixed since 2.4.0, see: esp8266/core/esp8266/Esp.cpp: ESP::eraseConfig()
void erasesdkconfig() {
#if defined(arduino_esp8266_release_2_3_0)
const size_t cfgsize = 0x4000;
size_t cfgaddr = esp.getflashchipsize() - cfgsize;

for (size_t offset = 0; offset < cfgsize; offset += spi_flash_sec_size) {
if (!esp.flasherasesector((cfgaddr + offset) / spi_flash_sec_size)) {
return;
}
}
#else
esp.eraseconfig();
#endif
}

// -----------------------------------------------------------------------------

char * ltrim(char * s) {
Expand Down

0 comments on commit 3488736

Please sign in to comment.