Skip to content

Commit 9b277ae

Browse files
bcostm0xc0170
authored andcommitted
[STM32L4] Change LSI_VALUE to 32 kHz (ARMmbed#1662)
* Add DEVICE_RTC_LSI=0 * Change LSI value to 32 kHz This is the value written in the device datasheet. * Replace tabulations with spaces
1 parent ffcdd68 commit 9b277ae

File tree

1 file changed

+19
-19
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4

1 file changed

+19
-19
lines changed

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void rtc_init(void)
6565
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
6666
rtc_freq = LSE_VALUE;
6767
} else {
68-
error("Cannot initialize RTC with LSE\n");
68+
error("Cannot initialize RTC with LSE\n");
6969
}
70-
#else
70+
#else
7171
// Enable Power clock
7272
__HAL_RCC_PWR_CLK_ENABLE();
7373

@@ -78,22 +78,22 @@ void rtc_init(void)
7878
__HAL_RCC_BACKUPRESET_FORCE();
7979
__HAL_RCC_BACKUPRESET_RELEASE();
8080

81-
// Enable LSI clock
82-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
83-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
84-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
85-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
86-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
87-
error("Cannot initialize RTC with LSI\n");
88-
}
89-
// Connect LSI to RTC
90-
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
91-
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
92-
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
93-
error("Cannot initialize RTC with LSI\n");
94-
}
95-
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
96-
rtc_freq = 40000;
81+
// Enable LSI clock
82+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
83+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
84+
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
85+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
86+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
87+
error("Cannot initialize RTC with LSI\n");
88+
}
89+
// Connect LSI to RTC
90+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
91+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
92+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
93+
error("Cannot initialize RTC with LSI\n");
94+
}
95+
// This value is LSI typical value (see device datasheet)
96+
rtc_freq = 32000;
9797
#endif
9898

9999
// Check if RTC is already initialized
@@ -141,7 +141,7 @@ void rtc_free(void)
141141

142142
#if DEVICE_RTC_LSI
143143
rtc_inited = 0;
144-
#endif
144+
#endif
145145
}
146146

147147
int rtc_isenabled(void)

0 commit comments

Comments
 (0)