From d6c40c7c1dcb5ce54b96d07669f169994942933c Mon Sep 17 00:00:00 2001 From: chenjianqiang Date: Thu, 9 May 2019 15:26:24 +0800 Subject: [PATCH] bugfix(flash): improve spi cs timing settings for flash cs setup time is recomemded to be 1.5T, and cs hold time is recommended to be 2.5T. (cs_setup = 1, cs_setup_time = 0; cs_hold = 1, cs_hold_time = 1) --- .../bootloader_support/include/bootloader_common.h | 8 ++++++++ .../bootloader_support/src/bootloader_common.c | 12 ++++++++++++ components/bootloader_support/src/bootloader_init.c | 3 +++ components/esp32/cpu_start.c | 3 +++ 4 files changed, 26 insertions(+) diff --git a/components/bootloader_support/include/bootloader_common.h b/components/bootloader_support/include/bootloader_common.h index 2475d842a..bd32a8d7c 100644 --- a/components/bootloader_support/include/bootloader_common.h +++ b/components/bootloader_support/include/bootloader_common.h @@ -146,6 +146,14 @@ esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t */ void bootloader_common_vddsdio_configure(); +/** + * @brief Set the flash CS setup and hold time. + * + * CS setup time is recomemded to be 1.5T, and CS hold time is recommended to be 2.5T. + * cs_setup = 1, cs_setup_time = 0; cs_hold = 1, cs_hold_time = 1 + */ +void bootloader_common_set_flash_cs_timing(); + #ifdef __cplusplus } #endif diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index ed0169a96..795a6c9f5 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -25,6 +25,8 @@ #include "bootloader_common.h" #include "soc/gpio_periph.h" #include "soc/rtc.h" +#include "soc/efuse_reg.h" +#include "soc/spi_reg.h" #include "esp_image_format.h" #include "bootloader_sha.h" #include "sys/param.h" @@ -270,3 +272,13 @@ void bootloader_common_vddsdio_configure() } #endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST } + +void bootloader_common_set_flash_cs_timing() +{ + SET_PERI_REG_MASK(SPI_USER_REG(0), SPI_CS_HOLD_M | SPI_CS_SETUP_M); + SET_PERI_REG_BITS(SPI_CTRL2_REG(0), SPI_HOLD_TIME_V, 1, SPI_HOLD_TIME_S); + SET_PERI_REG_BITS(SPI_CTRL2_REG(0), SPI_SETUP_TIME_V, 0, SPI_SETUP_TIME_S); + SET_PERI_REG_MASK(SPI_USER_REG(1), SPI_CS_HOLD_M | SPI_CS_SETUP_M); + SET_PERI_REG_BITS(SPI_CTRL2_REG(1), SPI_HOLD_TIME_V, 1, SPI_HOLD_TIME_S); + SET_PERI_REG_BITS(SPI_CTRL2_REG(1), SPI_SETUP_TIME_V, 0, SPI_SETUP_TIME_S); +} diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index 6a94713d1..17c94f190 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -394,6 +394,9 @@ static void IRAM_ATTR flash_gpio_configure(const esp_image_header_t* pfhdr) #endif } } + + // improve the flash cs timing. + bootloader_common_set_flash_cs_timing(); } static void uart_console_configure(void) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 4b8c2d5c4..460e350ed 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -71,6 +71,7 @@ #include "trax.h" #include "esp_ota_ops.h" #include "esp_efuse.h" +#include "bootloader_common.h" #define STRINGIFY(s) STRINGIFY2(s) #define STRINGIFY2(s) #s @@ -172,6 +173,8 @@ void IRAM_ATTR call_start_cpu0() abort(); #endif } +# else // If psram is uninitialized, we need to improve the flash cs timing. + bootloader_common_set_flash_cs_timing(); #endif ESP_EARLY_LOGI(TAG, "Pro cpu up.");