@@ -52,16 +52,6 @@ void rtc_init(void)
52
52
53
53
RtcHandle .Instance = RTC ;
54
54
55
- // Enable Power clock
56
- __HAL_RCC_PWR_CLK_ENABLE ();
57
-
58
- // Enable access to Backup domain
59
- HAL_PWR_EnableBkUpAccess ();
60
-
61
- // Reset Backup domain
62
- __HAL_RCC_BACKUPRESET_FORCE ();
63
- __HAL_RCC_BACKUPRESET_RELEASE ();
64
-
65
55
#if !DEVICE_RTC_LSI
66
56
// Enable LSE Oscillator
67
57
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
@@ -78,6 +68,16 @@ void rtc_init(void)
78
68
error ("Cannot initialize RTC with LSE\n" );
79
69
}
80
70
#else
71
+ // Enable Power clock
72
+ __HAL_RCC_PWR_CLK_ENABLE ();
73
+
74
+ // Enable access to Backup domain
75
+ HAL_PWR_EnableBkUpAccess ();
76
+
77
+ // Reset Backup domain
78
+ __HAL_RCC_BACKUPRESET_FORCE ();
79
+ __HAL_RCC_BACKUPRESET_RELEASE ();
80
+
81
81
// Enable LSI clock
82
82
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
83
83
RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ; // Mandatory, otherwise the PLL is reconfigured!
@@ -116,6 +116,7 @@ void rtc_init(void)
116
116
117
117
void rtc_free (void )
118
118
{
119
+ #if DEVICE_RTC_LSI
119
120
// Enable Power clock
120
121
__HAL_RCC_PWR_CLK_ENABLE ();
121
122
@@ -128,6 +129,7 @@ void rtc_free(void)
128
129
129
130
// Disable access to Backup domain
130
131
HAL_PWR_DisableBkUpAccess ();
132
+ #endif
131
133
132
134
// Disable LSI and LSE clocks
133
135
RCC_OscInitTypeDef RCC_OscInitStruct ;
0 commit comments