cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f042 standby mode cannot wake up from RTC.

jiangpen
Associate II
Posted on January 18, 2018 at 12:46

I put STM32f042 into standby mode, and enable the RTC alarm as 10 second. However, this RTC does not wake up the  STM32f042. 

I try below:

1) WKUP pin can wake up the standby mode correctly

2) If not put to standby mode, same RTC code interrupt can fire on 10 second later

3) STM32f042 RTC driver appears does not support the RTC wake up. For example, HAL_RTCEx_SetWakeUpTimer cannot be used for this MCU type

'#if defined(STM32F070xB) || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)'

My question is if STM32f042  has the capability to wake up standby from RTC? How about stop mode?

I don't see standby has limitation to wake up from RTC for this MCU in datasheet.

How about connect the PC13(RTC alarm pin) to a WKUP pin? Does this help?

thanks a lot

1 REPLY 1
jiangpen
Associate II
Posted on January 18, 2018 at 13:00

BTW, I post my code here:

RTC code:

/* RTC init function */

static void MX_RTC_Init(void)

{

  RTC_TimeTypeDef sTime;

  RTC_DateTypeDef sDate;

  RTC_AlarmTypeDef sAlarm;

    /**Initialize RTC Only

    */

  hrtc.Instance = RTC;

  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

  hrtc.Init.AsynchPrediv = 127;

  hrtc.Init.SynchPrediv = 255;

  hrtc.Init.OutPut = RTC_OUTPUT_ALARMA;

  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  if (HAL_RTC_Init(&hrtc) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

    /**Initialize RTC and set the Time and Date

    */

  sTime.Hours = 0x0;

  sTime.Minutes = 0x0;

  sTime.Seconds = 0x0;

  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sTime.StoreOperation = RTC_STOREOPERATION_RESET;

  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

  sDate.WeekDay = RTC_WEEKDAY_MONDAY;

  sDate.Month = RTC_MONTH_JANUARY;

  sDate.Date = 0x1;

  sDate.Year = 0x0;

  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

  if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){

    HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);

  }

    /**Enable the Alarm A

    */

  sAlarm.AlarmTime.Hours = 0x0;

  sAlarm.AlarmTime.Minutes = 0x0;

  sAlarm.AlarmTime.Seconds = 0x0a;

  sAlarm.AlarmTime.SubSeconds = 0x0;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_NONE;

  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(__FILE__, __LINE__);

  }

}

standby code:

void StandbyMode(void)

{

  /* Enable Power Clock*/

  __HAL_RCC_PWR_CLK_ENABLE();

  /* Allow access to Backup */

  HAL_PWR_EnableBkUpAccess();

  /* Reset RTC Domain */

  //__HAL_RCC_BACKUPRESET_FORCE();

  //__HAL_RCC_BACKUPRESET_RELEASE();

  /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry

     mainly  when using more than one wakeup source this is to not miss any wakeup event.

       - Disable all used wakeup sources,

       - Clear all related wakeup flags,

       - Re-enable all used wakeup sources,

       - Enter the Standby mode.

  */

  /*#### Disable all used wakeup sources: WKUP pin ###########################*/

  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN7);//connect PB15 to Vbus as wakeup source 7

  /*#### Clear all related wakeup flags ######################################*/

  /* Clear PWR wake up Flag */

  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

  /* Enable WKUP pin */

  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN7);

  /* Request to enter STANDBY mode */

  HAL_PWR_EnterSTANDBYMode();

}