@@ -100,22 +100,11 @@ void RTC_SetClockSource(sourceClock_t source)
100100 */
101101static void RTC_initClock (sourceClock_t source )
102102{
103- RCC_OscInitTypeDef RCC_OscInitStruct ;
104103 RCC_PeriphCLKInitTypeDef PeriphClkInit ;
105104
106105 if (source == LSE_CLOCK ) {
107106 /* 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 );
119108
120109 PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
121110 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSE ;
@@ -125,14 +114,8 @@ static void RTC_initClock(sourceClock_t source)
125114 clkSrc = LSE_CLOCK ;
126115 } else if (source == HSE_CLOCK ) {
127116 /* 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+
136119 /* HSE division factor for RTC clock must be set to ensure that
137120 * the clock supplied to the RTC is less than or equal to 1 MHz
138121 */
@@ -182,14 +165,7 @@ static void RTC_initClock(sourceClock_t source)
182165 clkSrc = HSE_CLOCK ;
183166 } else if (source == LSI_CLOCK ) {
184167 /* 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 );
193169
194170 PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
195171 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
@@ -314,14 +290,6 @@ void RTC_init(hourFormat_t format, sourceClock_t source)
314290{
315291 initFormat = format ;
316292
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-
325293 /* Init RTC clock */
326294 RTC_initClock (source );
327295
0 commit comments