Skip to content

Commit 76649d8

Browse files
dbestm0xc0170
authored andcommitted
[XXX_L15XX] Move erasing of BkUpR in RTC API
the erasing of back up register is only needed when using LSI
1 parent c90b7f8 commit 76649d8

File tree

1 file changed

+12
-10
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1

1 file changed

+12
-10
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ void rtc_init(void)
5151

5252
RtcHandle.Instance = RTC;
5353

54-
// Enable Power clock
55-
__PWR_CLK_ENABLE();
56-
57-
// Enable access to Backup domain
58-
HAL_PWR_EnableBkUpAccess();
59-
60-
// Reset Backup domain
61-
__HAL_RCC_BACKUPRESET_FORCE();
62-
__HAL_RCC_BACKUPRESET_RELEASE();
63-
6454
#if !DEVICE_RTC_LSI
6555
// Enable LSE Oscillator
6656
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
@@ -76,6 +66,16 @@ void rtc_init(void)
7666
error("Cannot initialize RTC with LSE\n");
7767
}
7868
#else
69+
// Enable Power clock
70+
__PWR_CLK_ENABLE();
71+
72+
// Enable access to Backup domain
73+
HAL_PWR_EnableBkUpAccess();
74+
75+
// Reset Backup domain
76+
__HAL_RCC_BACKUPRESET_FORCE();
77+
__HAL_RCC_BACKUPRESET_RELEASE();
78+
7979
// Enable LSI clock
8080
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
8181
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
@@ -114,6 +114,7 @@ void rtc_init(void)
114114

115115
void rtc_free(void)
116116
{
117+
#if DEVICE_RTC_LSI
117118
// Enable Power clock
118119
__PWR_CLK_ENABLE();
119120

@@ -126,6 +127,7 @@ void rtc_free(void)
126127

127128
// Disable access to Backup domain
128129
HAL_PWR_DisableBkUpAccess();
130+
#endif
129131

130132
// Disable LSI and LSE clocks
131133
RCC_OscInitTypeDef RCC_OscInitStruct;

0 commit comments

Comments
 (0)