Skip to content

Commit baab409

Browse files
committed
Merge branch 'fix/fix_iram_safe_code_inlined_to_flash_' into 'master'
fix(esp_hw_support): fix sleep iram safe code inlined to flash Closes PM-412 and PM-413 See merge request espressif/esp-idf!39185
2 parents f931739 + 077ce90 commit baab409

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

components/esp_common/include/esp_attr.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ extern "C" {
1919
//and all variables in shared RAM. These macros can be used to redirect
2020
//particular functions/variables to other memory regions.
2121

22-
// Forces code into IRAM instead of flash
22+
// Places code into IRAM instead of flash
2323
#define IRAM_ATTR _SECTION_ATTR_IMPL(".iram1", __COUNTER__)
2424

25+
// Forces code into IRAM instead of flash
26+
#define FORCE_IRAM_ATTR _SECTION_FORCE_ATTR_IMPL(".iram1", __COUNTER__)
27+
2528
// Forces data into DRAM instead of flash
2629
#define DRAM_ATTR _SECTION_ATTR_IMPL(".dram1", __COUNTER__)
2730

28-
// Forces code into TCM instead of flash
31+
// Places code into TCM instead of flash
2932
#define TCM_IRAM_ATTR _SECTION_ATTR_IMPL(".tcm.text", __COUNTER__)
3033

34+
// Forces code into TCM instead of flash
35+
#define FORCE_TCM_IRAM_ATTR _SECTION_FORCE_ATTR_IMPL(".tcm.text", __COUNTER__)
36+
3137
// Forces data into TCM instead of L2MEM
3238
#define TCM_DRAM_ATTR _SECTION_ATTR_IMPL(".tcm.data", __COUNTER__)
3339

@@ -189,11 +195,13 @@ FORCE_INLINE_ATTR TYPE& operator<<=(TYPE& a, int b) { a = a << b; return a; }
189195
// data with a custom section type set
190196
#ifndef CONFIG_IDF_TARGET_LINUX
191197
#define _SECTION_ATTR_IMPL(SECTION, COUNTER) __attribute__((section(SECTION "." _COUNTER_STRINGIFY(COUNTER))))
198+
#define _SECTION_FORCE_ATTR_IMPL(SECTION, COUNTER) __attribute__((noinline, section(SECTION "." _COUNTER_STRINGIFY(COUNTER))))
192199
#define _COUNTER_STRINGIFY(COUNTER) #COUNTER
193200
#else
194201
// Custom section attributes are generally not used in the port files for Linux target, but may be found
195202
// in the common header files. Don't declare custom sections in that case.
196203
#define _SECTION_ATTR_IMPL(SECTION, COUNTER)
204+
#define _SECTION_FORCE_ATTR_IMPL(SECTION, COUNTER)
197205
#endif
198206

199207
/* Use IDF_DEPRECATED attribute to mark anything deprecated from use in

components/esp_hw_support/sleep_modes.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
(source == value))
229229

230230
#if CONFIG_PM_SLP_IRAM_OPT
231-
# define SLEEP_FN_ATTR IRAM_ATTR
231+
# define SLEEP_FN_ATTR FORCE_IRAM_ATTR
232232
#else
233233
# define SLEEP_FN_ATTR
234234
#endif
@@ -532,7 +532,7 @@ static void s_do_deep_sleep_phy_callback(void)
532532
static int s_cache_suspend_cnt = 0;
533533

534534
// Must be called from critical sections.
535-
static void IRAM_ATTR suspend_cache(void) {
535+
static void FORCE_IRAM_ATTR suspend_cache(void) {
536536
s_cache_suspend_cnt++;
537537
if (s_cache_suspend_cnt == 1) {
538538
#if CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION && CONFIG_IDF_TARGET_ESP32P4
@@ -546,7 +546,7 @@ static void IRAM_ATTR suspend_cache(void) {
546546
}
547547

548548
// Must be called from critical sections.
549-
static void IRAM_ATTR resume_cache(void) {
549+
static void FORCE_IRAM_ATTR resume_cache(void) {
550550
s_cache_suspend_cnt--;
551551
assert(s_cache_suspend_cnt >= 0 && DRAM_STR("cache resume doesn't match suspend ops"));
552552
if (s_cache_suspend_cnt == 0) {
@@ -832,12 +832,12 @@ static SLEEP_FN_ATTR void sleep_low_power_clock_calibration(bool is_dslp)
832832
}
833833

834834

835-
inline static uint32_t call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp);
835+
static uint32_t call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp);
836836

837837
#if SOC_PMU_SUPPORTED
838-
static esp_err_t IRAM_ATTR esp_sleep_start_safe(uint32_t sleep_flags, uint32_t reject_triggers, bool deep_sleep, pmu_sleep_config_t *config)
838+
static esp_err_t FORCE_IRAM_ATTR esp_sleep_start_safe(uint32_t sleep_flags, uint32_t reject_triggers, bool deep_sleep, pmu_sleep_config_t *config)
839839
#else
840-
static esp_err_t IRAM_ATTR esp_sleep_start_safe(uint32_t sleep_flags, uint32_t reject_triggers, bool deep_sleep, rtc_sleep_config_t *config)
840+
static esp_err_t FORCE_IRAM_ATTR esp_sleep_start_safe(uint32_t sleep_flags, uint32_t reject_triggers, bool deep_sleep, rtc_sleep_config_t *config)
841841
#endif
842842
{
843843
esp_err_t result = ESP_OK;
@@ -1185,7 +1185,7 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl
11851185
return result ? ESP_ERR_SLEEP_REJECT : ESP_OK;
11861186
}
11871187

1188-
inline static uint32_t IRAM_ATTR call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp)
1188+
static uint32_t FORCE_IRAM_ATTR call_rtc_sleep_start(uint32_t reject_triggers, uint32_t lslp_mem_inf_fpu, bool dslp)
11891189
{
11901190
#ifdef CONFIG_IDF_TARGET_ESP32
11911191
return rtc_sleep_start(s_config.wakeup_triggers, reject_triggers);
@@ -1196,7 +1196,7 @@ inline static uint32_t IRAM_ATTR call_rtc_sleep_start(uint32_t reject_triggers,
11961196
#endif
11971197
}
11981198

1199-
static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
1199+
static esp_err_t FORCE_IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
12001200
{
12011201
#if SOC_VBAT_SUPPORTED
12021202
if (s_sleep_sub_mode_ref_cnt[ESP_SLEEP_VBAT_POWER_DEEPSLEEP_MODE]) {
@@ -1298,15 +1298,15 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
12981298
return err;
12991299
}
13001300

1301-
void IRAM_ATTR esp_deep_sleep_start(void)
1301+
void FORCE_IRAM_ATTR esp_deep_sleep_start(void)
13021302
{
13031303
bool allow_sleep_rejection = true;
13041304
deep_sleep_start(!allow_sleep_rejection);
13051305
// Never returns here
13061306
abort();
13071307
}
13081308

1309-
esp_err_t IRAM_ATTR esp_deep_sleep_try_to_start(void)
1309+
esp_err_t FORCE_IRAM_ATTR esp_deep_sleep_try_to_start(void)
13101310
{
13111311
bool allow_sleep_rejection = true;
13121312
return deep_sleep_start(allow_sleep_rejection);

0 commit comments

Comments
 (0)