diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 7cbca55944e..df350168ca1 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -84,6 +84,7 @@ menu "Hardware Settings" select ESP_REGI2C_CTRL_FUNC_IN_IRAM depends on !SPIRAM || ESP_LDO_RESERVE_PSRAM || SOC_PSRAM_HAS_DEDICATED_LDO depends on !(IDF_TARGET_ESP32P4 && (ESP32P4_REV_MIN_FULL < 100)) + depends on !SOC_PM_FLASH_KEEP_POWER_IN_LSLP default n help If enabled, chip will try to power down flash as part of esp_light_sleep_start(), which costs @@ -227,7 +228,7 @@ menu "Hardware Settings" config ESP_SLEEP_SET_FLASH_DPD bool "Set SPI flash to deep power-down mode in light sleep" depends on (!APP_BUILD_TYPE_PURE_RAM_APP && !ESP_SLEEP_POWER_DOWN_FLASH && !SPI_FLASH_ROM_IMPL) - default y if (IDF_TARGET_ESP32H4 || IDF_TARGET_ESP32H21) + default y if SOC_PM_FLASH_KEEP_POWER_IN_LSLP default y if (IDF_TARGET_ESP32P4 && ESP32P4_SELECTS_REV_LESS_V3) default n help @@ -237,11 +238,10 @@ menu "Hardware Settings" which will reduce the sleep current by about 10uA. And you can also use this option to reduce power consumption when using PSRAM - NOTE: We have conducted sufficient testing on ESP32H21, ESP32H4 and ESP32P4(less v3). If you plan to - use a customized flash chip, or if you are working with other ESP32-series chips, please make sure to - check the corresponding flash datasheet or consult us directly. This is to ensure that using the B9h - command to enter Deep Power-Down mode and ABh to exit Deep Power-Down mode will not introduce any - potential issues. + NOTE: We have conducted sufficient testing on ESP32-C5, ESP32-C61, ESP32-H21, ESP32-H4 and + ESP32-P4 (less v3). If you plan to use a customized flash chip, or if you are working with other + ESP32-series chips, please make sure to check the corresponding flash datasheet or consult us + directly. This is to ensure that using the B9h command to enter Deep Power-Down mode and ABh to exit. config ESP_SLEEP_SPI_FLASH_ENTER_DPD_MODE_DELAY int "SPI Flash enter deep power-down time delay (in us)" diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 3602c1e3c12..fff090a5ab8 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1575,6 +1575,7 @@ esp_err_t esp_light_sleep_start(void) * will be set in `sleep_flags`. */ if (sleep_flags & RTC_SLEEP_PD_VDDSDIO) { +#if !SOC_PM_FLASH_KEEP_POWER_IN_LSLP /* * When VDD_SDIO power domain has to be turned off, the minimum sleep time of the * system needs to meet the sum below: @@ -1610,8 +1611,13 @@ esp_err_t esp_light_sleep_start(void) s_config.sleep_time_adjustment -= flash_enable_time_us; } } - } else if (!(sleep_flags & RTC_SLEEP_PD_VDDSDIO)) { +#else + sleep_flags &= ~RTC_SLEEP_PD_VDDSDIO; +#endif + } + #if CONFIG_ESP_SLEEP_SET_FLASH_DPD + if (!(sleep_flags & RTC_SLEEP_PD_VDDSDIO) && (sleep_flags & RTC_SLEEP_FLASH_DPD)) { const uint32_t flash_enable_dpd_us = spi_flash_dpd_get_enter_duration() + spi_flash_dpd_get_exit_duration(); if (s_config.sleep_duration > flash_enable_dpd_us) { if (s_config.sleep_time_overhead_out < flash_enable_dpd_us) { @@ -1626,8 +1632,8 @@ esp_err_t esp_light_sleep_start(void) s_config.sleep_time_adjustment -= flash_enable_dpd_us; } } -#endif } +#endif periph_inform_out_light_sleep_overhead(s_config.sleep_time_adjustment - sleep_time_overhead_in); @@ -2955,9 +2961,20 @@ static SLEEP_FN_ATTR uint32_t get_power_down_flags(void) #endif #if CONFIG_ESP_SLEEP_SET_FLASH_DPD - if (!(pd_flags & RTC_SLEEP_PD_VDDSDIO)) { - // Flash power domain will disable DPD mode. - pd_flags |= RTC_SLEEP_FLASH_DPD; + { + uint32_t pd_flags_for_dpd = pd_flags; +#if SOC_PM_FLASH_KEEP_POWER_IN_LSLP + /* Light sleep never powers down the flash supply on these targets; an app may still set VDDSDIO + * domain to OFF manually, and we later strip RTC_SLEEP_PD_VDDSDIO. + * Mask the bit when deriving DPD so flash deep power-down is not suppressed. */ + pd_flags_for_dpd &= ~RTC_SLEEP_PD_VDDSDIO; +#endif + if (!(pd_flags_for_dpd & RTC_SLEEP_PD_VDDSDIO)) { + // Flash power domain will disable DPD mode. + pd_flags |= RTC_SLEEP_FLASH_DPD; + } else { + ESP_LOGW(TAG, "Flash DPD mode cannot be enabled when VDDSDIO is configured to power down."); + } } #endif diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index afbcf6fb0e7..58cb8b9311e 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -1463,6 +1463,10 @@ config SOC_PM_RETENTION_MODULE_NUM int default 32 +config SOC_PM_FLASH_KEEP_POWER_IN_LSLP + bool + default y + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index 70e68f00dbf..165cbff9618 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -593,6 +593,8 @@ #define SOC_PM_RETENTION_MODULE_NUM (32) +#define SOC_PM_FLASH_KEEP_POWER_IN_LSLP (1) /*!