From 7fafe8e2fddc0b629fca7984c47b4e41b0972ed6 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Fri, 7 Apr 2023 00:00:09 +0100 Subject: [PATCH] esp32c3: Hacky patch to make Flash write almost work correctly at the loss of a huge amount of speed (25% the speed) --- src/target/esp32c3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/esp32c3.c b/src/target/esp32c3.c index 2c0596b9ca0..2437355da4e 100644 --- a/src/target/esp32c3.c +++ b/src/target/esp32c3.c @@ -424,15 +424,15 @@ static bool esp32c3_spi_flash_write( target_flash_s *const flash, const target_addr32_t dest, const void *const src, const size_t length) { target_s *const target = flash->t; - const spi_flash_s *const spi_flash = (spi_flash_s *)flash; + // const spi_flash_s *const spi_flash = (spi_flash_s *)flash; const target_addr_t begin = dest - flash->start; const char *const buffer = (const char *)src; - for (size_t offset = 0; offset < length; offset += spi_flash->page_size) { + for (size_t offset = 0; offset < length; offset += 64U) { esp32c3_spi_run_command(target, SPI_FLASH_CMD_WRITE_ENABLE, 0U); if (!(esp32c3_spi_read_status(target) & SPI_FLASH_STATUS_WRITE_ENABLED)) return false; - const size_t amount = MIN(length - offset, spi_flash->page_size); + const size_t amount = MIN(length - offset, 64U); esp32c3_spi_write(target, SPI_FLASH_CMD_PAGE_PROGRAM, begin + offset, buffer + offset, amount); while (esp32c3_spi_read_status(target) & SPI_FLASH_STATUS_BUSY) continue;