2019-10-25 11:20 PM
if(low_power_mode == 1)
{
standby(10);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
void standby(int seconds)
{
/* Clear all related wakeup flags*/
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
rtc_set_wake_up_timer_s(seconds);
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);
}
void rtc_set_wake_up_timer_s(uint32_t sec)
{
uint32_t clock = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
// HAL_RTCEx_SetWakeUpTimer_IT will assert that delta is 0xFFFF at max
if (delta > 0xFFFF) {
delta -= 0x10000;
clock = RTC_WAKEUPCLOCK_CK_SPRE_17BITS;
}
hrtc.Instance = RTC;
HAL_StatusTypeDef status = HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, delta, clock);
if (status != HAL_OK) {
// debug("Set wake up timer failed: %d\n", status);
NVIC_SystemReset();
}
}