cancel
Showing results for 
Search instead for 
Did you mean: 

Wakeup from STOP2 sleep using RTC Alarm

joshua.cowpland
Associate II

I'm trying to wake my STM32L471 up from STOP2 sleep mode using the RTC Alarm. I successfully get it to sleep, and then I'm using the code from the STMCube Example projects (\STM32Cube_FW_L0_V1.11.0) to try to wake it, but not succeeding. Is anyone able to help? Alarm code is below:

RTC_HandleTypeDef RtcHandle;
RTC_DateTypeDef  sdatestructure_set = {0};
  RTC_TimeTypeDef  stimestructure = {0};
  RTC_AlarmTypeDef salarmstructure = {{0}, 0};
 
  /*##-1- Configure the Date #################################################*/
  /* Set Date: October 31th 2014 */
  sdatestructure_set.Year = 14;
  sdatestructure_set.Month = RTC_MONTH_OCTOBER;
  sdatestructure_set.Date = 31;
  //sdatestructure_set.WeekDay = RTC_WEEKDAY_SUNDAY;
 
  if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure_set,RTC_FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
 
  /*##-2- Configure the Time #################################################*/
  /* Set Time: 23:59:55 */
  stimestructure.Hours = 23;
  stimestructure.Minutes = 59;
  stimestructure.Seconds = 55;
  stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
  stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
  stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
  if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
 
  /*##-3- Configure the RTC Alarm peripheral #################################*/
  /* Set Alarm to 00:00:10
     RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */
  salarmstructure.Alarm = RTC_ALARM_A;
  salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
  salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
  salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
  salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
  salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
  salarmstructure.AlarmTime.Hours = 00;
  salarmstructure.AlarmTime.Minutes = 00;
  salarmstructure.AlarmTime.Seconds = 30;
 
  if(HAL_RTC_SetAlarm_IT(&RtcHandle,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
 
__HAL_RTC_ALARM_ENABLE_IT(&RtcHandle,RTC_IT_ALRA);
 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
 
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
	NVIC_SystemRestart();
}

1 REPLY 1
Mohamed Aymen HZAMI
ST Employee

Hello Joshua,

You said you are using an STM32L4 but you are montioning that you use the firmware of STM32L0 "STM32Cube_FW_L0_V1.11.0".

Please check the firmware and try again.

Best Regards,

Mohamed Aymen.