Skip to content

Commit e42e174

Browse files
committed
[XXX_L15XXX] enhance RTC files
1 parent 4694003 commit e42e174

File tree

7 files changed

+41
-22
lines changed

7 files changed

+41
-22
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/stm32l1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123

124124
#if !defined (LSE_STARTUP_TIMEOUT)
125-
#define LSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for LSE start up, in ms */
125+
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
126126
#endif /* HSE_STARTUP_TIMEOUT */
127127

128128

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/stm32l1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123

124124
#if !defined (LSE_STARTUP_TIMEOUT)
125-
#define LSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for LSE start up, in ms */
125+
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
126126
#endif /* HSE_STARTUP_TIMEOUT */
127127

128128

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/stm32l1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123

124124
#if !defined (LSE_STARTUP_TIMEOUT)
125-
#define LSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for LSE start up, in ms */
125+
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
126126
#endif /* HSE_STARTUP_TIMEOUT */
127127

128128

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/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 1
5152

5253
#define DEVICE_PWMOUT 1
5354

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/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_STM32L1/TARGET_NZ32_SC151/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#define DEVICE_SPISLAVE 1
5858

5959
#define DEVICE_RTC 1
60+
#define DEVICE_RTC_LSI 1
6061

6162
#define DEVICE_PWMOUT 1
6263

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

Lines changed: 35 additions & 19 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
RTC_HandleTypeDef RtcHandle;
3941

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

47+
#if DEVICE_RTC_LSI
4548
if (rtc_inited) return;
4649
rtc_inited = 1;
50+
#endif
4751

4852
RtcHandle.Instance = RTC;
4953

@@ -57,33 +61,35 @@ void rtc_init(void)
5761
__HAL_RCC_BACKUPRESET_FORCE();
5862
__HAL_RCC_BACKUPRESET_RELEASE();
5963

64+
#if !DEVICE_RTC_LSI
6065
// Enable LSE Oscillator
61-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
66+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
6267
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
6368
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
64-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
69+
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
70+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) { // Check if LSE has started correctly
6571
// Connect LSE to RTC
6672
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
6773
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
6874
rtc_freq = LSE_VALUE;
6975
} else {
70-
// Enable LSI clock
71-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
72-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
73-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
74-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
75-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
76-
error("RTC error: LSI clock initialization failed.");
77-
}
78-
// Connect LSI to RTC
79-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
80-
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
81-
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
82-
rtc_freq = 40000;
76+
error("Cannot initialize RTC with LSE\n");
8377
}
84-
85-
// Check if RTC is already initialized
86-
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return;
78+
#else
79+
// Enable LSI clock
80+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
81+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
82+
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
83+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
84+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
85+
error("Cannot initialize RTC with LSI\n");
86+
}
87+
// Connect LSI to RTC
88+
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
89+
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
90+
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
91+
rtc_freq = 40000;
92+
#endif
8793

8894
// Enable RTC
8995
__HAL_RCC_RTC_ENABLE();
@@ -129,12 +135,22 @@ void rtc_free(void)
129135
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
130136
HAL_RCC_OscConfig(&RCC_OscInitStruct);
131137

138+
#if DEVICE_RTC_LSI
132139
rtc_inited = 0;
140+
#endif
133141
}
134142

135143
int rtc_isenabled(void)
136144
{
137-
return rtc_inited;
145+
#if DEVICE_RTC_LSI
146+
return rtc_inited;
147+
#else
148+
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) {
149+
return 1;
150+
} else {
151+
return 0;
152+
}
153+
#endif
138154
}
139155

140156
/*

0 commit comments

Comments
 (0)