106 lines
2.5 KiB
C
106 lines
2.5 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file rtc.c
|
|
* @brief This file provides code for the configuration
|
|
* of the RTC instances.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2022 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "rtc.h"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
RTC_HandleTypeDef hrtc;
|
|
|
|
/* RTC init function */
|
|
void MX_RTC_Init(void)
|
|
{
|
|
|
|
/* 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
|
|
*/
|
|
hrtc.Instance = RTC;
|
|
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
|
hrtc.Init.AsynchPrediv = 124;
|
|
hrtc.Init.SynchPrediv = 3199;
|
|
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
|
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 RTC_Init 2 */
|
|
|
|
/* USER CODE END RTC_Init 2 */
|
|
|
|
}
|
|
|
|
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
|
|
{
|
|
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(rtcHandle->Instance==RTC)
|
|
{
|
|
/* USER CODE BEGIN RTC_MspInit 0 */
|
|
|
|
/* USER CODE END RTC_MspInit 0 */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
|
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV30;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* RTC clock enable */
|
|
__HAL_RCC_RTC_ENABLE();
|
|
/* USER CODE BEGIN RTC_MspInit 1 */
|
|
|
|
/* USER CODE END RTC_MspInit 1 */
|
|
}
|
|
}
|
|
|
|
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();
|
|
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
|
|
|
/* USER CODE END RTC_MspDeInit 1 */
|
|
}
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|