From 5a3d2b18743660f2ba569c55682292b3c9d8cae8 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 1 Apr 2021 19:55:15 +0800 Subject: [PATCH] light sleep: modify some sleep params for esp32s3 --- components/esp32s3/Kconfig | 18 ++++++++++++++++++ components/esp_hw_support/sleep_modes.c | 15 ++++++--------- components/soc/esp32s3/include/soc/rtc.h | 8 ++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/components/esp32s3/Kconfig b/components/esp32s3/Kconfig index 77b51f890d..2205b88470 100644 --- a/components/esp32s3/Kconfig +++ b/components/esp32s3/Kconfig @@ -456,6 +456,24 @@ menu "ESP32S3-Specific" In case more value will help improve the definition of the launch of the crystal. If the crystal could not start, it will be switched to internal RC. + config ESP32S3_DEEP_SLEEP_WAKEUP_DELAY + int "Extra delay in deep sleep wake stub (in us)" + default 2000 + range 0 5000 + help + When ESP32S3 exits deep sleep, the CPU and the flash chip are powered on + at the same time. CPU will run deep sleep stub first, and then + proceed to load code from flash. Some flash chips need sufficient + time to pass between power on and first read operation. By default, + without any extra delay, this time is approximately 900us, although + some flash chip types need more than that. + + By default extra delay is set to 2000us. When optimizing startup time + for applications which require it, this value may be reduced. + + If you are seeing "flash read err, 1000" message printed to the + console after deep sleep reset, try increasing this value. + config ESP32S3_NO_BLOBS bool "No Binary Blobs" depends on !BT_ENABLED diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index bf2fb66db0..8a0baff4d4 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -100,8 +100,8 @@ #define DEFAULT_HARDWARE_OUT_OVERHEAD_US (28) #elif CONFIG_IDF_TARGET_ESP32S3 #define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ -#define DEFAULT_SLEEP_OUT_OVERHEAD_US (0) -#define DEFAULT_HARDWARE_OUT_OVERHEAD_US (0) +#define DEFAULT_SLEEP_OUT_OVERHEAD_US (382) +#define DEFAULT_HARDWARE_OUT_OVERHEAD_US (133) #elif CONFIG_IDF_TARGET_ESP32C3 #define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ #define DEFAULT_SLEEP_OUT_OVERHEAD_US (105) @@ -113,11 +113,7 @@ #endif #define LIGHT_SLEEP_TIME_OVERHEAD_US DEFAULT_HARDWARE_OUT_OVERHEAD_US -#if defined(CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS) || \ - defined(CONFIG_ESP32S2_RTC_CLK_SRC_EXT_CRYS) || \ - defined(CONFIG_ESP32C3_RTC_CLK_SRC_EXT_CRYS) || \ - defined(CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS) || \ - defined(CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS) +#ifdef CONFIG_ESP_SYSTEM_RTC_EXT_XTAL #define DEEP_SLEEP_TIME_OVERHEAD_US (650 + 100 * 240 / DEFAULT_CPU_FREQ_MHZ) #else #define DEEP_SLEEP_TIME_OVERHEAD_US (250 + 100 * 240 / DEFAULT_CPU_FREQ_MHZ) @@ -125,6 +121,8 @@ #if defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY) #define DEEP_SLEEP_WAKEUP_DELAY CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY +#elif defined(CONFIG_IDF_TARGET_ESP32S3) && defined(CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY) +#define DEEP_SLEEP_WAKEUP_DELAY CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY #else #define DEEP_SLEEP_WAKEUP_DELAY 0 #endif @@ -539,7 +537,6 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) // Enter sleep rtc_sleep_config_t config = RTC_SLEEP_CONFIG_DEFAULT(pd_flags); rtc_sleep_init(config); - rtc_sleep_low_init(s_config.rtc_clk_cal_period); // Set state machine time for light sleep if (!deep_sleep) { @@ -710,7 +707,7 @@ esp_err_t esp_light_sleep_start(void) uint32_t pd_flags = get_power_down_flags(); // Re-calibrate the RTC Timer clock -#if defined(CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS) || defined(CONFIG_ESP32S2_RTC_CLK_SRC_EXT_CRYS) || defined(CONFIG_ESP32C3_RTC_CLK_SRC_EXT_CRYS) +#ifdef CONFIG_ESP_SYSTEM_RTC_EXT_XTAL uint64_t time_per_us = 1000000ULL; s_config.rtc_clk_cal_period = (time_per_us << RTC_CLK_CAL_FRACT) / rtc_clk_slow_freq_get_hz(); #elif defined(CONFIG_ESP32S2_RTC_CLK_SRC_INT_RC) diff --git a/components/soc/esp32s3/include/soc/rtc.h b/components/soc/esp32s3/include/soc/rtc.h index fa4e837a94..ac186e5e93 100644 --- a/components/soc/esp32s3/include/soc/rtc.h +++ b/components/soc/esp32s3/include/soc/rtc.h @@ -107,10 +107,10 @@ extern "C" { #define RTC_CK8M_ENABLE_WAIT_DEFAULT 5 /* Various delays to be programmed into power control state machines */ -#define RTC_CNTL_PLL_BUF_WAIT_SLP_CYCLES RTC_CNTL_PLL_BUF_WAIT_DEFAULT -#define RTC_CNTL_XTL_BUF_WAIT_SLP_US RTC_CNTL_XTL_BUF_WAIT_DEFAULT -#define RTC_CNTL_CK8M_WAIT_SLP_CYCLES RTC_CNTL_CK8M_WAIT_DEFAULT -#define RTC_CNTL_WAKEUP_DELAY_CYCLES (0) +#define RTC_CNTL_XTL_BUF_WAIT_SLP_US (250) +#define RTC_CNTL_PLL_BUF_WAIT_SLP_CYCLES (1) +#define RTC_CNTL_CK8M_WAIT_SLP_CYCLES (4) +#define RTC_CNTL_WAKEUP_DELAY_CYCLES (4) #define RTC_CNTL_CK8M_DFREQ_DEFAULT 100 #define RTC_CNTL_SCK_DCAP_DEFAULT 255