Просмотр исходного кода

flash: fix 80Mhz for new spi flash driver on esp32s2

Wangjialin 6 лет назад
Родитель
Сommit
d4e5980823

+ 1 - 1
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 */

+ 17 - 0
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;