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 Jun 28, 2024
1 parent e3f697b commit a066fd1
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 @@ -138,6 +138,7 @@ static void esp32c3_spi_write(
target_s *target, uint16_t command, target_addr32_t address, const void *buffer, size_t length);
static void esp32c3_spi_run_command(target_s *target, uint16_t command, target_addr32_t address);

static void esp32c3_mem_read(target_s *target, void *dest, target_addr64_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_write(target_flash_s *flash, target_addr32_t dest, const void *src, size_t length);
Expand Down Expand Up @@ -205,6 +206,8 @@ bool esp32c3_probe(target_s *const target)
flash->flash.length = MIN(flash->flash.length, ESP32_C3_IBUS_FLASH_SIZE);
/* Adjust over to our slightly modified versions of the Flash routines */
flash->flash.write = esp32c3_spi_flash_write;

target->mem_read = esp32c3_mem_read;
}
return true;
}
Expand Down Expand Up @@ -420,6 +423,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_addr64_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_write(
target_flash_s *const flash, const target_addr32_t dest, const void *const src, const size_t length)
{
Expand Down

0 comments on commit a066fd1

Please sign in to comment.