From d8e73e94f2d13ba32afb9f996450b9385dfeeee8 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Tue, 8 Jul 2025 16:58:31 +0800 Subject: [PATCH] fix(esp_hw_support): fix esp32 APP_CPU accessing RTCFAST memory in sleep code Closes https://github.com/espressif/esp-idf/issues/16243 --- components/esp_hw_support/sleep_modes.c | 28 ++++++++++++------- .../deep_sleep/main/deep_sleep_example_main.c | 4 +-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 230672967b..7d25c4314f 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -291,8 +291,9 @@ static bool s_light_sleep_wakeup = false; static portMUX_TYPE spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED; static const char *TAG = "sleep"; -static RTC_FAST_ATTR int32_t s_sleep_sub_mode_ref_cnt[ESP_SLEEP_MODE_MAX] = { 0 }; -//in this mode, 2uA is saved, but RTC memory can't use at high temperature, and RTCIO can't be used as INPUT. + +/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */ +RTC_SLOW_ATTR static int32_t s_sleep_sub_mode_ref_cnt[ESP_SLEEP_MODE_MAX] = { 0 }; void esp_sleep_overhead_out_time_refresh(void) { @@ -385,12 +386,12 @@ esp_deep_sleep_wake_stub_fn_t esp_get_deep_sleep_wake_stub(void) } #if CONFIG_IDF_TARGET_ESP32 -/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */ -void +/* APP core of esp32 can't access to RTC FAST MEMORY, link to RTC SLOW MEMORY instead*/ +RTC_SLOW_ATTR #else -void RTC_IRAM_ATTR +RTC_IRAM_ATTR #endif -esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub) +void esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub) { #if SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY wake_stub_fn_handler = new_stub; @@ -399,7 +400,14 @@ esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub) #endif } -void RTC_IRAM_ATTR esp_default_wake_deep_sleep(void) + +#if CONFIG_IDF_TARGET_ESP32 +/* APP core of esp32 can't access to RTC FAST MEMORY, link to RTC SLOW MEMORY instead*/ +RTC_SLOW_ATTR +#else +RTC_IRAM_ATTR +#endif +void esp_default_wake_deep_sleep(void) { /* Clear MMU for CPU 0 */ #if CONFIG_IDF_TARGET_ESP32 @@ -2565,11 +2573,11 @@ static uint32_t get_sleep_flags(uint32_t sleep_flags, bool deepsleep) #if CONFIG_IDF_TARGET_ESP32 /* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */ -void +RTC_SLOW_ATTR #else -void RTC_IRAM_ATTR +RTC_IRAM_ATTR #endif -esp_deep_sleep_disable_rom_logging(void) +void esp_deep_sleep_disable_rom_logging(void) { rtc_suppress_rom_log(); } diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index d46a5c1ac2..7c1de51580 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -19,9 +19,7 @@ #include "deep_sleep_example.h" #if SOC_RTC_FAST_MEM_SUPPORTED -static RTC_DATA_ATTR struct timeval sleep_enter_time; -#else -static struct timeval sleep_enter_time; +RTC_SLOW_ATTR static struct timeval sleep_enter_time; #endif static void deep_sleep_task(void *args)