Skip to content

Commit 6501de9

Browse files
committed
Merge pull request #1548 from dbestm/dev_F446_rtc
[NUCLEO_F446RE] RTC+LSE+init
2 parents 2c6c939 + 81f3abc commit 6501de9

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_rcc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ void HAL_RCC_CSSCallback(void);
12171217
#define RCC_BDCR_BYTE0_ADDRESS (PERIPH_BASE + RCC_BDCR_OFFSET)
12181218

12191219
#define RCC_DBP_TIMEOUT_VALUE ((uint32_t)100)
1220-
#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
1220+
#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5000 ms */
12211221

12221222
#define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
12231223
#define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#define DEVICE_SPISLAVE 1
4949

5050
#define DEVICE_RTC 1
51+
#define DEVICE_RTC_LSI 0
5152

5253
#define DEVICE_PWMOUT 1
5354

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
#include "mbed_error.h"
3535

36+
#if DEVICE_RTC_LSI
3637
static int rtc_inited = 0;
38+
#endif
3739

3840
static RTC_HandleTypeDef RtcHandle;
3941

@@ -42,8 +44,9 @@ void rtc_init(void)
4244
RCC_OscInitTypeDef RCC_OscInitStruct;
4345
uint32_t rtc_freq = 0;
4446

45-
if (rtc_inited) return;
47+
#if DEVICE_RTC_LSI
4648
rtc_inited = 1;
49+
#endif
4750

4851
RtcHandle.Instance = RTC;
4952

@@ -57,6 +60,7 @@ void rtc_init(void)
5760
__HAL_RCC_BACKUPRESET_FORCE();
5861
__HAL_RCC_BACKUPRESET_RELEASE();
5962

63+
#if !DEVICE_RTC_LSI
6064
// Enable LSE Oscillator
6165
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
6266
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; /* Mandatory, otherwise the PLL is reconfigured! */
@@ -66,7 +70,11 @@ void rtc_init(void)
6670
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
6771
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
6872
rtc_freq = LSE_VALUE;
69-
} else {
73+
}
74+
else {
75+
error("RTC error: LSE clock initialization failed.");
76+
}
77+
#else
7078
// Enable LSI clock
7179
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
7280
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
@@ -80,10 +88,7 @@ void rtc_init(void)
8088
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
8189
// [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
8290
rtc_freq = LSI_VALUE;
83-
}
84-
85-
// Check if RTC is already initialized
86-
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return;
91+
#endif
8792

8893
// Enable RTC
8994
__HAL_RCC_RTC_ENABLE();
@@ -122,13 +127,19 @@ void rtc_free(void)
122127
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
123128
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
124129
HAL_RCC_OscConfig(&RCC_OscInitStruct);
125-
130+
#if DEVICE_RTC_LSI
126131
rtc_inited = 0;
132+
#endif
127133
}
128134

129135
int rtc_isenabled(void)
130136
{
137+
#if DEVICE_RTC_LSI
131138
return rtc_inited;
139+
#else
140+
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return 1;
141+
else return 0;
142+
#endif
132143
}
133144

134145
/*

0 commit comments

Comments
 (0)