From 05da91f0db1addbbf67bd9d77f2e8a08bcad6659 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Thu, 4 Jun 2020 14:51:34 +0530 Subject: [PATCH] spi_flash: add configuration option to select flash write chunk size Flash write operation is broken down into smaller chunk writes. Size of this chunk was previously set to 8K but that in-turn meant cache and non-IRAM resident interrupts could stay disabled upto ~24msec for 8K flash write operation. If chunk size is brought down to 256 (typical flash page size) then it brings down cache and non-IRAM interrupts disable duration to ~1msec. Fix here keeps defaults same but provides configuration option to tweak the setting based on application requirement. --- components/spi_flash/Kconfig | 10 ++++++++++ components/spi_flash/esp_flash_api.c | 5 +++++ components/spi_flash/flash_ops.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/components/spi_flash/Kconfig b/components/spi_flash/Kconfig index 678585248..cb41293a1 100644 --- a/components/spi_flash/Kconfig +++ b/components/spi_flash/Kconfig @@ -130,6 +130,16 @@ menu "SPI Flash driver" help Defines how many ticks will be before returning to continue a erasing. + config SPI_FLASH_WRITE_CHUNK_SIZE + int "Flash write chunk size" + default 8192 + range 256 8192 + help + Flash write is broken down in terms of multiple (smaller) write operations. + This configuration options helps to set individual write chunk size, smaller + value here ensures that cache (and non-IRAM resident interrupts) remains + disabled for shorter duration. + menu "Auto-detect flash chips" config SPI_FLASH_SUPPORT_ISSI_CHIP diff --git a/components/spi_flash/esp_flash_api.c b/components/spi_flash/esp_flash_api.c index 5bcdc20b0..2aa2aad38 100644 --- a/components/spi_flash/esp_flash_api.c +++ b/components/spi_flash/esp_flash_api.c @@ -28,7 +28,12 @@ static const char TAG[] = "spi_flash"; +#ifdef CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE +#define MAX_WRITE_CHUNK CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE /* write in chunks */ +#else #define MAX_WRITE_CHUNK 8192 /* write in chunks */ +#endif // CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE + #define MAX_READ_CHUNK 16384 diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index a561cb4b5..2e8dcd9e3 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -53,7 +53,12 @@ esp_rom_spiflash_result_t IRAM_ATTR spi_flash_write_encrypted_chip(size_t dest_a /* Limit number of bytes written/read in a single SPI operation, as these operations disable all higher priority tasks from running. */ +#ifdef CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE +#define MAX_WRITE_CHUNK CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE +#else #define MAX_WRITE_CHUNK 8192 +#endif // CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE + #define MAX_READ_CHUNK 16384 static const char *TAG __attribute__((unused)) = "spi_flash";