From a212d866f46ccd5136ddc4b090a6f0b1338d8e50 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Thu, 20 May 2021 20:51:38 +0800 Subject: [PATCH] spi_flash: fix cs line setup to make the flash driver more stable --- components/soc/esp32/include/hal/spi_flash_ll.h | 6 ++++++ components/soc/src/hal/spi_flash_hal_iram.c | 1 + 2 files changed, 7 insertions(+) diff --git a/components/soc/esp32/include/hal/spi_flash_ll.h b/components/soc/esp32/include/hal/spi_flash_ll.h index a30284fa65..bdc308595e 100644 --- a/components/soc/esp32/include/hal/spi_flash_ll.h +++ b/components/soc/esp32/include/hal/spi_flash_ll.h @@ -340,3 +340,9 @@ static inline void spi_flash_ll_set_dummy(spi_dev_t *dev, uint32_t dummy_n) dev->user.usr_dummy = dummy_n ? 1 : 0; dev->user1.usr_dummy_cyclelen = dummy_n - 1; } + +static inline void spi_flash_ll_set_cs_setup(spi_dev_t *dev, uint32_t cs_setup_time) +{ + dev->user.cs_setup = (cs_setup_time > 0 ? 1 : 0); + dev->ctrl2.setup_time = cs_setup_time - 1; +} diff --git a/components/soc/src/hal/spi_flash_hal_iram.c b/components/soc/src/hal/spi_flash_hal_iram.c index a6fb23fe5a..e91b243fd0 100644 --- a/components/soc/src/hal/spi_flash_hal_iram.c +++ b/components/soc/src/hal/spi_flash_hal_iram.c @@ -38,6 +38,7 @@ esp_err_t spi_flash_hal_device_config(spi_flash_host_driver_t *host) spi_flash_ll_reset(dev); spi_flash_ll_set_cs_pin(dev, drv_data->cs_num); spi_flash_ll_set_clock(dev, &drv_data->clock_conf); + spi_flash_ll_set_cs_setup(dev, 1); /* * workaround for the ROM: the ROM, as well as the OpenOCD, don't know the