Skip to content

Commit 7a057d7

Browse files
authored
Merge pull request #8085 from jeromecoutant/PR_RTC_LSI
STM32 RTC : start LSI clock (for targets without LSE)
2 parents 8b62315 + 827c8bd commit 7a057d7

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

targets/TARGET_STM/TARGET_STM32F0/common_objects.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ struct flash_s {
148148
#endif
149149

150150
/* STM32F0 HAL doesn't provide this API called in rtc_api.c */
151-
#define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__)
152151
#define RTC_WKUP_IRQn RTC_IRQn
153152

154153
#endif

targets/TARGET_STM/TARGET_STM32F1/common_objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,4 @@ struct flash_s {
137137
}
138138
#endif
139139

140-
/* STM32F1 HAL doesn't provide this API called in rtc_api.c */
141-
#define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__)
142-
143140
#endif
144-

targets/TARGET_STM/TARGET_STM32F3/common_objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,4 @@ struct flash_s {
145145
}
146146
#endif
147147

148-
/* STM32F3 HAL doesn't provide this API called in rtc_api.c */
149-
#define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__)
150-
151148
#endif
152-

targets/TARGET_STM/TARGET_STM32L4/common_objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,4 @@ struct can_s {
143143
};
144144
#endif
145145

146-
/* STM32L4 HAL doesn't provide this API called in rtc_api.c */
147-
#define __HAL_RCC_RTC_CLKPRESCALER(__RTCCLKSource__)
148-
149146
#endif
150-

targets/TARGET_STM/mbed_overrides.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,21 @@ void mbed_sdk_init()
5454
SetSysClock();
5555
SystemCoreClockUpdate();
5656

57+
/* Start LSI clock for RTC */
58+
#if DEVICE_RTC
59+
#if !MBED_CONF_TARGET_LSE_AVAILABLE
60+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
61+
62+
if (__HAL_RCC_GET_RTC_SOURCE() != RCC_RTCCLKSOURCE_NO_CLK) {
63+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
64+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
65+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
66+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
67+
error("Init : cannot initialize LSI\n");
68+
}
69+
}
70+
#endif /* ! MBED_CONF_TARGET_LSE_AVAILABLE */
71+
#endif /* DEVICE_RTC */
72+
5773
mbed_sdk_inited = 1;
5874
}

targets/TARGET_STM/rtc_api.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ void rtc_init(void)
6060

6161
#if MBED_CONF_TARGET_LSE_AVAILABLE
6262
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
63-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
63+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
6464
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
65-
6665
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
6766
error("Cannot initialize RTC with LSE\n");
6867
}
6968

70-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
7169
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
7270

7371
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
@@ -76,19 +74,13 @@ void rtc_init(void)
7674
error("PeriphClkInitStruct RTC failed with LSE\n");
7775
}
7876
#else /* MBED_CONF_TARGET_LSE_AVAILABLE */
79-
// Reset Backup domain
80-
__HAL_RCC_BACKUPRESET_FORCE();
81-
__HAL_RCC_BACKUPRESET_RELEASE();
82-
83-
// Enable LSI clock
8477
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
85-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
78+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
8679
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
8780
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
8881
error("Cannot initialize RTC with LSI\n");
8982
}
9083

91-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
9284
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
9385

9486
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
@@ -116,14 +108,14 @@ void rtc_init(void)
116108
#endif /* TARGET_STM32F1 */
117109

118110
if (HAL_RTC_Init(&RtcHandle) != HAL_OK) {
119-
error("RTC initialization failed");
111+
error("RTC initialization failed\n");
120112
}
121113

122114
#if !(TARGET_STM32F1) && !(TARGET_STM32F2)
123115
/* STM32F1 : there are no shadow registers */
124116
/* STM32F2 : shadow registers can not be bypassed */
125117
if (HAL_RTCEx_EnableBypassShadow(&RtcHandle) != HAL_OK) {
126-
error("EnableBypassShadow error");
118+
error("EnableBypassShadow error\n");
127119
}
128120
#endif /* TARGET_STM32F1 || TARGET_STM32F2 */
129121
}

0 commit comments

Comments
 (0)