fix _rtc_slow_length being incorrectly optimized by compiler

This commit is contained in:
jingli 2022-04-24 23:13:48 +08:00
parent 8efd164e7f
commit 74399f5b44

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