2023-11-02 11:20 AM
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:
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
2023-11-08 05:12 AM
2023-11-08 07:28 AM
Hi Sarra,
Thanks a lot for the support and the link to the thread.
I was not aware of the thread and I gave it a try. Unfortunately, it did not improve the situation.
In mean time I implemented a workaround: I use IWDG to wake up the system, and whenever it wakes the system from standby, I check if the RTC_ISR_ALRAF bit is set. If not, I just return into standby mode. This works well, however it has the drawback that the time is not very accurate.
Implementing this, I had another unexpected case: I thought that the RTC handler 'hrtc' represents the registers in 'hrtc.Instance'. But this is not the case, I had to access the registers directly by address. Maybe my origin issue is also linked on the fact that the handler 'hrtc' should not be used to reset and set flags.
2023-11-08 08:04 AM
Code not show how you use it, but maybe your miss is not knowledge , that wake from standby = reset MCU.
If you dont handle this right result is back to standby alltime.