Skip to content

Commit 56c2831

Browse files
committed
fix(esp_hw_support): fix esp32 APP_CPU accessing RTCFAST memory in sleep code
Closes #16243
1 parent 20f1700 commit 56c2831

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

components/esp_hw_support/sleep_modes.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ static bool s_light_sleep_wakeup = false;
326326
static portMUX_TYPE __attribute__((unused)) spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED;
327327

328328
static const char *TAG = "sleep";
329-
static RTC_FAST_ATTR int32_t s_sleep_sub_mode_ref_cnt[ESP_SLEEP_MODE_MAX] = { 0 };
330-
//in this mode, 2uA is saved, but RTC memory can't use at high temperature, and RTCIO can't be used as INPUT.
329+
330+
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */
331+
RTC_SLOW_ATTR static int32_t s_sleep_sub_mode_ref_cnt[ESP_SLEEP_MODE_MAX] = { 0 };
331332

332333
void esp_sleep_overhead_out_time_refresh(void)
333334
{
@@ -424,12 +425,12 @@ esp_deep_sleep_wake_stub_fn_t esp_get_deep_sleep_wake_stub(void)
424425
}
425426

426427
#if CONFIG_IDF_TARGET_ESP32
427-
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */
428-
void
428+
/* APP core of esp32 can't access to RTC FAST MEMORY, link to RTC SLOW MEMORY instead*/
429+
RTC_SLOW_ATTR
429430
#else
430-
void RTC_IRAM_ATTR
431+
RTC_IRAM_ATTR
431432
#endif
432-
esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub)
433+
void esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub)
433434
{
434435
#if SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
435436
wake_stub_fn_handler = new_stub;
@@ -438,7 +439,14 @@ esp_set_deep_sleep_wake_stub(esp_deep_sleep_wake_stub_fn_t new_stub)
438439
#endif
439440
}
440441

441-
void RTC_IRAM_ATTR esp_default_wake_deep_sleep(void)
442+
443+
#if CONFIG_IDF_TARGET_ESP32
444+
/* APP core of esp32 can't access to RTC FAST MEMORY, link to RTC SLOW MEMORY instead*/
445+
RTC_SLOW_ATTR
446+
#else
447+
RTC_IRAM_ATTR
448+
#endif
449+
void esp_default_wake_deep_sleep(void)
442450
{
443451
/* Clear MMU for CPU 0 */
444452
#if CONFIG_IDF_TARGET_ESP32
@@ -2839,11 +2847,11 @@ static SLEEP_FN_ATTR uint32_t get_sleep_clock_icg_flags(void)
28392847

28402848
#if CONFIG_IDF_TARGET_ESP32
28412849
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */
2842-
void
2850+
RTC_SLOW_ATTR
28432851
#else
2844-
void RTC_IRAM_ATTR
2852+
RTC_IRAM_ATTR
28452853
#endif
2846-
esp_deep_sleep_disable_rom_logging(void)
2854+
void esp_deep_sleep_disable_rom_logging(void)
28472855
{
28482856
rtc_suppress_rom_log();
28492857
}

examples/system/deep_sleep/main/deep_sleep_example_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#include "deep_sleep_example.h"
2020

2121
#if SOC_RTC_FAST_MEM_SUPPORTED
22-
static RTC_DATA_ATTR struct timeval sleep_enter_time;
23-
#else
24-
static struct timeval sleep_enter_time;
22+
RTC_SLOW_ATTR static struct timeval sleep_enter_time;
2523
#endif
2624

2725
static void deep_sleep_task(void *args)

0 commit comments

Comments
 (0)