1 | /* USER CODE BEGIN Header */ |
---|
2 | /** |
---|
3 | ****************************************************************************** |
---|
4 | * @file rtc.c |
---|
5 | * @brief This file provides code for the configuration |
---|
6 | * of the RTC instances. |
---|
7 | ****************************************************************************** |
---|
8 | * @attention |
---|
9 | * |
---|
10 | * Copyright (c) 2024 STMicroelectronics. |
---|
11 | * All rights reserved. |
---|
12 | * |
---|
13 | * This software is licensed under terms that can be found in the LICENSE file |
---|
14 | * in the root directory of this software component. |
---|
15 | * If no LICENSE file comes with this software, it is provided AS-IS. |
---|
16 | * |
---|
17 | ****************************************************************************** |
---|
18 | */ |
---|
19 | /* USER CODE END Header */ |
---|
20 | /* Includes ------------------------------------------------------------------*/ |
---|
21 | #include "rtc.h" |
---|
22 | |
---|
23 | /* USER CODE BEGIN 0 */ |
---|
24 | |
---|
25 | /* USER CODE END 0 */ |
---|
26 | |
---|
27 | RTC_HandleTypeDef hrtc; |
---|
28 | |
---|
29 | /* RTC init function */ |
---|
30 | void MX_RTC_Init(void) |
---|
31 | { |
---|
32 | |
---|
33 | /* USER CODE BEGIN RTC_Init 0 */ |
---|
34 | |
---|
35 | /* USER CODE END RTC_Init 0 */ |
---|
36 | |
---|
37 | /* USER CODE BEGIN RTC_Init 1 */ |
---|
38 | |
---|
39 | /* USER CODE END RTC_Init 1 */ |
---|
40 | |
---|
41 | /** Initialize RTC Only |
---|
42 | */ |
---|
43 | hrtc.Instance = RTC; |
---|
44 | hrtc.Init.HourFormat = RTC_HOURFORMAT_24; |
---|
45 | hrtc.Init.AsynchPrediv = 127; |
---|
46 | hrtc.Init.SynchPrediv = 255; |
---|
47 | hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; |
---|
48 | hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; |
---|
49 | hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; |
---|
50 | hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; |
---|
51 | if (HAL_RTC_Init(&hrtc) != HAL_OK) |
---|
52 | { |
---|
53 | Error_Handler(); |
---|
54 | } |
---|
55 | /* USER CODE BEGIN RTC_Init 2 */ |
---|
56 | |
---|
57 | /* USER CODE END RTC_Init 2 */ |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) |
---|
62 | { |
---|
63 | |
---|
64 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; |
---|
65 | if(rtcHandle->Instance==RTC) |
---|
66 | { |
---|
67 | /* USER CODE BEGIN RTC_MspInit 0 */ |
---|
68 | |
---|
69 | /* USER CODE END RTC_MspInit 0 */ |
---|
70 | |
---|
71 | /** Initializes the peripherals clock |
---|
72 | */ |
---|
73 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; |
---|
74 | PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
---|
75 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) |
---|
76 | { |
---|
77 | Error_Handler(); |
---|
78 | } |
---|
79 | |
---|
80 | /* RTC clock enable */ |
---|
81 | __HAL_RCC_RTC_ENABLE(); |
---|
82 | /* USER CODE BEGIN RTC_MspInit 1 */ |
---|
83 | |
---|
84 | /* USER CODE END RTC_MspInit 1 */ |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle) |
---|
89 | { |
---|
90 | |
---|
91 | if(rtcHandle->Instance==RTC) |
---|
92 | { |
---|
93 | /* USER CODE BEGIN RTC_MspDeInit 0 */ |
---|
94 | |
---|
95 | /* USER CODE END RTC_MspDeInit 0 */ |
---|
96 | /* Peripheral clock disable */ |
---|
97 | __HAL_RCC_RTC_DISABLE(); |
---|
98 | /* USER CODE BEGIN RTC_MspDeInit 1 */ |
---|
99 | |
---|
100 | /* USER CODE END RTC_MspDeInit 1 */ |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | /* USER CODE BEGIN 1 */ |
---|
105 | |
---|
106 | /* USER CODE END 1 */ |
---|