Skip to content

Commit

Permalink
esp32c3: Hacky patch to make Flash write almost work correctly at the…
Browse files Browse the repository at this point in the history
… loss of a huge amount of speed (25% the speed)
  • Loading branch information
dragonmux committed Aug 12, 2024
1 parent 9c0a41e commit 7fafe8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/target/esp32c3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7fafe8e

Please sign in to comment.