From a643ea94329b520e6c76000922a8cf9a83a0a81a Mon Sep 17 00:00:00 2001 From: jiangguangming Date: Thu, 11 Mar 2021 19:39:27 +0800 Subject: [PATCH] spi_flash: make spiflash compatible with ESP32C3 and ESP32S3 ROM --- components/hal/include/hal/spi_flash_types.h | 5 +++++ components/hal/spi_flash_hal_iram.c | 16 +++++++++++++++- .../spi_flash/include/memspi_host_driver.h | 1 + components/spi_flash/memspi_host_driver.c | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/components/hal/include/hal/spi_flash_types.h b/components/hal/include/hal/spi_flash_types.h index 8e7004548a..ed68d24f60 100644 --- a/components/hal/include/hal/spi_flash_types.h +++ b/components/hal/include/hal/spi_flash_types.h @@ -189,6 +189,11 @@ struct spi_flash_host_driver_s { */ esp_err_t (*flush_cache)(spi_flash_host_inst_t* host, uint32_t addr, uint32_t size); + /** + * Suspend check erase/program operation, reserved for ESP32-C3 and ESP32-S3 spi flash ROM IMPL. + */ + void (*check_suspend)(spi_flash_host_inst_t *host); + /** * Resume flash from suspend manually */ diff --git a/components/hal/spi_flash_hal_iram.c b/components/hal/spi_flash_hal_iram.c index 8fe43a3e1a..f8878f9169 100644 --- a/components/hal/spi_flash_hal_iram.c +++ b/components/hal/spi_flash_hal_iram.c @@ -20,10 +20,11 @@ void spi_flash_hal_disable_auto_resume_mode(spi_flash_host_inst_t *host); void spi_flash_hal_disable_auto_suspend_mode(spi_flash_host_inst_t *host); void spi_flash_hal_setup_auto_resume_mode(spi_flash_host_inst_t *host); #endif //SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND -#include "spi_flash_hal_common.inc" #ifndef CONFIG_SPI_FLASH_ROM_IMPL +#include "spi_flash_hal_common.inc" + // HAL for // - MEMSPI // - SPI1~3 on ESP32/S2/S3/C3 @@ -93,6 +94,19 @@ esp_err_t spi_flash_hal_set_write_protect(spi_flash_host_inst_t *host, bool wp) return ESP_OK; } +#else // defined CONFIG_SPI_FLASH_ROM_IMPL + +static inline spi_dev_t *get_spi_dev(spi_flash_host_inst_t *host) +{ + return ((spi_flash_hal_context_t*)host)->spi; +} + +static inline int get_host_id(spi_flash_host_inst_t* host) +{ + spi_dev_t *dev = get_spi_dev(host); + return spi_flash_ll_hw_get_id(dev); +} + #endif // !CONFIG_SPI_FLASH_ROM_IMPL uint32_t spi_flash_hal_check_status(spi_flash_host_inst_t *host) diff --git a/components/spi_flash/include/memspi_host_driver.h b/components/spi_flash/include/memspi_host_driver.h index 269bd991d0..1c7b3cb29c 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 = NULL, \ .resume = spi_flash_hal_resume, \ .suspend = spi_flash_hal_suspend,\ .sus_setup = spi_flash_hal_setup_read_suspend,\ diff --git a/components/spi_flash/memspi_host_driver.c b/components/spi_flash/memspi_host_driver.c index f713df829f..d15cb25aef 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 = NULL, .resume = spi_flash_hal_resume, .suspend = spi_flash_hal_suspend, };