|
125 | 125 | typedef struct esp32c3_priv { |
126 | 126 | uint32_t wdt_config[4]; |
127 | 127 | target_addr_t last_invalidated_sector; |
| 128 | + flash_erase_func spi_flash_erase; |
128 | 129 | } esp32c3_priv_s; |
129 | 130 |
|
130 | 131 | static void esp32c3_disable_wdts(target_s *target); |
@@ -205,6 +206,8 @@ bool esp32c3_probe(target_s *const target) |
205 | 206 | /* Adjust the resulting capacity to not exceed the available memory mapping window size */ |
206 | 207 | flash->flash.length = MIN(flash->flash.length, ESP32_C3_IBUS_FLASH_SIZE); |
207 | 208 | /* 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; |
208 | 211 | flash->flash.write = esp32c3_spi_flash_write; |
209 | 212 | flash->flash.erase = esp32c3_spi_flash_erase; |
210 | 213 | } |
@@ -434,20 +437,15 @@ static bool esp32c3_exit_flash_mode(target_s *const target) |
434 | 437 |
|
435 | 438 | static bool esp32c3_spi_flash_erase(target_flash_s *const flash, const target_addr_t addr, const size_t length) |
436 | 439 | { |
437 | | - (void)length; |
438 | 440 | 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) |
442 | 446 | 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; |
448 | 447 | /* 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; |
451 | 449 | return true; |
452 | 450 | } |
453 | 451 |
|
|
0 commit comments