@@ -100,22 +100,11 @@ void RTC_SetClockSource(sourceClock_t source)
100
100
*/
101
101
static void RTC_initClock (sourceClock_t source )
102
102
{
103
- RCC_OscInitTypeDef RCC_OscInitStruct ;
104
103
RCC_PeriphCLKInitTypeDef PeriphClkInit ;
105
104
106
105
if (source == LSE_CLOCK ) {
107
106
/* Enable the clock if not already set by user */
108
- if (__HAL_RCC_GET_FLAG (RCC_FLAG_LSERDY ) == RESET ) {
109
- #ifdef __HAL_RCC_LSEDRIVE_CONFIG
110
- __HAL_RCC_LSEDRIVE_CONFIG (RCC_LSEDRIVE_LOW );
111
- #endif
112
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSE ;
113
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
114
- RCC_OscInitStruct .LSEState = RCC_LSE_ON ;
115
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
116
- Error_Handler ();
117
- }
118
- }
107
+ enableClock (LSE_CLOCK );
119
108
120
109
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
121
110
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSE ;
@@ -125,14 +114,8 @@ static void RTC_initClock(sourceClock_t source)
125
114
clkSrc = LSE_CLOCK ;
126
115
} else if (source == HSE_CLOCK ) {
127
116
/* Enable the clock if not already set by user */
128
- if (__HAL_RCC_GET_FLAG (RCC_FLAG_HSERDY ) == RESET ) {
129
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSE ;
130
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
131
- RCC_OscInitStruct .HSEState = RCC_HSE_ON ;
132
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
133
- Error_Handler ();
134
- }
135
- }
117
+ enableClock (HSE_CLOCK );
118
+
136
119
/* HSE division factor for RTC clock must be set to ensure that
137
120
* the clock supplied to the RTC is less than or equal to 1 MHz
138
121
*/
@@ -182,14 +165,7 @@ static void RTC_initClock(sourceClock_t source)
182
165
clkSrc = HSE_CLOCK ;
183
166
} else if (source == LSI_CLOCK ) {
184
167
/* Enable the clock if not already set by user */
185
- if (__HAL_RCC_GET_FLAG (RCC_FLAG_LSIRDY ) == RESET ) {
186
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI ;
187
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
188
- RCC_OscInitStruct .LSIState = RCC_LSI_ON ;
189
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
190
- Error_Handler ();
191
- }
192
- }
168
+ enableClock (LSI_CLOCK );
193
169
194
170
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
195
171
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
@@ -314,14 +290,6 @@ void RTC_init(hourFormat_t format, sourceClock_t source)
314
290
{
315
291
initFormat = format ;
316
292
317
- /* Enable Power Clock */
318
- __HAL_RCC_PWR_CLK_ENABLE ();
319
-
320
- #ifdef HAL_PWR_MODULE_ENABLED
321
- /* Allow access to Backup domain */
322
- HAL_PWR_EnableBkUpAccess ();
323
- #endif
324
-
325
293
/* Init RTC clock */
326
294
RTC_initClock (source );
327
295
0 commit comments