From 80aeacfb80ac0796a81d274fab26874dd91e8b49 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 22 Sep 2017 15:52:00 +0800 Subject: [PATCH] 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. --- cores/esp8266/Esp.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 03dcf9ca00..a8e12f916f 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -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() {