Skip to content

Commit

Permalink
Fix erase size in ESP.eraseConfig
Browse files Browse the repository at this point in the history
SDK uses final 4 sectors of flash for configuration data.
ESP.eraseConfig would only erase 2 sectors, so in some cases of
corrupted data ("system param error"), users could not fix the issue
using ESP.eraseConfig, and had to use esptool instead.

Thanks @HugoML for reporting this.
  • Loading branch information
igrr committed Oct 15, 2017
1 parent 93ad1fb commit 80aeacf
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,22 +397,16 @@ struct rst_info * EspClass::getResetInfoPtr(void) {

bool EspClass::eraseConfig(void) {
bool ret = true;
size_t cfgAddr = (ESP.getFlashChipSize() - 0x4000);
size_t cfgSize = (8*1024);
const size_t cfgSize = 0x4000;
size_t cfgAddr = ESP.getFlashChipSize() - cfgSize;

noInterrupts();
while(cfgSize) {

if(spi_flash_erase_sector((cfgAddr / SPI_FLASH_SEC_SIZE)) != SPI_FLASH_RESULT_OK) {
ret = false;
for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) {
if (!flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) {
return false;
}

cfgSize -= SPI_FLASH_SEC_SIZE;
cfgAddr += SPI_FLASH_SEC_SIZE;
}
interrupts();

return ret;
return true;
}

uint32_t EspClass::getSketchSize() {
Expand Down

0 comments on commit 80aeacf

Please sign in to comment.