184 lines
5.4 KiB
C
184 lines
5.4 KiB
C
/**
|
|
******************************************************************************
|
|
* @file rtc.c
|
|
* @author MCD Application Team
|
|
* @brief Configures the RTC instances
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at:
|
|
* www.st.com/SLA0044
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "rtc.h"
|
|
|
|
|
|
/* External variables --------------------------------------------------------*/
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
|
RTC_TimeTypeDef RTC_TimeStructureGet;
|
|
RTC_DateTypeDef RTC_DateStructureGet;
|
|
|
|
RTC_HandleTypeDef hrtc;
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* Exported variables --------------------------------------------------------*/
|
|
|
|
/* Exported functions --------------------------------------------------------*/
|
|
void MX_RTC_Init(void)
|
|
{
|
|
RTC_TimeTypeDef sTime = {0};
|
|
RTC_DateTypeDef sDate = {0};
|
|
RTC_AlarmTypeDef sAlarm = {0};
|
|
|
|
/** Initialize RTC Only
|
|
*/
|
|
hrtc.Instance = RTC;
|
|
|
|
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
|
hrtc.Init.AsynchPrediv = RTC_PREDIV_A;
|
|
hrtc.Init.SynchPrediv = RTC_PREDIV_S;
|
|
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;
|
|
|
|
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* USER CODE BEGIN Check_RTC_BKUP */
|
|
|
|
/* USER CODE END Check_RTC_BKUP */
|
|
|
|
/**Initialize RTC and set the Time and Date
|
|
*/
|
|
sTime.Hours = 0;
|
|
sTime.Minutes = 0;
|
|
sTime.Seconds = 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();
|
|
}
|
|
|
|
/**Enable the Alarm A
|
|
*/
|
|
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_SS14_10;
|
|
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
|
|
sAlarm.AlarmDateWeekDay = 30;
|
|
sAlarm.Alarm = RTC_ALARM_A;
|
|
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RTC MSP Initialization
|
|
* This function configures the hardware resources used in this example:
|
|
* - Peripheral's clock enable
|
|
* @param hrtc: RTC handle pointer
|
|
* @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
|
|
* the RTC clock source; in this case the Backup domain will be reset in
|
|
* order to modify the RTC Clock source, as consequence RTC registers (including
|
|
* the backup registers) and RCC_CSR register are set to their reset values.
|
|
* @retval none
|
|
*/
|
|
void HAL_RTC_MspInit(RTC_HandleTypeDef *rtcHandle)
|
|
{
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
|
|
if (rtcHandle->Instance == RTC)
|
|
{
|
|
/* USER CODE BEGIN RTC_MspInit 0 */
|
|
|
|
/* RCC configuration */
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
|
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
__HAL_RCC_RTCAPB_CLK_ENABLE() ;
|
|
/* USER CODE END RTC_MspInit 0 */
|
|
|
|
/* RTC clock enable */
|
|
__HAL_RCC_RTC_ENABLE();
|
|
|
|
/* RTC interrupt Init */
|
|
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
|
|
|
|
/* USER CODE BEGIN RTC_MspInit 1 */
|
|
|
|
/* USER CODE END RTC_MspInit 1 */
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RTC MSP DeInitialization
|
|
* @param hrtc: RTC handle pointer
|
|
* @retval none
|
|
*/
|
|
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *rtcHandle)
|
|
{
|
|
if (rtcHandle->Instance == RTC)
|
|
{
|
|
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
|
|
|
/* USER CODE END RTC_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_RTC_DISABLE();
|
|
/* RTC interrupt Deinit */
|
|
HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
|
|
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
|
|
|
|
|
/* USER CODE END RTC_MspDeInit 1 */
|
|
|
|
}
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
|