Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit e937b68

Browse files
committed
esp32c3: Switched out the custom Flash erase implementation for the one in spi.c w/ a small modification
1 parent d971b41 commit e937b68

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/target/esp32c3.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
typedef struct esp32c3_priv {
126126
uint32_t wdt_config[4];
127127
target_addr_t last_invalidated_sector;
128+
flash_erase_func spi_flash_erase;
128129
} esp32c3_priv_s;
129130

130131
static void esp32c3_disable_wdts(target_s *target);
@@ -205,6 +206,8 @@ bool esp32c3_probe(target_s *const target)
205206
/* Adjust the resulting capacity to not exceed the available memory mapping window size */
206207
flash->flash.length = MIN(flash->flash.length, ESP32_C3_IBUS_FLASH_SIZE);
207208
/* Adjust over to our slightly modified versions of the Flash routines */
209+
esp32c3_priv_s *const priv = (esp32c3_priv_s *)target->target_storage;
210+
priv->spi_flash_erase = flash->flash.erase;
208211
flash->flash.write = esp32c3_spi_flash_write;
209212
flash->flash.erase = esp32c3_spi_flash_erase;
210213
}
@@ -434,20 +437,15 @@ static bool esp32c3_exit_flash_mode(target_s *const target)
434437

435438
static bool esp32c3_spi_flash_erase(target_flash_s *const flash, const target_addr_t addr, const size_t length)
436439
{
437-
(void)length;
438440
target_s *const target = flash->t;
439-
const spi_flash_s *const spi_flash = (spi_flash_s *)flash;
440-
esp32c3_spi_run_command(target, SPI_FLASH_CMD_WRITE_ENABLE, 0U);
441-
if (!(esp32c3_spi_read_status(target) & SPI_FLASH_STATUS_WRITE_ENABLED))
441+
esp32c3_priv_s *const priv = (esp32c3_priv_s *)target->target_storage;
442+
/* Call the underlying erase routine */
443+
const bool result = priv->spi_flash_erase(flash, addr, length);
444+
/* If it didn't work out, propergate the failure */
445+
if (!result)
442446
return false;
443-
444-
esp32c3_spi_run_command(
445-
target, SPI_FLASH_CMD_SECTOR_ERASE | SPI_FLASH_OPCODE(spi_flash->sector_erase_opcode), addr - flash->start);
446-
while (esp32c3_spi_read_status(target) & SPI_FLASH_STATUS_BUSY)
447-
continue;
448447
/* Update the address of the last invalidated sector so we can correctly invalidate the i-cache and reload it */
449-
esp32c3_priv_s *const priv = (esp32c3_priv_s *)target->target_storage;
450-
priv->last_invalidated_sector = addr + length;
448+
priv->last_invalidated_sector = addr + flash->blocksize;
451449
return true;
452450
}
453451

0 commit comments

Comments
 (0)