@@ -138,6 +138,7 @@ static void esp32c3_spi_write(
138138 target_s * target , uint16_t command , target_addr32_t address , const void * buffer , size_t length );
139139static void esp32c3_spi_run_command (target_s * target , uint16_t command , target_addr32_t address );
140140
141+ static void esp32c3_mem_read (target_s * target , void * dest , target_addr64_t src , size_t len );
141142static bool esp32c3_enter_flash_mode (target_s * target );
142143static bool esp32c3_exit_flash_mode (target_s * target );
143144static bool esp32c3_spi_flash_write (target_flash_s * flash , target_addr32_t dest , const void * src , size_t length );
@@ -205,6 +206,8 @@ bool esp32c3_probe(target_s *const target)
205206 flash -> flash .length = MIN (flash -> flash .length , ESP32_C3_IBUS_FLASH_SIZE );
206207 /* Adjust over to our slightly modified versions of the Flash routines */
207208 flash -> flash .write = esp32c3_spi_flash_write ;
209+
210+ target -> mem_read = esp32c3_mem_read ;
208211 }
209212 return true;
210213}
@@ -420,6 +423,18 @@ static bool esp32c3_exit_flash_mode(target_s *const target)
420423 return true;
421424}
422425
426+ static void esp32c3_mem_read (target_s * const target , void * const dest , const target_addr64_t src , const size_t len )
427+ {
428+ /* If the read is somewhere inside Flash, we have to special-case it */
429+ if (src >= target -> flash -> start && src < target -> flash -> start + target -> flash -> length )
430+ /* Reach entirely past the I-Cache system and read the SPI Flash directly using a standard read command */
431+ esp32c3_spi_read (target , SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DUMMY_LEN (0U ) | SPI_FLASH_OPCODE (0x03U ),
432+ src - target -> flash -> start , dest , len );
433+ else
434+ /* Otherwise delegate to the normal RISC-V 32 memory read routine */
435+ riscv32_mem_read (target , dest , src , len );
436+ }
437+
423438static bool esp32c3_spi_flash_write (
424439 target_flash_s * const flash , const target_addr32_t dest , const void * const src , const size_t length )
425440{
0 commit comments