From d4e59808233c08ff2630aafc0fce65d62b964b79 Mon Sep 17 00:00:00 2001 From: Wangjialin Date: Thu, 16 Jan 2020 14:41:41 +0800 Subject: [PATCH] flash: fix 80Mhz for new spi flash driver on esp32s2 --- components/soc/esp32s2beta/include/soc/soc.h | 2 +- components/spi_flash/esp_flash_spi_init.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/soc/esp32s2beta/include/soc/soc.h b/components/soc/esp32s2beta/include/soc/soc.h index 9d30529818..353c66f57a 100644 --- a/components/soc/esp32s2beta/include/soc/soc.h +++ b/components/soc/esp32s2beta/include/soc/soc.h @@ -239,7 +239,7 @@ #define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16 #define SPI_CLK_DIV 4 #define TICKS_PER_US_ROM 40 // CPU is 80MHz -#define GPIO_MATRIX_DELAY_NS 15 +#define GPIO_MATRIX_DELAY_NS 0 //}} /* Overall memory map */ diff --git a/components/spi_flash/esp_flash_spi_init.c b/components/spi_flash/esp_flash_spi_init.c index 7299cb47ba..459ba16396 100644 --- a/components/spi_flash/esp_flash_spi_init.c +++ b/components/spi_flash/esp_flash_spi_init.c @@ -50,6 +50,7 @@ __attribute__((unused)) static const char TAG[] = "spi_flash"; #define DEFAULT_FLASH_MODE SPI_FLASH_FASTRD #endif +#if CONFIG_IDF_TARGET_ESP32 #define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \ .host_id = SPI_HOST,\ .speed = DEFAULT_FLASH_SPEED, \ @@ -57,6 +58,16 @@ __attribute__((unused)) static const char TAG[] = "spi_flash"; .iomux = false, \ .input_delay_ns = 0,\ } +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#include "esp32s2beta/rom/efuse.h" +#define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \ + .host_id = SPI_HOST,\ + .speed = DEFAULT_FLASH_SPEED, \ + .cs_num = 0, \ + .iomux = true, \ + .input_delay_ns = 0,\ +} +#endif esp_flash_t *esp_flash_default_chip = NULL; @@ -181,6 +192,12 @@ static DRAM_ATTR esp_flash_t default_chip = { esp_err_t esp_flash_init_default_chip(void) { memspi_host_config_t cfg = ESP_FLASH_HOST_CONFIG_DEFAULT(); + + #ifdef CONFIG_IDF_TARGET_ESP32S2BETA + // For esp32s2 spi IOs are configured as from IO MUX by default + cfg.iomux = ets_efuse_get_spiconfig() == 0 ? true : false; + #endif + //the host is already initialized, only do init for the data and load it to the host spi_flash_hal_init(&default_driver_data, &cfg); default_chip.host->driver_data = &default_driver_data;