diff --git a/components/spi_flash/esp_flash_api.c b/components/spi_flash/esp_flash_api.c index bc9bede10b..80f663467b 100644 --- a/components/spi_flash/esp_flash_api.c +++ b/components/spi_flash/esp_flash_api.c @@ -173,6 +173,9 @@ bool esp_flash_chip_driver_initialized(const esp_flash_t *chip) return true; } +#ifdef CONFIG_SPI_FLASH_AUTO_SUSPEND + spi_flash_ll_auto_suspend_init(spi_flash_ll_get_hw(SPI_HOST), val); +#endif esp_err_t IRAM_ATTR esp_flash_init(esp_flash_t *chip) { // Chip init flow diff --git a/components/spi_flash/esp_flash_spi_init.c b/components/spi_flash/esp_flash_spi_init.c index 73eaf6dad4..5095d2f6a7 100644 --- a/components/spi_flash/esp_flash_spi_init.c +++ b/components/spi_flash/esp_flash_spi_init.c @@ -255,6 +255,10 @@ esp_err_t esp_flash_init_default_chip(void) return err; } +#ifdef CONFIG_SPI_FLASH_AUTO_SUSPEND + spi_flash_hal_setup_auto_suspend_mode(default_chip.host); +#endif + // ROM TODO: account for non-standard default pins in efuse // ROM TODO: to account for chips which are slow to power on, maybe keep probing in a loop here err = esp_flash_init(&default_chip); diff --git a/components/spi_flash/include/memspi_host_driver.h b/components/spi_flash/include/memspi_host_driver.h index edc6c705eb..e3ad68f4e3 100644 --- a/components/spi_flash/include/memspi_host_driver.h +++ b/components/spi_flash/include/memspi_host_driver.h @@ -35,6 +35,7 @@ .configure_host_io_mode = spi_flash_hal_configure_host_io_mode, \ .poll_cmd_done = spi_flash_hal_poll_cmd_done, \ .flush_cache = memspi_host_flush_cache, \ + .check_suspend = memspi_host_cb_check_suspend, \ } /// configuration for the memspi host @@ -176,3 +177,11 @@ int memspi_host_read_data_slicer(spi_flash_host_inst_t *host, uint32_t address, * @return Length that can actually be written in one `program_page` call in `spi_flash_host_driver_t`. */ int memspi_host_write_data_slicer(spi_flash_host_inst_t *host, uint32_t address, uint32_t len, uint32_t *align_address, uint32_t page_size); + +/** + * @brief Check the suspend status and resume a suspended operation. + * + * @param host The driver context. + * + */ +void memspi_host_cb_check_suspend(spi_flash_host_inst_t *host); diff --git a/components/spi_flash/memspi_host_driver.c b/components/spi_flash/memspi_host_driver.c index edbfc00325..1cedc303c4 100644 --- a/components/spi_flash/memspi_host_driver.c +++ b/components/spi_flash/memspi_host_driver.c @@ -61,6 +61,7 @@ static const spi_flash_host_driver_t esp_flash_gpspi_host = { .configure_host_io_mode = spi_flash_hal_gpspi_configure_host_io_mode, .poll_cmd_done = spi_flash_hal_gpspi_poll_cmd_done, .flush_cache = NULL, + .check_suspend = memspi_host_cb_check_suspend, }; #endif diff --git a/components/spi_flash/spi_flash_os_func_app.c b/components/spi_flash/spi_flash_os_func_app.c index f9c334ac3f..3df88bd9a1 100644 --- a/components/spi_flash/spi_flash_os_func_app.c +++ b/components/spi_flash/spi_flash_os_func_app.c @@ -67,12 +67,16 @@ static inline IRAM_ATTR bool on_spi1_check_yield(spi1_app_func_arg_t* ctx); IRAM_ATTR static void cache_enable(void* arg) { +#ifndef CONFIG_SPI_FLASH_AUTO_SUSPEND g_flash_guard_default_ops.end(); +#endif } IRAM_ATTR static void cache_disable(void* arg) { +#ifndef CONFIG_SPI_FLASH_AUTO_SUSPEND g_flash_guard_default_ops.start(); +#endif } static IRAM_ATTR esp_err_t spi_start(void *arg)