diff --git a/tasmota/settings.ino b/tasmota/settings.ino index fe362179b..552f04937 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -539,6 +539,25 @@ void SettingsLoad(void) RtcSettingsLoad(); } +void EspErase(uint32_t start_sector, uint32_t end_sector) +{ + bool serial_output = (LOG_LEVEL_DEBUG_MORE <= seriallog_level); + for (uint32_t sector = start_sector; sector < end_sector; sector++) { + + bool result = ESP.flashEraseSector(sector); // Arduino core - erases flash as seen by SDK +// bool result = !SPIEraseSector(sector); // SDK - erases flash as seen by SDK +// bool result = EsptoolEraseSector(sector); // Esptool - erases flash completely (slow) + + if (serial_output) { + Serial.printf_P(PSTR(D_LOG_APPLICATION D_ERASED_SECTOR " %d %s\n"), sector, (result) ? D_OK : D_ERROR); + delay(10); + } else { + yield(); + } + OsWatchLoop(); + } +} + void SettingsErase(uint8_t type) { /* @@ -572,31 +591,8 @@ void SettingsErase(uint8_t type) AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart); -/* - bool _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level); - - for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) { - - bool result = ESP.flashEraseSector(_sector); // Arduino core - erases flash as seen by SDK -// bool result = !SPIEraseSector(_sector); // SDK - erases flash as seen by SDK -// bool result = EsptoolEraseSector(_sector); // Esptool - erases flash completely (slow) - - if (_serialoutput) { - Serial.print(F(D_LOG_APPLICATION D_ERASED_SECTOR " ")); - Serial.print(_sector); - if (result) { - Serial.println(F(" " D_OK)); - } else { - Serial.println(F(" " D_ERROR)); - } - delay(10); - } else { - yield(); - } - OsWatchLoop(); - } -*/ - EsptoolErase(_sectorStart, _sectorEnd); // Esptool - erases flash completely (fast) +// EspErase(_sectorStart, _sectorEnd); // Arduino core and SDK - erases flash as seen by SDK + EsptoolErase(_sectorStart, _sectorEnd); // Esptool - erases flash completely #endif // FIRMWARE_MINIMAL } diff --git a/tasmota/support_esptool.ino b/tasmota/support_esptool.ino index f030e113d..bf62a8da1 100644 --- a/tasmota/support_esptool.ino +++ b/tasmota/support_esptool.ino @@ -77,7 +77,6 @@ static void spi_write_enable(void) while(READ_REG(SPI_CMD_REG) != 0) { } } -/* bool EsptoolEraseSector(uint32_t sector) { spi_write_enable(); @@ -90,7 +89,6 @@ bool EsptoolEraseSector(uint32_t sector) return true; } -*/ void EsptoolErase(uint32_t start_sector, uint32_t end_sector) { @@ -100,18 +98,18 @@ void EsptoolErase(uint32_t start_sector, uint32_t end_sector) while (remaining_erase_sector > 0) { spi_write_enable(); - uint32_t command = SPI_FLASH_SE; // Sector erase, 4KB + uint32_t command = SPI_FLASH_SE; // Sector erase, 4kB uint32_t sectors_to_erase = 1; if (remaining_erase_sector >= SECTORS_PER_BLOCK && next_erase_sector % SECTORS_PER_BLOCK == 0) { - command = SPI_FLASH_BE; // Block erase 64KB if we have space for it + command = SPI_FLASH_BE; // Block erase 64kB if we have space for it sectors_to_erase = SECTORS_PER_BLOCK; } uint32_t addr = next_erase_sector * SPI_FLASH_SEC_SIZE; spi_wait_ready(); WRITE_REG(SPI_ADDR_REG, addr & 0xffffff); - WRITE_REG(SPI_CMD_REG, command); // Sector erase, 4KB + WRITE_REG(SPI_CMD_REG, command); // Perform erase, 4kB or 65kB while(READ_REG(SPI_CMD_REG) != 0) { } remaining_erase_sector -= sectors_to_erase; next_erase_sector += sectors_to_erase;