From d48c4e1da7a0293abd8d369c8a37130c7275efc2 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Thu, 22 Oct 2020 18:54:42 +0800 Subject: [PATCH] spi_flash_test: workaround for broken ROM API after new API calls. --- components/spi_flash/test/test_read_write.c | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/spi_flash/test/test_read_write.c b/components/spi_flash/test/test_read_write.c index 1ade2bdaa1..14f1773bab 100644 --- a/components/spi_flash/test/test_read_write.c +++ b/components/spi_flash/test/test_read_write.c @@ -69,6 +69,26 @@ static int cmp_or_dump(const void *a, const void *b, size_t len) return r; } +static void IRAM_ATTR fix_rom_func(void) +{ +#ifdef CONFIG_IDF_TARGET_ESP32S2 + esp_rom_spiflash_read_mode_t read_mode; +# if defined CONFIG_ESPTOOLPY_FLASHMODE_QIO + read_mode = ESP_ROM_SPIFLASH_QIO_MODE; +# elif defined CONFIG_ESPTOOLPY_FLASHMODE_QOUT + read_mode = ESP_ROM_SPIFLASH_QOUT_MODE; +# elif defined CONFIG_ESPTOOLPY_FLASHMODE_DIO + read_mode = ESP_ROM_SPIFLASH_DIO_MODE; +# elif defined CONFIG_ESPTOOLPY_FLASHMODE_DOUT + read_mode = ESP_ROM_SPIFLASH_DOUT_MODE; +# endif + //Currently only call this can fix the rom_read issue, maybe we need to call more functions (freq, dummy, etc) in the future + spi_flash_disable_interrupts_caches_and_other_cpu(); + esp_rom_spiflash_config_readmode(read_mode); + spi_flash_enable_interrupts_caches_and_other_cpu(); +#endif +} + static void IRAM_ATTR test_read(int src_off, int dst_off, int len) { uint32_t src_buf[16]; @@ -161,6 +181,8 @@ static void IRAM_ATTR test_write(int dst_off, int src_off, int len) } ESP_ERROR_CHECK(spi_flash_write(start + dst_off, src_buf + src_off, len)); + fix_rom_func(); + spi_flash_disable_interrupts_caches_and_other_cpu(); esp_rom_spiflash_result_t rc = esp_rom_spiflash_read(start, dst_buf, sizeof(dst_buf)); spi_flash_enable_interrupts_caches_and_other_cpu();