1 /**
2 ******************************************************************************
3 * @file stm32u5xx_hal_msp.c
4 * @author MCD Application Team
5 * @brief HAL MSP module.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>© Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
16 *
17 ******************************************************************************
18 */
19
20 /* Includes ------------------------------------------------------------------*/
21 #include "boot_hal_cfg.h"
22
23 /** @addtogroup STM32U5xx_HAL_Examples
24 * @{
25 */
26
27
28 /** @defgroup RTC_ActiveTamper
29 * @{
30 */
31
32 /* Private typedef -----------------------------------------------------------*/
33 /* Private define ------------------------------------------------------------*/
34 /* Private macro -------------------------------------------------------------*/
35 /* Private variables ---------------------------------------------------------*/
36 /* Private constant ----------------------------------------------------------*/
37 /** @defgroup HAL_MSP_Private_Constant
38 * @{
39 */
40 const RCC_OscInitTypeDef RCC_OscInitStruct_RTC =
41 {
42 .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE,
43 .HSEState = 0,
44 #if defined(RTC_CLOCK_SOURCE_LSE)
45 .LSEState = RCC_LSE_ON,
46 .LSIState = RCC_LSI_OFF,
47 #elif defined (RTC_CLOCK_SOURCE_LSI)
48 .LSEState = RCC_LSE_OFF,
49 .LSIState = RCC_LSI_ON,
50 #else
51 #error
52 #endif /* defined (RTC_CLOCK_SOURCE_LSI) */
53 .HSIState = 0,
54 .HSICalibrationValue = 0,
55 .LSIDiv = 0,
56 .MSIState = 0,
57 .MSICalibrationValue = 0,
58 .MSIClockRange = 0,
59 .MSIKClockRange = 0,
60 .HSI48State = 0,
61 .SHSIState = 0,
62 .MSIKState = 0,
63 .PLL = {
64 .PLLState = RCC_PLL_NONE,
65 .PLLSource = 0,
66 .PLLM = 0,
67 .PLLMBOOST = 0,
68 . PLLN = 0,
69 .PLLP = 0,
70 .PLLQ = 0,
71 .PLLR = 0,
72 .PLLRGE = 0,
73 .PLLFRACN = 0
74 }
75 };
76
77 const RCC_PeriphCLKInitTypeDef PeriphClkInitStruct_RTC =
78 {
79 .PeriphClockSelection = RCC_PERIPHCLK_RTC,
80 .PLL2 = {0},
81 .PLL3 = {0},
82 .Usart1ClockSelection = 0,
83 .Usart2ClockSelection = 0,
84 .Usart3ClockSelection = 0,
85 .Uart4ClockSelection = 0,
86 .Uart5ClockSelection = 0,
87 .Lpuart1ClockSelection = 0,
88 .I2c1ClockSelection = 0,
89 .I2c2ClockSelection = 0,
90 .I2c3ClockSelection = 0,
91 .I2c4ClockSelection = 0,
92 .Lptim1ClockSelection = 0,
93 .Lptim2ClockSelection = 0,
94 .Lptim34ClockSelection = 0,
95 .Fdcan1ClockSelection = 0,
96 .Mdf1ClockSelection = 0,
97 .Adf1ClockSelection = 0,
98 .Sai1ClockSelection = 0,
99 .Sai2ClockSelection = 0,
100 .RngClockSelection = 0,
101 .SaesClockSelection = 0,
102 .Clk48ClockSelection = 0,
103 .SdmmcClockSelection = 0,
104 .AdcDacClockSelection = 0,
105 .Dac1ClockSelection = 0,
106 .OspiClockSelection = 0,
107 .Spi1ClockSelection = 0,
108 .Spi2ClockSelection = 0,
109 .Spi3ClockSelection = 0,
110 #if defined(RTC_CLOCK_SOURCE_LSE)
111 .RTCClockSelection = RCC_RTCCLKSOURCE_LSE,
112 #elif defined (RTC_CLOCK_SOURCE_LSI)
113 .RTCClockSelection = RCC_RTCCLKSOURCE_LSI,
114 #else
115 #error
116 #endif /* RTC_CLOCK_SOURCE_LSE */
117 };
118 /**
119 * @}
120 */
121
122 /* Private function prototypes -----------------------------------------------*/
123 /* Private functions ---------------------------------------------------------*/
124
125 /** @defgroup HAL_MSP_Private_Functions
126 * @{
127 */
128
129 /**
130 * @brief RTC MSP Initialization
131 * This function configures the hardware resources used in this example:
132 * - Peripheral's clock enable
133 * @param hrtc: RTC handle pointer
134 * @retval None
135 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)136 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
137 {
138 __HAL_RCC_PWR_CLK_ENABLE();
139
140 HAL_PWR_EnableBkUpAccess();
141 /* not required to be removed */
142 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
143 /* Reset the whole backup domain, RTC included */
144 if (HAL_RCC_OscConfig((RCC_OscInitTypeDef *)&RCC_OscInitStruct_RTC) != HAL_OK)
145 {
146 Error_Handler();
147 }
148 if (HAL_RCCEx_PeriphCLKConfig((RCC_PeriphCLKInitTypeDef *)&PeriphClkInitStruct_RTC) != HAL_OK)
149 {
150 Error_Handler();
151 }
152 /* Enable RTC Clock */
153 __HAL_RCC_RTC_ENABLE();
154
155 /* Enable RTC APB clock */
156 __HAL_RCC_RTCAPB_CLK_ENABLE();
157
158 HAL_NVIC_SetPriority(TAMP_IRQn, 0x4, 0);
159 HAL_NVIC_EnableIRQ(TAMP_IRQn);
160 }
161
162 /**
163 * @brief RTC MSP De-Initialization
164 * This function freeze the hardware resources used in this example:
165 * - Disable the Peripheral's clock
166 * @param hrtc: RTC handle pointer
167 * @retval None
168 */
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)169 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc)
170 {
171 /*##-1- Reset peripherals ##################################################*/
172 __HAL_RCC_RTC_DISABLE();
173 }
174
175 /**
176 * @}
177 */
178
179 /**
180 * @}
181 */
182
183 /**
184 * @}
185 */
186
187 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
188