Browse Source

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

pull/1623/head
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
8de61598f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions
  1. +1
    -0
      code/espurna/config/prototypes.h
  2. +1
    -1
      code/espurna/terminal.ino
  3. +19
    -0
      code/espurna/utils.ino

+ 1
- 0
code/espurna/config/prototypes.h View File

@ -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__};


+ 1
- 1
code/espurna/terminal.ino View File

@ -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
});


+ 19
- 0
code/espurna/utils.ino View File

@ -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) {


Loading…
Cancel
Save