[STM32L0] Wake up Flag for RTC does not rise when an alarm occurs
Hi,
I have a STM32L071 on a custom board
The code was generated with CubeMx for TrueSTUDIO.
I have an alarm set on the RTC to wake up the chip from standby mode everyday at 2 AM.
I tested it and the system does wake up ! good.
My problem is that I need to differentiate the origin of the wake up between RTC alarm and WKUP pin 1.
I check for PWR_FLAG_WU which does not give much information to differentiate the two.
My understanding from the reference manual (RM0377 DocID025942 Rev 8 p559) is that the bit ALRAF in the RTC initialization and status register (RTC_ISR) is the one that might be useful for me.
But even tho the system wakes up from RTC, the ALRAF flag is not set
same with RTC_IT_ALRA and RTC_FLAG_WUTF
Is there a way to know if the origin of wake up is the WKUP pin ?
regards,
Benjamin GREFFE.
code used to check the flags :
if(__HAL_RTC_ALARM_GET_IT(&hrtc, RTC_IT_ALRA))
{
lbWakedUpByRTC_IT = true;
}
if (__HAL_RTC_ALARM_GET_FLAG(&hrtc, RTC_FLAG_ALRAF))
{
lbWakedUpByRTC_ALRAF = true;
}
if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF))
{
lbWakedUpByRTC_WUTF = true;
}code to initialize the rtc
static void MX_RTC_Init(void)
{
RTC_AlarmTypeDef sAlarm = {0};
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 125;
hrtc.Init.SynchPrediv = 296;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/** Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0x2;
sAlarm.AlarmTime.Minutes = 0x0;
sAlarm.AlarmTime.Seconds = 0x0;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
}code to go to sleep
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_PWR_EnterSTANDBYMode();
while (1)
{
NVIC_SystemReset();
}