Skip to content

Commit 80aeacf

Browse files
committed
Fix erase size in ESP.eraseConfig
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.
1 parent 93ad1fb commit 80aeacf

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

cores/esp8266/Esp.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,16 @@ struct rst_info * EspClass::getResetInfoPtr(void) {
397397

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

403-
noInterrupts();
404-
while(cfgSize) {
405-
406-
if(spi_flash_erase_sector((cfgAddr / SPI_FLASH_SEC_SIZE)) != SPI_FLASH_RESULT_OK) {
407-
ret = false;
403+
for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) {
404+
if (!flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) {
405+
return false;
408406
}
409-
410-
cfgSize -= SPI_FLASH_SEC_SIZE;
411-
cfgAddr += SPI_FLASH_SEC_SIZE;
412407
}
413-
interrupts();
414408

415-
return ret;
409+
return true;
416410
}
417411

418412
uint32_t EspClass::getSketchSize() {

0 commit comments

Comments
 (0)