20
20
21
21
#include "Arduino.h"
22
22
#include "low_power.h"
23
+ #include "stm32yyxx_ll_pwr.h"
23
24
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
26
32
27
33
#ifdef __cplusplus
28
34
extern "C" {
29
35
#endif
30
36
31
- #if defined(UART_IT_WUF ) && defined( HAL_UART_MODULE_ENABLED ) && !defined( HAL_UART_MODULE_ONLY )
37
+ #if defined(UART_WKUP_SUPPORT )
32
38
/* Save UART handler for callback */
33
39
static UART_HandleTypeDef * WakeUpUart = NULL ;
34
40
#endif
@@ -37,6 +43,11 @@ static void (*WakeUpUartCb)(void) = NULL;
37
43
38
44
#if defined(PWR_FLAG_WUF )
39
45
#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
40
51
#endif
41
52
42
53
/**
@@ -82,7 +93,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
82
93
PinName p = digitalPinToPinName (pin );
83
94
if (p != NC ) {
84
95
#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
+ ) {
86
104
wkup_pin = PWR_WAKEUP_PIN1 ;
87
105
#ifdef PWR_WAKEUP_PIN1_HIGH
88
106
if (mode != RISING ) {
@@ -92,7 +110,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
92
110
}
93
111
#endif /* PWR_WAKEUP_PIN1 */
94
112
#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
+ ) {
96
121
wkup_pin = PWR_WAKEUP_PIN2 ;
97
122
#ifdef PWR_WAKEUP_PIN2_HIGH
98
123
if (mode != RISING ) {
@@ -102,7 +127,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
102
127
}
103
128
#endif /* PWR_WAKEUP_PIN2 */
104
129
#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
+ ) {
106
138
wkup_pin = PWR_WAKEUP_PIN3 ;
107
139
#ifdef PWR_WAKEUP_PIN3_HIGH
108
140
if (mode != RISING ) {
@@ -112,7 +144,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
112
144
}
113
145
#endif /* PWR_WAKEUP_PIN3 */
114
146
#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
+ ) {
116
155
wkup_pin = PWR_WAKEUP_PIN4 ;
117
156
#ifdef PWR_WAKEUP_PIN4_HIGH
118
157
if (mode != RISING ) {
@@ -122,7 +161,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
122
161
}
123
162
#endif /* PWR_WAKEUP_PIN4 */
124
163
#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
+ ) {
126
172
wkup_pin = PWR_WAKEUP_PIN5 ;
127
173
#ifdef PWR_WAKEUP_PIN5_HIGH
128
174
if (mode != RISING ) {
@@ -132,7 +178,14 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
132
178
}
133
179
#endif /* PWR_WAKEUP_PIN5 */
134
180
#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
+ ) {
136
189
wkup_pin = PWR_WAKEUP_PIN6 ;
137
190
#ifdef PWR_WAKEUP_PIN6_HIGH
138
191
if (mode != RISING ) {
@@ -142,12 +195,26 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
142
195
}
143
196
#endif /* PWR_WAKEUP_PIN6 */
144
197
#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
+ ) {
146
206
wkup_pin = PWR_WAKEUP_PIN7 ;
147
207
}
148
208
#endif /* PWR_WAKEUP_PIN7 */
149
209
#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
+ ) {
151
218
wkup_pin = PWR_WAKEUP_PIN8 ;
152
219
}
153
220
#endif /* PWR_WAKEUP_PIN8 */
@@ -191,7 +258,7 @@ void LowPower_stop(serial_t *obj)
191
258
{
192
259
__disable_irq ();
193
260
194
- #if defined(UART_IT_WUF ) && defined( HAL_UART_MODULE_ENABLED ) && !defined( HAL_UART_MODULE_ONLY )
261
+ #if defined(UART_WKUP_SUPPORT )
195
262
if (WakeUpUart != NULL ) {
196
263
HAL_UARTEx_EnableStopMode (WakeUpUart );
197
264
}
@@ -201,6 +268,10 @@ void LowPower_stop(serial_t *obj)
201
268
/* Enable Ultra low power mode */
202
269
HAL_PWREx_EnableUltraLowPower ();
203
270
#endif
271
+ #if defined(PWR_CR1_ULPMEN ) || defined(PWR_CR3_ULPMEN )
272
+ /* Enable Ultra low power mode */
273
+ HAL_PWREx_EnableUltraLowPowerMode ();
274
+ #endif
204
275
#if defined(PWR_CR_FWU )
205
276
/* Enable the fast wake up from Ultra low power mode */
206
277
HAL_PWREx_EnableFastWakeUp ();
@@ -215,10 +286,15 @@ void LowPower_stop(serial_t *obj)
215
286
#endif
216
287
217
288
/* 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
+ ) {
222
298
// STM32L4xx supports STOP2 mode which halves consumption
223
299
HAL_PWREx_EnterSTOP2Mode (PWR_STOPENTRY_WFI );
224
300
} else
@@ -229,7 +305,7 @@ void LowPower_stop(serial_t *obj)
229
305
230
306
/* Exit Stop mode reset clocks */
231
307
SystemClock_ConfigFromStop ();
232
- #if defined(UART_IT_WUF ) && defined( HAL_UART_MODULE_ENABLED ) && !defined( HAL_UART_MODULE_ONLY )
308
+ #if defined(UART_WKUP_SUPPORT )
233
309
if (WakeUpUart != NULL ) {
234
310
/* In case of WakeUp from UART, reset its clock source to HSI */
235
311
uart_config_lowpower (obj );
@@ -277,7 +353,7 @@ void LowPower_standby()
277
353
void LowPower_shutdown ()
278
354
{
279
355
__disable_irq ();
280
- #if defined(PWR_LOWPOWERMODE_SHUTDOWN ) || defined( PWR_CR1_LPMS_SHUTDOWN )
356
+ #if defined(PWR_CR1_LPMS )
281
357
/* LSE must be on to use shutdown mode */
282
358
if (__HAL_RCC_GET_FLAG (RCC_FLAG_LSERDY ) == SET ) {
283
359
HAL_PWREx_EnterSHUTDOWNMode ();
@@ -299,7 +375,8 @@ void LowPower_shutdown()
299
375
*/
300
376
void LowPower_EnableWakeUpUart (serial_t * serial , void (* FuncPtr )(void ))
301
377
{
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
303
380
UART_WakeUpTypeDef WakeUpSelection ;
304
381
if (serial == NULL ) {
305
382
return ;
@@ -318,9 +395,11 @@ void LowPower_EnableWakeUpUart(serial_t *serial, void (*FuncPtr)(void))
318
395
*/
319
396
WakeUpSelection .WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY ;
320
397
HAL_UARTEx_StopModeWakeUpSourceConfig (WakeUpUart , WakeUpSelection );
321
-
398
+ #endif
399
+ #if defined(UART_IT_WUF )
322
400
/* Enable the UART Wake UP from STOPx mode Interrupt */
323
401
__HAL_UART_ENABLE_IT (WakeUpUart , UART_IT_WUF );
402
+ #endif
324
403
#else
325
404
UNUSED (serial );
326
405
#endif
0 commit comments