Skip to content

Commit 5ebcc34

Browse files
committed
Merge pull request ARMmbed#1643 from dbestm/dev_xxx_f4xx_rtc
[XXX_F4XX] remove erasing of BkUpR in RTC API
2 parents 58c0b22 + 31defa8 commit 5ebcc34

File tree

8 files changed

+66
-45
lines changed

8 files changed

+66
-45
lines changed

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

+1-1
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

+1-1
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

+1-1
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_STM32F4/rtc_api.c

+25-23
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ void rtc_init(void)
5050

5151
RtcHandle.Instance = RTC;
5252

53-
// Enable Power clock
54-
__PWR_CLK_ENABLE();
55-
56-
// Enable access to Backup domain
57-
HAL_PWR_EnableBkUpAccess();
58-
59-
// Reset Backup domain
60-
__HAL_RCC_BACKUPRESET_FORCE();
61-
__HAL_RCC_BACKUPRESET_RELEASE();
62-
6353
#if !DEVICE_RTC_LSI
6454
// Enable LSE Oscillator
6555
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
@@ -75,19 +65,29 @@ void rtc_init(void)
7565
error("RTC error: LSE clock initialization failed.");
7666
}
7767
#else
78-
// Enable LSI clock
79-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
80-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
81-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
82-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
83-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
84-
error("RTC error: LSI clock initialization failed.");
85-
}
86-
// Connect LSI to RTC
87-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
88-
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
89-
// [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
90-
rtc_freq = LSI_VALUE;
68+
// Enable Power clock
69+
__PWR_CLK_ENABLE();
70+
71+
// Enable access to Backup domain
72+
HAL_PWR_EnableBkUpAccess();
73+
74+
// Reset Backup domain
75+
__HAL_RCC_BACKUPRESET_FORCE();
76+
__HAL_RCC_BACKUPRESET_RELEASE();
77+
78+
// Enable LSI clock
79+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
80+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
81+
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
82+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
83+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
84+
error("RTC error: LSI clock initialization failed.");
85+
}
86+
// Connect LSI to RTC
87+
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
88+
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
89+
// [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
90+
rtc_freq = LSI_VALUE;
9191
#endif
9292

9393
// Enable RTC
@@ -107,6 +107,7 @@ void rtc_init(void)
107107

108108
void rtc_free(void)
109109
{
110+
#if DEVICE_RTC_LSI
110111
// Enable Power clock
111112
__PWR_CLK_ENABLE();
112113

@@ -119,6 +120,7 @@ void rtc_free(void)
119120

120121
// Disable access to Backup domain
121122
HAL_PWR_DisableBkUpAccess();
123+
#endif
122124

123125
// Disable LSI and LSE clocks
124126
RCC_OscInitTypeDef RCC_OscInitStruct;

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device.h

+1
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

+1
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

+1
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

+35-19
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)