Skip to content

Commit c4e913b

Browse files
author
Cruz Monrreal
authored
Merge pull request #8960 from jeromecoutant/PR_RTC2
STM32: avoid STM32 family name check
2 parents 54f53e0 + 4aca14f commit c4e913b

File tree

12 files changed

+62
-69
lines changed

12 files changed

+62
-69
lines changed

targets/TARGET_STM/TARGET_STM32F0/device/stm32f0xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32f0xx_hal_def.h"
46+
#include "stm32f0xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32F0xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
/* Includes ------------------------------------------------------------------*/
4747
#include "stm32f2xx_hal_def.h"
48+
#include "stm32f2xx_ll_rtc.h"
4849

4950
/** @addtogroup STM32F2xx_HAL_Driver
5051
* @{

targets/TARGET_STM/TARGET_STM32F3/device/stm32f3xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32f3xx_hal_def.h"
46+
#include "stm32f3xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32F3xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32f4xx_hal_def.h"
46+
#include "stm32f4xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32F4xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32f7xx_hal_def.h"
46+
#include "stm32f7xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32F7xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32l0xx_hal_def.h"
46+
#include "stm32l0xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32L0xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32L1/device/stm32l1xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32l1xx_hal_def.h"
46+
#include "stm32l1xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32L1xx_HAL_Driver
4849
* @{

targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_rtc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
/* Includes ------------------------------------------------------------------*/
4545
#include "stm32l4xx_hal_def.h"
46+
#include "stm32l4xx_ll_rtc.h"
4647

4748
/** @addtogroup STM32L4xx_HAL_Driver
4849
* @{

targets/TARGET_STM/lp_ticker.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ void lp_ticker_init(void)
139139
LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
140140
LptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
141141
LptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
142-
#if (TARGET_STM32L4)
142+
#if defined (LPTIM_INPUT1SOURCE_GPIO) /* STM32L4 */
143143
LptimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
144144
LptimHandle.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
145-
#endif /* TARGET_STM32L4 */
145+
#endif /* LPTIM_INPUT1SOURCE_GPIO */
146146

147147
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK) {
148148
error("HAL_LPTIM_Init ERROR\n");
@@ -151,7 +151,7 @@ void lp_ticker_init(void)
151151

152152
NVIC_SetVector(LPTIM1_IRQn, (uint32_t)LPTIM1_IRQHandler);
153153

154-
#if !(TARGET_STM32L4)
154+
#if defined (__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT)
155155
/* EXTI lines are not configured by default */
156156
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
157157
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
@@ -190,7 +190,8 @@ static void LPTIM1_IRQHandler(void)
190190
}
191191
}
192192

193-
#if !(TARGET_STM32L4)
193+
#if defined (__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG)
194+
/* EXTI lines are not configured by default */
194195
__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
195196
#endif
196197
}

targets/TARGET_STM/mbed_overrides.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int mbed_sdk_inited = 0;
3232
// This function is called after RAM initialization and before main.
3333
void mbed_sdk_init()
3434
{
35-
#if TARGET_STM32F7
35+
#if defined(__ICACHE_PRESENT) /* STM32F7 */
3636
// The mbed_sdk_init can be called either during cold boot or during
3737
// application boot after bootloader has been executed.
3838
// In case the bootloader has already enabled the cache,
@@ -43,7 +43,7 @@ void mbed_sdk_init()
4343
if ((SCB->CCR & (uint32_t)SCB_CCR_DC_Msk) == 0) { // If DCache is disabled
4444
SCB_EnableDCache();
4545
}
46-
#endif /* TARGET_STM32F7 */
46+
#endif /* __ICACHE_PRESENT */
4747

4848
// Update the SystemCoreClock variable.
4949
SystemCoreClockUpdate();

targets/TARGET_STM/rtc_api.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ void rtc_init(void)
9393
// Enable RTC
9494
__HAL_RCC_RTC_ENABLE();
9595

96+
#if defined __HAL_RCC_RTCAPB_CLK_ENABLE /* part of STM32L4 */
97+
__HAL_RCC_RTCAPB_CLK_ENABLE();
98+
#endif /* __HAL_RCC_RTCAPB_CLK_ENABLE */
99+
96100
RtcHandle.Instance = RTC;
97101
RtcHandle.State = HAL_RTC_STATE_RESET;
98102

@@ -105,6 +109,12 @@ void rtc_init(void)
105109
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
106110
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
107111
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
112+
#if defined (RTC_OUTPUT_REMAP_NONE)
113+
RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
114+
#endif /* defined (RTC_OUTPUT_REMAP_NONE) */
115+
#if defined (RTC_OUTPUT_PULLUP_NONE)
116+
RtcHandle.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
117+
#endif /* defined (RTC_OUTPUT_PULLUP_NONE) */
108118
#endif /* TARGET_STM32F1 */
109119

110120
if (HAL_RTC_Init(&RtcHandle) != HAL_OK) {
@@ -257,11 +267,11 @@ void rtc_write(time_t t)
257267

258268
int rtc_isenabled(void)
259269
{
260-
#if !(TARGET_STM32F1)
261-
return ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS);
262-
#else /* TARGET_STM32F1 */
270+
#if defined (RTC_FLAG_INITS) /* all STM32 except STM32F1 */
271+
return LL_RTC_IsActiveFlag_INITS(RTC);
272+
#else /* RTC_FLAG_INITS */ /* TARGET_STM32F1 */
263273
return ((RTC->CRL & RTC_CRL_RSF) == RTC_CRL_RSF);
264-
#endif /* TARGET_STM32F1 */
274+
#endif /* RTC_FLAG_INITS */
265275
}
266276

267277

@@ -296,7 +306,9 @@ static void RTC_IRQHandler(void)
296306
}
297307
}
298308

