From 87b8e64953525e7009f1e5ef5bfcea256d6f13aa Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Fri, 14 Mar 2025 14:29:11 +0800 Subject: [PATCH] change(esp_hw_support): force invalidate all cache before exiting the sleep flow when sleep iram is disabled --- components/esp_hw_support/sleep_modes.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 767de9ddda..6b213d7758 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1135,6 +1135,21 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl if (!deep_sleep) { if (result == ESP_OK) { +#if !CONFIG_PM_SLP_IRAM_OPT && !CONFIG_IDF_TARGET_ESP32 +#if CONFIG_SPIRAM +# if CONFIG_IDF_TARGET_ESP32P4 + cache_ll_writeback_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_DATA, CACHE_LL_ID_ALL); +# else + Cache_WriteBack_All(); +# endif +#endif + /* When the IRAM optimization for the sleep flow is disabled, all + * cache contents are forcibly invalidated before exiting the sleep + * flow. This ensures that the code execution time of sleep exit + * flow remains consistent, allowing the use of ccount to + * dynamically calculate the sleep adjustment time. */ + cache_ll_invalidate_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_ALL, CACHE_LL_ID_ALL); +#endif s_config.ccount_ticks_record = esp_cpu_get_cycle_count(); #if SOC_PM_RETENTION_SW_TRIGGER_REGDMA if (sleep_flags & PMU_SLEEP_PD_TOP) {