From f69ea24d1502b217d3daee498becbc516e2acf48 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 14 Jul 2023 17:48:20 +0800 Subject: [PATCH 1/3] fix(esp_pm): wait spi bus idle before hold CS pin - Wait for spi bus idle before holding CS pin to prevent hold selected state during sleep --- components/esp_hw_support/sleep_cpu.c | 4 ---- components/esp_hw_support/sleep_modes.c | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/esp_hw_support/sleep_cpu.c b/components/esp_hw_support/sleep_cpu.c index eb4cbbdfb193..8ed524e74a4c 100644 --- a/components/esp_hw_support/sleep_cpu.c +++ b/components/esp_hw_support/sleep_cpu.c @@ -706,10 +706,6 @@ esp_err_t IRAM_ATTR esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t, uin { uint32_t mstatus = save_mstatus_and_disable_global_int(); - /* wait cache idle */ - Cache_Freeze_ICache_Enable(CACHE_FREEZE_ACK_BUSY); - Cache_Freeze_ICache_Disable(); - cpu_domain_dev_regs_save(s_cpu_retention.retent.plic_frame); cpu_domain_dev_regs_save(s_cpu_retention.retent.clint_frame); cpu_domain_dev_regs_save(s_cpu_retention.retent.intpri_frame); diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 859d4a3642df..1b34628fd05b 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -44,6 +44,7 @@ #include "soc/soc_caps.h" #include "regi2c_ctrl.h" //For `REGI2C_ANA_CALI_PD_WORKAROUND`, temp +#include "hal/cache_hal.h" #include "hal/wdt_hal.h" #include "hal/uart_hal.h" #if SOC_TOUCH_SENSOR_SUPPORTED @@ -105,6 +106,10 @@ #include "esp_private/sleep_retention.h" #endif +#if (CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND) && !CONFIG_IDF_TARGET_ESP32H2 +#include "hal/cache_hal.h" +#endif + // If light sleep time is less than that, don't power down flash #define FLASH_PD_MIN_SLEEP_TIME_US 2000 @@ -731,6 +736,7 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m #if (CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND) #if !CONFIG_IDF_TARGET_ESP32H2 // ESP32H2 TODO IDF-7359: related rtcio ll func not supported yet if(!(pd_flags & PMU_SLEEP_PD_VDDSDIO)) { + cache_hal_freeze(CACHE_TYPE_ALL); gpio_ll_hold_en(&GPIO, SPI_CS0_GPIO_NUM); } #endif @@ -753,6 +759,7 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m #if !CONFIG_IDF_TARGET_ESP32H2 // ESP32H2 TODO IDF-7359: related rtcio ll func not supported yet if(!(pd_flags & PMU_SLEEP_PD_VDDSDIO)) { gpio_ll_hold_dis(&GPIO, SPI_CS0_GPIO_NUM); + cache_hal_unfreeze(CACHE_TYPE_ALL); } #endif #endif From ec35c2ab60b526af2e1f67cd5d5d395641668e6b Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Wed, 7 Jun 2023 19:50:30 +0800 Subject: [PATCH 2/3] fix(esp_pm): put vddsdio configure api always in iram if pd_flash is enabled - Put vddsdio configure api always in iram if pd_flash is enabled to ensure access flash at flash unavailable time --- components/esp_hw_support/linker.lf | 3 ++- components/esp_pm/linker.lf | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 468f03d4bae3..dfc2509bf61c 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -15,7 +15,8 @@ entries: rtc_clk (noflash) esp_gpio_reserve: esp_gpio_reserve_pins (noflash) esp_gpio_reserve: esp_gpio_is_pin_reserved (noflash) - if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED: + if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED = y && (PM_SLP_IRAM_OPT = y || ESP_SLEEP_POWER_DOWN_FLASH = y): + rtc_init:rtc_vddsdio_get_config (noflash) rtc_init:rtc_vddsdio_set_config (noflash) if IDF_TARGET_ESP32C6 = n && IDF_TARGET_ESP32H2 = n: # TODO: IDF-5645 rtc_sleep (noflash_text) diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index f17e24e8a2b3..12d9282a408e 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -13,8 +13,6 @@ entries: sleep_modes:esp_sleep_enable_timer_wakeup (noflash) sleep_modes:timer_wakeup_prepare (noflash) sleep_modes:get_power_down_flags (noflash) - if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED: - rtc_init:rtc_vddsdio_get_config (noflash) esp_clk:esp_clk_slowclk_cal_set (noflash) esp_clk:esp_clk_slowclk_cal_get (noflash) esp_clk:esp_rtc_get_time_us (noflash) From 16d849b95ea2cccbd78d0e0980696df164c9501c Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 14 Jul 2023 17:40:02 +0800 Subject: [PATCH 3/3] fix(esp_pm): fix flash access after light sleep wakeup --- components/esp_hw_support/linker.lf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index dfc2509bf61c..744de22edc5c 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -46,3 +46,9 @@ entries: sar_periph_ctrl (noflash) else: sar_periph_ctrl: sar_periph_ctrl_power_enable (noflash) + +[mapping:soc_pm] +archive: libsoc.a +entries: + if PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND: + gpio_periph: GPIO_HOLD_MASK (noflash)