Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESP.eraseConfig() when using Core 2.3.0 #1616

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
bool 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
19 changes: 19 additions & 0 deletions code/espurna/utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,25 @@ 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()
bool 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 false;
}
}

return true;
#else
return ESP.eraseConfig();
#endif
}

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

char * ltrim(char * s) {
Expand Down