STM32L4, can't wake up with RTC Alarm A after Stop 2 mode (WFE)
Hi all,
As stated above, I can't seem to wake up the controller from STOP2 mode using WFE with the ALARM A. Here's my alarm and EXTI settings:
if(EXTI->PR1 & EXTI_PR1_PIF18)
{
EXTI->PR1 |= EXTI_PR1_PIF18; ///< Clear pending interrupt if necessary
}
EXTI->EMR1 |= EXTI_EMR1_EM18; ///< RTC Alarm Mask
EXTI->RTSR1 |= EXTI_RTSR1_RT18; ///< Rising trigger
/* Set the alarm values with the config values */
HAL_PWREx_EnableInternalWakeUpLine();
__HAL_RTC_ALARMA_ENABLE(&hrtc);
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);
alarm_Time.Hours = storage_config.wup_time.Hours;
alarm_Time.Minutes = storage_config.wup_time.Minutes;
alarm_Time.Seconds = storage_config.wup_time.Seconds;
alarm_Time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
alrm_a.Alarm = RTC_ALARM_A;
alrm_a.AlarmMask = RTC_ALRMAR_MSK4;
alrm_a.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
alrm_a.AlarmTime = alarm_Time;
alrm_a.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
if (HAL_RTC_SetAlarm(&hrtc, &alrm_a, RTC_FORMAT_BIN) != HAL_OK)
{
log_msg(LOG_ERR, "dg_system.c: Error setting alarm Line: %u", __LINE__);
}
log_msg(LOG_INFTo send the unit to sleep (I'm using FreeRTOS):
/* Send system to sleep */
vTaskSuspendAll();
vPortRaiseBASEPRI();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFE);I know that the code above works, because I can wake up the micro using a push button:
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(USB_Det_GPIO_Port, &GPIO_InitStruct);But either I'm not configuring the Alarm correctly or there is some incorrect setting in the EXTI. I cannot really use an interrupt, as the OS would then trigger it...
Any ideas or pointers are welcome.
Cheers,
Alberto
