fix(esp_hw_support): fix esp32 APP_CPU accessing RTCFAST memory in sleep code

Closes https://github.com/espressif/esp-idf/issues/16243
This commit is contained in:
wuzhenghui
2025-07-08 16:58:31 +08:00
parent e839ed589c
commit d8e73e94f2
2 changed files with 19 additions and 13 deletions

View File

@@ -291,8 +291,9 @@ static bool s_light_sleep_wakeup = false;
static portMUX_TYPE spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED; static portMUX_TYPE spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED;
static const char *TAG = "sleep"; 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) 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 #if CONFIG_IDF_TARGET_ESP32
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */ /* APP core of esp32 can't access to RTC FAST MEMORY, link to RTC SLOW MEMORY instead*/
void RTC_SLOW_ATTR
#else #else
void RTC_IRAM_ATTR RTC_IRAM_ATTR
#endif #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 #if SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
wake_stub_fn_handler = new_stub; 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 #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 */ /* Clear MMU for CPU 0 */
#if CONFIG_IDF_TARGET_ESP32 #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 #if CONFIG_IDF_TARGET_ESP32
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */ /* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */
void RTC_SLOW_ATTR
#else #else
void RTC_IRAM_ATTR RTC_IRAM_ATTR
#endif #endif
esp_deep_sleep_disable_rom_logging(void) void esp_deep_sleep_disable_rom_logging(void)
{ {
rtc_suppress_rom_log(); rtc_suppress_rom_log();
} }

View File

@@ -19,9 +19,7 @@
#include "deep_sleep_example.h" #include "deep_sleep_example.h"
#if SOC_RTC_FAST_MEM_SUPPORTED #if SOC_RTC_FAST_MEM_SUPPORTED
static RTC_DATA_ATTR struct timeval sleep_enter_time; RTC_SLOW_ATTR static struct timeval sleep_enter_time;
#else
static struct timeval sleep_enter_time;
#endif #endif
static void deep_sleep_task(void *args) static void deep_sleep_task(void *args)