Skip to main content
AFahr.1
Associate III
June 14, 2021
Solved

STM32L4, can't wake up with RTC Alarm A after Stop 2 mode (WFE)

  • June 14, 2021
  • 5 replies
  • 1602 views

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_INF

To 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

This topic has been closed for replies.
Best answer by waclawek.jan

Which STM32?

I believe you don't need to enable the interrupt in NVIC and it would suffice to set ALRAIE/ALRBIE in RTC.

JW

5 replies

AFahr.1
AFahr.1Author
Associate III
June 14, 2021

I seem to again have found my own solution... I had to enable the RTC interrupt even though I'm only using the event.... I get confused by that still.

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_NVIC_SetPriority(RTC_Alarm_IRQn, 7, 0);			///< Set the interrupt priority and enable
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
 
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
if (HAL_RTC_SetAlarm_IT(&hrtc, &alrm_a, RTC_FORMAT_BIN) != HAL_OK)
{
 log_msg(LOG_ERR, "dg_system.c: Error setting alarm Line: %u", __LINE__);
}
 
log_msg(LOG_INFO, "Setting alarm: %02d:%02d:%02d", alrm_a.AlarmTime.Hours, alrm_a.AlarmTime.Minutes, alrm_a.AlarmTime.Seconds);

This worked when I turned it off at 11 PM and it woke up at 6 AM again.

Cheers,

Alberto

waclawek.jan
waclawek.janBest answer
Super User
June 15, 2021

Which STM32?

I believe you don't need to enable the interrupt in NVIC and it would suffice to set ALRAIE/ALRBIE in RTC.

JW

AFahr.1
AFahr.1Author
Associate III
June 15, 2021

Thanks Jan,

I will give that a try.

It's an STM32L496

Cheers,

Alberto

AFahr.1
AFahr.1Author
Associate III
June 16, 2021

@Community member​ Hi, you were right, enabling the ALRAIE bit did the trick, no need to enable the interrupt!

Cheers,

Alberto

Mohamed Aymen HZAMI
ST Employee
June 16, 2021

Hello @Community member​,

In order to help other users found quickly the solution please mark waclawek.jan's answer as Best.

Thanks,

Mohamed Aymen.