Skip to content

Commit 864606b

Browse files
committed
bsp: add support for the STM32U5xx soc
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 3f26f9b commit 864606b

File tree

2 files changed

+101
-22
lines changed

2 files changed

+101
-22
lines changed

src/STM32LowPower.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void STM32LowPower::programRtcWakeUp(uint32_t ms, LP_Mode lp_mode)
191191
break;
192192
default:
193193
case SHUTDOWN_MODE:
194-
#if defined(STM32L4xx) || defined(STM32L5xx)
195-
// For shutdown mode LSE have to be used (STM32L4 or STM32L5 series only)
194+
#if defined(PWR_CR1_LPMS)
195+
// For shutdown mode LSE have to be used
196196
clkSrc = STM32RTC::LSE_CLOCK;
197197
#else
198198
// LSE or LSI

src/low_power.c

+99-20
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020

2121
#include "Arduino.h"
2222
#include "low_power.h"
23+
#include "stm32yyxx_ll_pwr.h"
2324

24-
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01090000) &&\
25-
defined(HAL_PWR_MODULE_ENABLED) && !defined(HAL_PWR_MODULE_ONLY)
25+
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01090000) \
26+
&& defined(HAL_PWR_MODULE_ENABLED) && !defined(HAL_PWR_MODULE_ONLY)
27+
28+
#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) \
29+
&& (defined(UART_IT_WUF) || defined(LPUART1_BASE))
30+
#define UART_WKUP_SUPPORT
31+
#endif
2632

