Merge branch 'bugfix/_rtc_slow_length_incorrectly_optimized_backport_v4.4' into 'release/v4.4'

sleep_power_domain: fix _rtc_slow_length being incorrectly optimized by compiler(backport v4.4)

See merge request espressif/esp-idf!17974
This commit is contained in:
Jiang Jiang Jian 2022-05-03 15:04:09 +08:00
commit b6f4629e11

View File

@ -1184,10 +1184,14 @@ static uint32_t get_power_down_flags(void)
#if SOC_RTC_SLOW_MEM_SUPPORTED && SOC_ULP_SUPPORTED
// Labels are defined in the linker script
extern int _rtc_slow_length;
/**
* Compiler considers "(size_t) &_rtc_slow_length > 0" to always be true.
* So use a volatile variable to prevent compiler from doing this optimization.
*/
volatile size_t rtc_slow_mem_used = (size_t)&_rtc_slow_length;
if ((s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] == ESP_PD_OPTION_AUTO) &&
((size_t) &_rtc_slow_length > 0 ||
(s_config.wakeup_triggers & RTC_ULP_TRIG_EN))) {
(rtc_slow_mem_used > 0 || (s_config.wakeup_triggers & RTC_ULP_TRIG_EN))) {
s_config.pd_options[ESP_PD_DOMAIN_RTC_SLOW_MEM] = ESP_PD_OPTION_ON;
}
#endif