Skip to content

Commit 31defa8

Browse files
committed
[xxx_F4XX] remove erasing of BkUpR in RTC API
the erasing of back up register is only needed when using LSI in RTC API
1 parent e42e174 commit 31defa8

File tree

1 file changed

+25
-23
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4

1 file changed

+25
-23
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c

+25-23
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ void rtc_init(void)
5050

5151
RtcHandle.Instance = RTC;
5252

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-
6353
#if !DEVICE_RTC_LSI
6454
// Enable LSE Oscillator
6555
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
@@ -75,19 +65,29 @@ void rtc_init(void)
7565
error("RTC error: LSE clock initialization failed.");
7666
}
7767
#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;
9191
#endif
9292

9393
// Enable RTC
@@ -107,6 +107,7 @@ void rtc_init(void)
107107

108108
void rtc_free(void)
109109
{
110+
#if DEVICE_RTC_LSI
110111
// Enable Power clock
111112
__PWR_CLK_ENABLE();
112113

@@ -119,6 +120,7 @@ void rtc_free(void)
119120

120121
// Disable access to Backup domain
121122
HAL_PWR_DisableBkUpAccess();
123+
#endif
122124

123125
// Disable LSI and LSE clocks
124126
RCC_OscInitTypeDef RCC_OscInitStruct;

0 commit comments

Comments
 (0)