309+
#ifdef __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG
299310
__HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
311+
#endif
300312
}
301313

302314
uint32_t rtc_read_lp(void)

targets/TARGET_STM/sleep.c

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,38 @@ static void wait_loop(uint32_t timeout)
5151
}
5252

5353

54-
// On L4 platforms we've seen unstable PLL CLK configuraiton
55-
// when DEEP SLEEP exits just few µs after being entered
56-
// So we need to force MSI usage before setting clocks again
5754
static void ForcePeriphOutofDeepSleep(void)
5855
{
5956
uint32_t pFLatency = 0;
6057
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
6158

62-
#if (TARGET_STM32L4 || TARGET_STM32L1) /* MSI used for L4 */
6359
/* Get the Clocks configuration according to the internal RCC registers */
6460
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
6561

66-
// Select HSI ss system clock source as a first step
67-
#ifdef RCC_CLOCKTYPE_PCLK2
68-
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
69-
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
70-
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
71-
#else
72-
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
73-
| RCC_CLOCKTYPE_PCLK1);
74-
#endif
75-
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
76-
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
77-
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
78-
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) {
79-
error("clock issue\r\n");
80-
}
81-
#else /* HSI used on others */
82-
/* Get the Clocks configuration according to the internal RCC registers */
83-
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
84-
85-
/**Initializes the CPU, AHB and APB busses clocks
86-
*/
8762
#ifdef RCC_CLOCKTYPE_PCLK2
8863
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
8964
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
9065
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
91-
#else
66+
#else /* RCC_CLOCKTYPE_PCLK2 */
9267
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
9368
| RCC_CLOCKTYPE_PCLK1);
94-
#endif
69+
#endif /* RCC_CLOCKTYPE_PCLK2 */
70+
71+
#if defined (RCC_SYSCLKSOURCE_MSI) /* STM32Lx */
72+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
73+
#else /* defined RCC_SYSCLKSOURCE_MSI */
9574
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
96-
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
97-
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
75+
#endif /* defined RCC_SYSCLKSOURCE_MSI */
76+
77+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
78+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
79+
9880
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) {
99-
error("clock issue");
81+
error("ForcePeriphOutofDeepSleep clock issue\r\n");
10082
}
101-
#endif // TARGET_STM32L4
10283
}
10384

