Skip to content

Commit

Permalink
esp32c3: Implemented a custom memory read routine that directly reads…
Browse files Browse the repository at this point in the history
… the SPI Flash to solve the access problem
  • Loading branch information
dragonmux committed Nov 27, 2023
1 parent d708f0f commit 3f6c32d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/target/esp32c3.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static void esp32c3_spi_write(
target_s *target, uint16_t command, target_addr_t address, const void *buffer, size_t length);
static void esp32c3_spi_run_command(target_s *target, uint16_t command, target_addr_t address);

static void esp32c3_mem_read(target_s *target, void *dest, target_addr_t src, size_t len);
static bool esp32c3_enter_flash_mode(target_s *target);
static bool esp32c3_exit_flash_mode(target_s *target);
static bool esp32c3_spi_flash_erase(target_flash_s *flash, target_addr_t addr, size_t length);
Expand Down Expand Up @@ -210,6 +211,8 @@ bool esp32c3_probe(target_s *const target)
priv->spi_flash_erase = flash->flash.erase;
flash->flash.write = esp32c3_spi_flash_write;
flash->flash.erase = esp32c3_spi_flash_erase;

target->mem_read = esp32c3_mem_read;
}
return true;
}
Expand Down Expand Up @@ -426,6 +429,18 @@ static bool esp32c3_exit_flash_mode(target_s *const target)
return true;
}

static void esp32c3_mem_read(target_s *const target, void *const dest, const target_addr_t src, const size_t len)
{
/* If the read is somewhere inside Flash, we have to special-case it */
if (src >= target->flash->start && src < target->flash->start + target->flash->length)
/* Reach entirely past the I-Cache system and read the SPI Flash directly using a standard read command */
esp32c3_spi_read(target, SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DUMMY_LEN(0U) | SPI_FLASH_OPCODE(0x03U),
src - target->flash->start, dest, len);
else
/* Otherwise delegate to the normal RISC-V 32 memory read routine */
riscv32_mem_read(target, dest, src, len);
}

static bool esp32c3_spi_flash_erase(target_flash_s *const flash, const target_addr_t addr, const size_t length)
{
target_s *const target = flash->t;
Expand Down

0 comments on commit 3f6c32d

Please sign in to comment.