summaryrefslogtreecommitdiff
path: root/stmhal/rtc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-03-16 22:54:44 +0000
committerDamien George <damien.p.george@gmail.com>2015-03-16 22:54:44 +0000
commit49fe6dc89a45a5791cfa8dad86f25469749f2312 (patch)
tree20c6f41f68d3a3d177704a1b914a8a9a2d6ccccf /stmhal/rtc.c
parent3cb766344ddd214c29d682929b78ae228b899c0b (diff)
stmhal: Add config option to use LSE/LSI for RTC.
Most boards (except the pyboard) don't have a 32kHz crystal so they should use the LSI for the RTC.
Diffstat (limited to 'stmhal/rtc.c')
-rw-r--r--stmhal/rtc.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/stmhal/rtc.c b/stmhal/rtc.c
index 2bbe5b10c..b4fa69e86 100644
--- a/stmhal/rtc.c
+++ b/stmhal/rtc.c
@@ -256,18 +256,29 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) {
__HAL_RCC_BACKUPRESET_RELEASE().
- Configure the needed RTc clock source */
- // set LSE as RTC clock source
+ // RTC clock source uses LSE (external crystal) only if relevant
+ // configuration variable is set. Otherwise it uses LSI (internal osc).
+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ #if defined(MICROPY_HW_RTC_USE_LSE) && MICROPY_HW_RTC_USE_LSE
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
+ #else
+ RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
+ RCC_OscInitStruct.LSIState = RCC_LSI_ON;
+ #endif
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
//Error_Handler();
return;
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+ #if defined(MICROPY_HW_RTC_USE_LSE) && MICROPY_HW_RTC_USE_LSE
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+ #else
+ PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
+ #endif
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
//Error_Handler();
return;