85+
10486
static void ForceOscOutofDeepSleep(void)
10587
{
10688
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
@@ -111,47 +93,32 @@ static void ForceOscOutofDeepSleep(void)
11193
/* Get the Oscillators configuration according to the internal RCC registers */
11294
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
11395

114-
#if (TARGET_STM32L4 || TARGET_STM32L1) /* MSI used for L4 */
115-
/**Initializes the CPU, AHB and APB busses clocks
116-
*/
96+
#if defined (RCC_SYSCLKSOURCE_MSI) /* STM32Lx */
11797
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
11898
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
11999
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
120100
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4; // Intermediate freq, 1MHz range
121101
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
122-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
123-
error("clock issue\r\n");
124-
}
125-
#else /* HSI used on others */
126-
/**Initializes the CPU, AHB and APB busses clocks
127-
*/
102+
#else /* defined RCC_SYSCLKSOURCE_MSI */
128103
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
129104
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
130105
RCC_OscInitStruct.HSICalibrationValue = 16;
131106
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
107+
#endif /* defined RCC_SYSCLKSOURCE_MSI */
108+
132109
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
133-
error("clock issue");
110+
error("ForceOscOutofDeepSleep clock issue\r\n");
134111
}
135-
#endif // TARGET_STM32L4
136112
}
137113

138-
/* The content of this function has been split into 2 separate functions
139-
so that the involved structures are not allocated on the stack in parallel.
140-
This will reduce the maximum stack usage in case on non-optimized / debug
141-
compilers settings */
142-
static void ForceClockOutofDeepSleep(void)
143-
{
144-
ForceOscOutofDeepSleep();
145-
ForcePeriphOutofDeepSleep();
146-
}
147114

148115
void hal_sleep(void)
149116
{
150117
// Disable IRQs
151118
core_util_critical_section_enter();
152119

153120
// Request to enter SLEEP mode
154-
#if TARGET_STM32L4
121+
#ifdef PWR_CR1_LPR
155122
// State Transitions (see 5.3 Low-power modes, Fig. 13):
156123
// * (opt): Low Power Run (LPR) Mode -> Run Mode
157124
// * Run Mode -> Sleep
@@ -160,7 +127,7 @@ void hal_sleep(void)
160127
// * (opt): Run Mode -> Low Power Run Mode
161128

162129
// [5.4.1 Power control register 1 (PWR_CR1)]
163-
// LPR: When this bit is set, the regulator is switched from main mode (MR) to low-power mode (LPR).
130+
// LPR: When this bit is set, the regulator is switched from main mode (MR) to low-power mode (LPR).
164131
int lowPowerMode = PWR->CR1 & PWR_CR1_LPR;
165132
if (lowPowerMode) {
166133
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
@@ -186,7 +153,7 @@ void hal_deepsleep(void)
186153
* This is tracked in mbed issue 4408.
187154
* For now, we're checking all Serial HW FIFO. If any transfer is ongoing
188155
* we're not entering deep sleep and returning immediately. */
189-
if(serial_is_tx_ongoing()) {
156+
if (serial_is_tx_ongoing()) {
190157
return;
191158
}
192159

@@ -196,7 +163,7 @@ void hal_deepsleep(void)
196163
save_timer_ctx();
197164

198165
// Request to enter STOP mode with regulator in low power mode
199-
#if TARGET_STM32L4
166+
#ifdef PWR_CR1_LPMS_STOP2 /* STM32L4 */
200167
int pwrClockEnabled = __HAL_RCC_PWR_IS_CLK_ENABLED();
201168
int lowPowerModeEnabled = PWR->CR1 & PWR_CR1_LPR;
202169

@@ -215,16 +182,21 @@ void hal_deepsleep(void)
215182
if (!pwrClockEnabled) {
216183
__HAL_RCC_PWR_CLK_DISABLE();
217184
}
218-
#else /* TARGET_STM32L4 */
185+
#else /* PWR_CR1_LPMS_STOP2 */
219186
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
220-
#endif /* TARGET_STM32L4 */
187+
#endif /* PWR_CR1_LPMS_STOP2 */
221188

222189
/* Prevent HAL_GetTick() from using ticker_read_us() to read the
223190
* us_ticker timestamp until the us_ticker context is restored. */
224191
mbed_sdk_inited = 0;
225192

226-
// Verify Clock Out of Deep Sleep
227-
ForceClockOutofDeepSleep();
193+
/* We've seen unstable PLL CLK configuration when DEEP SLEEP exits just few µs after being entered
194+
* So we need to force clock init out of Deep Sleep.
195+
* This init has been split into 2 separate functions so that the involved structures are not allocated on the stack in parallel.
196+
* This will reduce the maximum stack usage in case on non-optimized / debug compilers settings
197+
*/
198+
ForceOscOutofDeepSleep();
199+
ForcePeriphOutofDeepSleep();
228200

229201
// After wake-up from STOP reconfigure the PLL
230202
SetSysClock();

0 commit comments

Comments
 (0)