diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index f5a6b29295..1fa2d8d884 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -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