Skip to content

Commit 47c580b

Browse files
committed
Merge pull request ARMmbed#1640 from dbestm/dev_xxx_f3xx_rtc
[XXX_F3XX] enhance RTC API
2 parents 43b94d2 + f6cafe3 commit 47c580b

File tree

8 files changed

+48
-27
lines changed

8 files changed

+48
-27
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_rcc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ typedef struct
164164
* @{
165165
*/
166166
/* LSE state change timeout */
167-
#define LSE_TIMEOUT_VALUE ((uint32_t)100) /* 5 s */
167+
#define LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */
168168

169169
/* Disable Backup domain write protection state change timeout */
170170
#define DBP_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/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_STM32F3/TARGET_DISCO_F334C8/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_STM32F3/TARGET_NUCLEO_F302R8/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_STM32F3/TARGET_NUCLEO_F303K8/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_STM32F3/TARGET_NUCLEO_F303RE/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_STM32F3/TARGET_NUCLEO_F334R8/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_STM32F3/rtc_api.c

Lines changed: 41 additions & 26 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,21 +44,13 @@ 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

50-
// Enable Power clock
51-
__PWR_CLK_ENABLE();
52-
53-
// Enable access to Backup domain
54-
HAL_PWR_EnableBkUpAccess();
55-
56-
// Reset Backup domain
57-
__HAL_RCC_BACKUPRESET_FORCE();
58-
__HAL_RCC_BACKUPRESET_RELEASE();
59-
53+
#if !DEVICE_RTC_LSI
6054
// Enable LSE Oscillator
6155
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
6256
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; /* Mandatory, otherwise the PLL is reconfigured! */
@@ -65,23 +59,35 @@ void rtc_init(void)
6559
// Connect LSE to RTC
6660
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
6761
rtc_freq = LSE_VALUE;
68-
} else {
69-
// Enable LSI clock
70-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
71-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
72-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
73-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
74-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
75-
error("RTC error: LSI clock initialization failed.");
76-
}
77-
// Connect LSI to RTC
78-
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
79-
// Note: The LSI clock can be measured precisely using a timer input capture.
80-
rtc_freq = LSI_VALUE;
8162
}
63+
else {
64+
error("RTC error: LSE clock initialization failed.");
65+
}
66+
#else
67+
// Enable Power clock
68+
__PWR_CLK_ENABLE();
69+
70+
// Enable access to Backup domain
71+
HAL_PWR_EnableBkUpAccess();
72+
73+
// Reset Backup domain
74+
__HAL_RCC_BACKUPRESET_FORCE();
75+
__HAL_RCC_BACKUPRESET_RELEASE();
76+
77+
// Enable LSI clock
78+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
79+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
80+
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
81+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
82+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
83+
error("RTC error: LSI clock initialization failed.");
84+
}
85+
// Connect LSI to RTC
86+
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
87+
// Note: The LSI clock can be measured precisely using a timer input capture.
88+
rtc_freq = LSI_VALUE;
89+
#endif
8290

83-
// Check if RTC is already initialized
84-
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return;
8591

8692
// Enable RTC
8793
__HAL_RCC_RTC_ENABLE();
@@ -100,6 +106,7 @@ void rtc_init(void)
100106

101107
void rtc_free(void)
102108
{
109+
#if DEVICE_RTC_LSI
103110
// Enable Power clock
104111
__PWR_CLK_ENABLE();
105112

@@ -112,6 +119,7 @@ void rtc_free(void)
112119

113120
// Disable access to Backup domain
114121
HAL_PWR_DisableBkUpAccess();
122+
#endif
115123

116124
// Disable LSI and LSE clocks
117125
RCC_OscInitTypeDef RCC_OscInitStruct;
@@ -121,12 +129,19 @@ void rtc_free(void)
121129
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
122130
HAL_RCC_OscConfig(&RCC_OscInitStruct);
123131

132+
#if DEVICE_RTC_LSI
124133
rtc_inited = 0;
134+
#endif
125135
}
126136

127137
int rtc_isenabled(void)
128138
{
139+
#if DEVICE_RTC_LSI
129140
return rtc_inited;
141+
#else
142+
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return 1;
143+
else return 0;
144+
#endif
130145
}
131146

132147
/*

0 commit comments

Comments
 (0)