Skip to content

Commit c13ffaf

Browse files
committed
STM32 LOW_POWER_TIMER update : sleep
RSF synchro after deepsleep is not specific to Low Power Timer feature And we have to check if RTC is configured before synchro
1 parent 0bf364e commit c13ffaf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ void hal_deepsleep(void)
6868
#if TARGET_STM32L4
6969
int pwrClockEnabled = __HAL_RCC_PWR_IS_CLK_ENABLED();
7070
int lowPowerModeEnabled = PWR->CR1 & PWR_CR1_LPR;
71-
71+
7272
if (!pwrClockEnabled) {
7373
__HAL_RCC_PWR_CLK_ENABLE();
7474
}
7575
if (lowPowerModeEnabled) {
7676
HAL_PWREx_DisableLowPowerRunMode();
7777
}
78-
78+
7979
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
80-
80+
8181
if (lowPowerModeEnabled) {
8282
HAL_PWREx_EnableLowPowerRunMode();
8383
}
@@ -101,8 +101,15 @@ void hal_deepsleep(void)
101101
TimMasterHandle.Instance = TIM_MST;
102102
__HAL_TIM_SET_COUNTER(&TimMasterHandle, EnterTimeUS);
103103

104-
#if DEVICE_LOWPOWERTIMER
105-
rtc_synchronize();
104+
#if DEVICE_RTC
105+
/* Wait for RTC RSF bit synchro if RTC is configured */
106+
#if (TARGET_STM32F2) || (TARGET_STM32F4) || (TARGET_STM32F7)
107+
if (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL)) {
108+
#else /* (TARGET_STM32F2) || (TARGET_STM32F4) || (TARGET_STM32F7) */
109+
if (__HAL_RCC_GET_RTC_SOURCE()) {
110+
#endif /* (TARGET_STM32F2) || (TARGET_STM32F4) || (TARGET_STM32F7) */
111+
rtc_synchronize();
112+
}
106113
#endif
107114
}
108115

0 commit comments

Comments
 (0)