cancel
Showing results for 
Search instead for 
Did you mean: 

Why STM32L053 does not wakeup from ALARM in STANDBY mode?

Alexey Ostrejkovsky
Associate II

That is my code below (Nucleo STM32L053). RTC works from 32768 quartz (LSE). Blue Button disconnected by eliminating of the SB17. Additional LED is connected to PC13 instead of the button. So, the device wakes up normally, when I set high level on wakeup pin PA0, but never wakes up from RTC ALARM-A signal. Alarm-A is working properly: additional LED on PC13-pin switches on after 12 seconds after reset system, but m/controller does not wake up (green LED PA5 switches on once after reset system and never more). Please, help me.

#include "main.h"

#include "rtc.h"

#include "usart.h"

#include "gpio.h"

/* USER CODE BEGIN PV */

 RTC_TimeTypeDef sTime = {0};

 RTC_DateTypeDef sDate = {0};

 RTC_AlarmTypeDef sAlarm = {0};

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

int main(void)

{

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_RTC_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 __HAL_RTC_ALARMA_DISABLE(&hrtc);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);

 HAL_Delay(1000);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

  

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 //-----------------------------------------------------------------------------

 /* Load all parameters to ALARM registers */  

 HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

 HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BCD);

 sAlarm.AlarmTime.Seconds = sTime.Seconds + 0x12; // ---> Wakeup every 12 seconds...

  

 sAlarm.AlarmTime.Hours = 0x0;

 sAlarm.AlarmTime.Minutes = 0x0;

 sAlarm.AlarmTime.SubSeconds = 0x0;

 sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

 sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

 sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS

               |RTC_ALARMMASK_MINUTES;

 sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;

 sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

 sAlarm.AlarmDateWeekDay = 0x1;

 sAlarm.Alarm = RTC_ALARM_A;

 if (HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)

 {

  Error_Handler();

 }

 //----------------------------------------------------------------------------

 if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)

 {

   __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // clear the flag

   /** Disable the WWAKEUP PIN **/

   HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // disable PA0

   /** Deactivate the RTC wakeup **/

   HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

 }

  /* clear the WU FLAG */

 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

  /* clear the RTC Wake UP (WU) flag */

 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

  

  /* clear the RTC ALARM A flag */

  __HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);

  

 /* Enable ALARM A module */

 __HAL_RTC_ALARMA_ENABLE(&hrtc);

  /* Enable the WAKEUP PIN ---> PA0 */

 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  

  /* Enter the standby mode */

 HAL_PWR_EnterSTANDBYMode();

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */   

 }

 /* USER CODE END 3 */

}

10 REPLIES 10
Alexey Ostrejkovsky
Associate II

I researched this problem in great detail.

First, alarm does not work, if I use BCD-format in calendar and alarm.

Second. Interrupt must be switched on for the RTC (line 17).