Skip to content

Commit 57c70d6

Browse files
committed
stmhal: Move RTC HAL init functions to rtc.c, where they belong.
So can remove unnecessary stm32f4xx_hal_msp.c file.
1 parent 578ea6d commit 57c70d6

3 files changed

Lines changed: 45 additions & 150 deletions

File tree

stmhal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ SRC_C = \
7676
string0.c \
7777
system_stm32f4xx.c \
7878
stm32f4xx_it.c \
79-
stm32f4xx_hal_msp.c \
8079
usbd_conf.c \
8180
usbd_desc_cdc_msc.c \
8281
usbd_cdc_interface.c \

stmhal/rtc.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void rtc_init(void) {
161161
}
162162
#endif
163163

164-
static void RTC_CalendarConfig(void);
164+
STATIC void RTC_CalendarConfig(void);
165165

166166
void rtc_init(void) {
167167
RTCHandle.Instance = RTC;
@@ -211,7 +211,7 @@ void rtc_init(void) {
211211
}
212212
}
213213

214-
static void RTC_CalendarConfig(void) {
214+
STATIC void RTC_CalendarConfig(void) {
215215
// set the date to 1st Jan 2014
216216
RTC_DateTypeDef date;
217217
date.Year = 14;
@@ -242,6 +242,49 @@ static void RTC_CalendarConfig(void) {
242242
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x32f2);
243243
}
244244

245+
/*
246+
Note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
247+
the RTC clock source; in this case the Backup domain will be reset in
248+
order to modify the RTC Clock source, as consequence RTC registers (including
249+
the backup registers) and RCC_BDCR register are set to their reset values.
250+
*/
251+
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) {
252+
RCC_OscInitTypeDef RCC_OscInitStruct;
253+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
254+
255+
/* To change the source clock of the RTC feature (LSE, LSI), You have to:
256+
- Enable the power clock using __PWR_CLK_ENABLE()
257+
- Enable write access using HAL_PWR_EnableBkUpAccess() function before to
258+
configure the RTC clock source (to be done once after reset).
259+
- Reset the Back up Domain using __HAL_RCC_BACKUPRESET_FORCE() and
260+
__HAL_RCC_BACKUPRESET_RELEASE().
261+
- Configure the needed RTc clock source */
262+
263+
// set LSE as RTC clock source
264+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
265+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
266+
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
267+
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
268+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
269+
//Error_Handler();
270+
return;
271+
}
272+
273+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
274+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
275+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
276+
//Error_Handler();
277+
return;
278+
}
279+
280+
// enable RTC peripheral clock
281+
__HAL_RCC_RTC_ENABLE();
282+
}
283+
284+
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) {
285+
__HAL_RCC_RTC_DISABLE();
286+
}
287+
245288
/******************************************************************************/
246289
// Micro Python bindings
247290

stmhal/stm32f4xx_hal_msp.c

Lines changed: 0 additions & 147 deletions
This file was deleted.

0 commit comments

Comments
 (0)