@@ -50,16 +50,6 @@ void rtc_init(void)
50
50
51
51
RtcHandle .Instance = RTC ;
52
52
53
- // Enable Power clock
54
- __PWR_CLK_ENABLE ();
55
-
56
- // Enable access to Backup domain
57
- HAL_PWR_EnableBkUpAccess ();
58
-
59
- // Reset Backup domain
60
- __HAL_RCC_BACKUPRESET_FORCE ();
61
- __HAL_RCC_BACKUPRESET_RELEASE ();
62
-
63
53
#if !DEVICE_RTC_LSI
64
54
// Enable LSE Oscillator
65
55
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSE ;
@@ -75,19 +65,29 @@ void rtc_init(void)
75
65
error ("RTC error: LSE clock initialization failed." );
76
66
}
77
67
#else
78
- // Enable LSI clock
79
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
80
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ; // Mandatory, otherwise the PLL is reconfigured!
81
- RCC_OscInitStruct .LSEState = RCC_LSE_OFF ;
82
- RCC_OscInitStruct .LSIState = RCC_LSI_ON ;
83
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
84
- error ("RTC error: LSI clock initialization failed." );
85
- }
86
- // Connect LSI to RTC
87
- __HAL_RCC_RTC_CLKPRESCALER (RCC_RTCCLKSOURCE_LSI );
88
- __HAL_RCC_RTC_CONFIG (RCC_RTCCLKSOURCE_LSI );
89
- // [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
90
- rtc_freq = LSI_VALUE ;
68
+ // Enable Power clock
69
+ __PWR_CLK_ENABLE ();
70
+
71
+ // Enable access to Backup domain
72
+ HAL_PWR_EnableBkUpAccess ();
73
+
74
+ // Reset Backup domain
75
+ __HAL_RCC_BACKUPRESET_FORCE ();
76
+ __HAL_RCC_BACKUPRESET_RELEASE ();
77
+
78
+ // Enable LSI clock
79
+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
80
+ RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ; // Mandatory, otherwise the PLL is reconfigured!
81
+ RCC_OscInitStruct .LSEState = RCC_LSE_OFF ;
82
+ RCC_OscInitStruct .LSIState = RCC_LSI_ON ;
83
+ if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
84
+ error ("RTC error: LSI clock initialization failed." );
85
+ }
86
+ // Connect LSI to RTC
87
+ __HAL_RCC_RTC_CLKPRESCALER (RCC_RTCCLKSOURCE_LSI );
88
+ __HAL_RCC_RTC_CONFIG (RCC_RTCCLKSOURCE_LSI );
89
+ // [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
90
+ rtc_freq = LSI_VALUE ;
91
91
#endif
92
92
93
93
// Enable RTC
@@ -107,6 +107,7 @@ void rtc_init(void)
107
107
108
108
void rtc_free (void )
109
109
{
110
+ #if DEVICE_RTC_LSI
110
111
// Enable Power clock
111
112
__PWR_CLK_ENABLE ();
112
113
@@ -119,6 +120,7 @@ void rtc_free(void)
119
120
120
121
// Disable access to Backup domain
121
122
HAL_PWR_DisableBkUpAccess ();
123
+ #endif
122
124
123
125
// Disable LSI and LSE clocks
124
126
RCC_OscInitTypeDef RCC_OscInitStruct ;
0 commit comments