Src/main.c
/**
  * @brief RTC Initialization Function
  * @param None
  * @retval None
  */
@brief RTC Initialization Function
@param None
@retval None
@brief RTC Initialization Function @param None @retval None
static void MX_RTC_Init(void)
{
  RTC_TimeTypeDef sTime = {0};
  RTC_DateTypeDef sDate = {0};
  RTC_AlarmTypeDef sAlarm = {0};
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = 31;
  hrtc.Init.SynchPrediv = 999;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    Error_Handler();
  }
  sTime.Hours = 0;
  sTime.Minutes = 0;
  sTime.Seconds = 0;
  sTime.SubSeconds = 0;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  sDate.Month = RTC_MONTH_JANUARY;
  sDate.Date = 1;
  sDate.Year = 0;
  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  sAlarm.AlarmTime.Hours = 0;
  sAlarm.AlarmTime.Minutes = 0;
  sAlarm.AlarmTime.Seconds = 0;
  sAlarm.AlarmTime.SubSeconds = 0;
  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 = 1;
  sAlarm.Alarm = RTC_ALARM_A;
  if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0xFFFF, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK)
  {
    Error_Handler();
  }
}
static void MX_RTC_Init ( void ) { RTC_TimeTypeDef sTime = { 0 } ; RTC_DateTypeDef sDate = { 0 } ; RTC_AlarmTypeDef sAlarm = { 0 } ; hrtc . Instance = RTC ; hrtc . Init . HourFormat = RTC_HOURFORMAT_24 ; hrtc . Init . AsynchPrediv = 31 ; hrtc . Init . SynchPrediv = 999 ; hrtc . Init . OutPut = RTC_OUTPUT_DISABLE ; hrtc . Init . OutPutRemap = RTC_OUTPUT_REMAP_NONE ; hrtc . Init . OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH ; hrtc . Init . OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN ; hrtc . Init . OutPutPullUp = RTC_OUTPUT_PULLUP_NONE ; if ( HAL_RTC_Init ( & hrtc ) != HAL_OK ) { Error_Handler ( ) ; } sTime . Hours = 0 ; sTime . Minutes = 0 ; sTime . Seconds = 0 ; sTime . SubSeconds = 0 ; sTime . DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; sTime . StoreOperation = RTC_STOREOPERATION_RESET ; if ( HAL_RTC_SetTime ( & hrtc , & sTime , RTC_FORMAT_BIN ) != HAL_OK ) { Error_Handler ( ) ; } sDate . WeekDay = RTC_WEEKDAY_MONDAY ; sDate . Month = RTC_MONTH_JANUARY ; sDate . Date = 1 ; sDate . Year = 0 ; if ( HAL_RTC_SetDate ( & hrtc , & sDate , RTC_FORMAT_BIN ) != HAL_OK ) { Error_Handler ( ) ; } sAlarm . AlarmTime . Hours = 0 ; sAlarm . AlarmTime . Minutes = 0 ; sAlarm . AlarmTime . Seconds = 0 ; sAlarm . AlarmTime . SubSeconds = 0 ; 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 = 1 ; sAlarm . Alarm = RTC_ALARM_A ; if ( HAL_RTC_SetAlarm_IT ( & hrtc , & sAlarm , RTC_FORMAT_BIN ) != HAL_OK ) { Error_Handler ( ) ; } if ( HAL_RTCEx_SetWakeUpTimer_IT ( & hrtc , 0xFFFF , RTC_WAKEUPCLOCK_RTCCLK_DIV16 ) != HAL_OK ) { Error_Handler ( ) ; } if ( HAL_RTCEx_DeactivateWakeUpTimer ( & hrtc ) != HAL_OK ) { Error_Handler ( ) ; } }
@brief RTC Initialization Function
 @param None
 @retval None
@brief RTC Initialization Function @param None @retval None
/* USER CODE BEGIN RTC_Init 0 */ /* USER CODE END RTC_Init 0 */ /* USER CODE BEGIN RTC_Init 1 */ /* USER CODE END RTC_Init 1 */ /** Initialize RTC Only
  */ /* USER CODE BEGIN Check_RTC_BKUP */ /* USER CODE END Check_RTC_BKUP */ /** Initialize RTC and set the Time and Date
  */ /** Enable the Alarm A
  */ /** Enable the WakeUp
  */ /* USER CODE BEGIN RTC_Init 2 */ /* USER CODE END RTC_Init 2 */