RTC Alarm+Standby: Waking up from standby works once, but returns immediatelly afterwards
Hi all,
I configured RTC and standby to wake up after 5 seconds, once standby is entered. This works fine after flashing the program. But once waken up from standby, if going to standby again, the device returns from standby immediately.
Beside the RTC, I have also the SYS_WKUP pin configured to wakup the device. When disabling the RTC alarm, this feature alone works as expected.
What I checked:
- cleared flags RTC_FLAG_WUTF, RTC_FLAG_ALRAF, RTC_FLAG_ALRBF (even though I only use Alarm A)
- checked NRST and SYS_WKUP pins with oscilloscope
- verified configured time. The RTC time is currently always set again at startup to avoid time setting issues.
- compared registers for the working standby alarm and the others. Register for RTC, PWR, EXTI look the same.
Here is how I configured the peripheral:
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HalRtc_GetDateAndTime(&nowtime); /* own function to get the time */
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_B);
__HAL_GPIO_EXTI_CLEAR_IT(0x2000);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRBF);
RTC_AlarmTypeDef sAlarm = { 0 };
sAlarm.AlarmTime.Hours = nowtime.hour;
sAlarm.AlarmTime.Minutes = nowtime.min;
sAlarm.AlarmTime.Seconds = nowtime.sec + 5;
sAlarm.AlarmTime.SubSeconds = 0U;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_DATEWEEKDAY; /* Select which items shall be INORED (!) */
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;/* Select to match by date, not day of week */
sAlarm.AlarmDateWeekDay = nowtime.day;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK) {
status = eError;
}
if (status == eOk) {
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
}
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_Delay(100);
if ((PWR->CSR & 0x100) && ((RTC->ISR & 0x100) == 0)) { /* just assure again the bits are set as expected */
HAL_PWR_EnterSTANDBYMode();
}After searching and debugging for hours, I hope someone can help me.
Thanks in advance, denise