2733
#ifdef __cplusplus
2834
extern "C" {
2935
#endif
3036

31-
#if defined(UART_IT_WUF) && defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
37+
#if defined(UART_WKUP_SUPPORT)
3238
/* Save UART handler for callback */
3339
static UART_HandleTypeDef *WakeUpUart = NULL;
3440
#endif
@@ -37,6 +43,11 @@ static void (*WakeUpUartCb)(void) = NULL;
3743

3844
#if defined(PWR_FLAG_WUF)
3945
#define PWR_FLAG_WU PWR_FLAG_WUF
46+
#elif defined(PWR_WAKEUP_ALL_FLAG)
47+
#define PWR_FLAG_WU PWR_WAKEUP_ALL_FLAG
48+
#endif
49+
#if defined(PWR_FLAG_SBF)
50+
#define PWR_FLAG_SB PWR_FLAG_SBF
4051
#endif
4152

4253
/**
@@ -82,7 +93,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
8293
PinName p = digitalPinToPinName(pin);
8394
if (p != NC) {
8495
#ifdef PWR_WAKEUP_PIN1
85-
if (p == SYS_WKUP1) {
96+
if ((p == SYS_WKUP1)
97+
#ifdef PWR_WAKEUP_PIN1_1
98+
|| (p == SYS_WKUP1_1)
99+
#endif
100+
#ifdef PWR_WAKEUP_PIN1_2
101+
|| (p == SYS_WKUP1_2)
102+
#endif
103+
) {
86104
wkup_pin = PWR_WAKEUP_PIN1;
87105
#ifdef PWR_WAKEUP_PIN1_HIGH
88106
if (mode != RISING) {
@@ -92,7 +110,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
92110
}
93111
#endif /* PWR_WAKEUP_PIN1 */
94112
#ifdef PWR_WAKEUP_PIN2
95-
if (p == SYS_WKUP2) {
113+
if ((p == SYS_WKUP2)
114+
#ifdef PWR_WAKEUP_PIN2_1
115+
|| (p == SYS_WKUP2_1)
116+
#endif
117+
#ifdef PWR_WAKEUP_PIN2_2
118+
|| (p == SYS_WKUP2_2)
119+
#endif
120+
) {
96121
wkup_pin = PWR_WAKEUP_PIN2;
97122
#ifdef PWR_WAKEUP_PIN2_HIGH
98123
if (mode != RISING) {
@@ -102,7 +127,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
102127
}
103128
#endif /* PWR_WAKEUP_PIN2 */
104129
#ifdef PWR_WAKEUP_PIN3
105-
if (p == SYS_WKUP3) {
130+
if ((p == SYS_WKUP3)
131+
#ifdef PWR_WAKEUP_PIN3_1
132+
|| (p == SYS_WKUP3_1)
133+
#endif
134+
#ifdef PWR_WAKEUP_PIN3_2
135+
|| (p == SYS_WKUP3_2)
136+
#endif
137+
) {
106138
wkup_pin = PWR_WAKEUP_PIN3;
107139
#ifdef PWR_WAKEUP_PIN3_HIGH
108140
if (mode != RISING) {
@@ -112,7 +144,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
112144
}
113145
#endif /* PWR_WAKEUP_PIN3 */
114146
#ifdef PWR_WAKEUP_PIN4
115-
if (p == SYS_WKUP4) {
147+
if ((p == SYS_WKUP4)
148+
#ifdef PWR_WAKEUP_PIN4_1
149+
|| (p == SYS_WKUP4_1)
150+
#endif
151+
#ifdef PWR_WAKEUP_PIN4_2
152+
|| (p == SYS_WKUP4_2)
153+
#endif
154+
) {
116155
wkup_pin = PWR_WAKEUP_PIN4;
117156
#ifdef PWR_WAKEUP_PIN4_HIGH
118157
if (mode != RISING) {
@@ -122,7 +161,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
122161
}
123162
#endif /* PWR_WAKEUP_PIN4 */
124163
#ifdef PWR_WAKEUP_PIN5
125-
if (p == SYS_WKUP5) {
164+
if ((p == SYS_WKUP5)
165+
#ifdef PWR_WAKEUP_PIN5_1
166+
|| (p == SYS_WKUP5_1)
167+
#endif
168+
#ifdef PWR_WAKEUP_PIN5_2
169+
|| (p == SYS_WKUP5_2)
170+
#endif
171+
) {
126172
wkup_pin = PWR_WAKEUP_PIN5;
127173
#ifdef PWR_WAKEUP_PIN5_HIGH
128174
if (mode != RISING) {
@@ -132,7 +178,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
132178
}
133179
#endif /* PWR_WAKEUP_PIN5 */
134180
#ifdef PWR_WAKEUP_PIN6
135-
if (p == SYS_WKUP6) {
181+
if ((p == SYS_WKUP6)
182+
#ifdef PWR_WAKEUP_PIN6_1
183+
|| (p == SYS_WKUP6_1)
184+
#endif
185+
#ifdef PWR_WAKEUP_PIN6_2
186+
|| (p == SYS_WKUP6_2)
187+
#endif
188+
) {
136189
wkup_pin = PWR_WAKEUP_PIN6;
137190
#ifdef PWR_WAKEUP_PIN6_HIGH
138191
if (mode != RISING) {
@@ -142,12 +195,26 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
142195
}
143196
#endif /* PWR_WAKEUP_PIN6 */
144197
#ifdef PWR_WAKEUP_PIN7
145-
if (p == SYS_WKUP7) {
198+
if ((p == SYS_WKUP7)
199+
#ifdef PWR_WAKEUP_PIN7_1
200+
|| (p == SYS_WKUP7_1)
201+
#endif
202+
#ifdef PWR_WAKEUP_PIN7_2
203+
|| (p == SYS_WKUP7_2)
204+
#endif
205+
) {
146206
wkup_pin = PWR_WAKEUP_PIN7;
147207
}
148208
#endif /* PWR_WAKEUP_PIN7 */
149209
#ifdef PWR_WAKEUP_PIN8
150-
if (p == SYS_WKUP8) {
210+
if ((p == SYS_WKUP8)
211+
#ifdef PWR_WAKEUP_PIN8_1
212+
|| (p == SYS_WKUP8_1)
213+
#endif
214+
#ifdef PWR_WAKEUP_PIN8_2
215+
|| (p == SYS_WKUP8_2)
216+
#endif
217+
) {
151218
wkup_pin = PWR_WAKEUP_PIN8;
152219
}
153220
#endif /* PWR_WAKEUP_PIN8 */
@@ -191,7 +258,7 @@ void LowPower_stop(serial_t *obj)
191258
{
192259
__disable_irq();
193260

194-
#if defined(UART_IT_WUF) && defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
261+
#if defined(UART_WKUP_SUPPORT)
195262
if (WakeUpUart != NULL) {
196263
HAL_UARTEx_EnableStopMode(WakeUpUart);
197264
}
@@ -201,6 +268,10 @@ void LowPower_stop(serial_t *obj)
201268
/* Enable Ultra low power mode */
202269
HAL_PWREx_EnableUltraLowPower();
203270
#endif
271+
#if defined(PWR_CR1_ULPMEN) || defined(PWR_CR3_ULPMEN)
272+
/* Enable Ultra low power mode */
273+
HAL_PWREx_EnableUltraLowPowerMode();
274+
#endif
204275
#if defined(PWR_CR_FWU)
205276
/* Enable the fast wake up from Ultra low power mode */
206277
HAL_PWREx_EnableFastWakeUp();
@@ -215,10 +286,15 @@ void LowPower_stop(serial_t *obj)
215286
#endif
216287

217288
/* Enter Stop mode */
218-
#if defined(PWR_CPUCR_RETDS_CD) || defined(PWR_CR1_LPMS_STOP2) ||\
219-
defined(PWR_LOWPOWERMODE_STOP2)
220-
221-
if ((WakeUpUart == NULL) || (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)) {
289+
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) \
290+
|| defined(PWR_CR1_LPMS_STOP2) || defined(PWR_LOWPOWERMODE_STOP2) \
291+
|| defined(LL_PWR_STOP2_MODE))
292+
if ((WakeUpUart == NULL)
293+
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)
294+
#ifdef LPUART2_BASE
295+
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART2_BASE)
296+
#endif
297+
) {
222298
// STM32L4xx supports STOP2 mode which halves consumption
223299
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
224300
} else
@@ -229,7 +305,7 @@ void LowPower_stop(serial_t *obj)
229305

230306
/* Exit Stop mode reset clocks */
231307
SystemClock_ConfigFromStop();
232-
#if defined(UART_IT_WUF) && defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
308+
#if defined(UART_WKUP_SUPPORT)
233309
if (WakeUpUart != NULL) {
234310
/* In case of WakeUp from UART, reset its clock source to HSI */
235311
uart_config_lowpower(obj);
@@ -277,7 +353,7 @@ void LowPower_standby()
277353
void LowPower_shutdown()
278354
{
279355
__disable_irq();
280-
#if defined(PWR_LOWPOWERMODE_SHUTDOWN) || defined(PWR_CR1_LPMS_SHUTDOWN)
356+
#if defined(PWR_CR1_LPMS)
281357
/* LSE must be on to use shutdown mode */
282358
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET) {
283359
HAL_PWREx_EnterSHUTDOWNMode();
@@ -299,7 +375,8 @@ void LowPower_shutdown()
299375
*/
300376
void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
301377
{
302-
#if defined(UART_IT_WUF) && defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
378+
#if defined(UART_WKUP_SUPPORT)
379+
#ifdef IS_UART_WAKEUP_SELECTION
303380
UART_WakeUpTypeDef WakeUpSelection;
304381
if (serial == NULL) {
305382
return;
@@ -318,9 +395,11 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
318395
*/
319396
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
320397
HAL_UARTEx_StopModeWakeUpSourceConfig(WakeUpUart, WakeUpSelection);
321-
398+
#endif
399+
#if defined(UART_IT_WUF)
322400
/* Enable the UART Wake UP from STOPx mode Interrupt */
323401
__HAL_UART_ENABLE_IT(WakeUpUart, UART_IT_WUF);
402+
#endif
324403
#else
325404
UNUSED(serial);
326405
#endif

0 commit comments

Comments
 (0)