@@ -40,6 +40,118 @@ static UART_HandleTypeDef *WakeUpUart = NULL;
40
40
/* Save callback pointer */
41
41
static void (* WakeUpUartCb )(void ) = NULL ;
42
42
43
+ #if defined(PWR_WAKEUP_SELECT_0 ) || defined(PWR_WAKEUP1_SOURCE_SELECTION_0 )
44
+ typedef struct {
45
+ PinName pin ;
46
+ uint32_t wkup_pin ;
47
+ uint32_t selection ;
48
+ #if defined(PWR_WAKEUP1_SOURCE_SELECTION_0 )
49
+ uint32_t low ;
50
+ #endif
51
+ } WakePinSel ;
52
+
53
+ const WakePinSel WakeupPinSel [] = {
54
+ #if defined(PWR_WAKEUP_SELECT_0 )
55
+ /* PWR_WAKEUP_SELECT_0 */
56
+ {PA_0 , PWR_WAKEUP_LINE1 , PWR_WAKEUP_SELECT_0 },
57
+ {PA_4 , PWR_WAKEUP_LINE2 , PWR_WAKEUP_SELECT_0 },
58
+ {PE_6 , PWR_WAKEUP_LINE3 , PWR_WAKEUP_SELECT_0 },
59
+ {PA_2 , PWR_WAKEUP_LINE4 , PWR_WAKEUP_SELECT_0 },
60
+ {PC_5 , PWR_WAKEUP_LINE5 , PWR_WAKEUP_SELECT_0 },
61
+ {PB_5 , PWR_WAKEUP_LINE6 , PWR_WAKEUP_SELECT_0 },
62
+ {PB_15 , PWR_WAKEUP_LINE7 , PWR_WAKEUP_SELECT_0 },
63
+ /* PWR_WAKEUP_SELECT_1 */
64
+ {PB_2 , PWR_WAKEUP_LINE1 , PWR_WAKEUP_SELECT_1 },
65
+ {PC_13 , PWR_WAKEUP_LINE2 , PWR_WAKEUP_SELECT_1 },
66
+ {PA_1 , PWR_WAKEUP_LINE3 , PWR_WAKEUP_SELECT_1 },
67
+ {PB_1 , PWR_WAKEUP_LINE4 , PWR_WAKEUP_SELECT_1 },
68
+ {PA_3 , PWR_WAKEUP_LINE5 , PWR_WAKEUP_SELECT_1 },
69
+ {PA_5 , PWR_WAKEUP_LINE6 , PWR_WAKEUP_SELECT_1 },
70
+ {PA_6 , PWR_WAKEUP_LINE7 , PWR_WAKEUP_SELECT_1 },
71
+ {PA_7 , PWR_WAKEUP_LINE8 , PWR_WAKEUP_SELECT_1 },
72
+ /* PWR_WAKEUP_SELECT_2 */
73
+ {PE_4 , PWR_WAKEUP_LINE1 , PWR_WAKEUP_SELECT_2 },
74
+ {PE_5 , PWR_WAKEUP_LINE2 , PWR_WAKEUP_SELECT_2 },
75
+ {PB_6 , PWR_WAKEUP_LINE3 , PWR_WAKEUP_SELECT_2 },
76
+ {PB_7 , PWR_WAKEUP_LINE4 , PWR_WAKEUP_SELECT_2 },
77
+ {PB_8 , PWR_WAKEUP_LINE5 , PWR_WAKEUP_SELECT_2 },
78
+ {PE_7 , PWR_WAKEUP_LINE6 , PWR_WAKEUP_SELECT_2 },
79
+ {PE_8 , PWR_WAKEUP_LINE7 , PWR_WAKEUP_SELECT_2 },
80
+ {PB_10 , PWR_WAKEUP_LINE8 , PWR_WAKEUP_SELECT_2 },
81
+ {NC , 0 , 0 }
82
+ #else /* PWR_WAKEUP_SELECT_0 */
83
+ /* PWR_WAKEUPx_SOURCE_SELECTION_0 */
84
+ {PA_0 , PWR_WAKEUP_PIN1 , PWR_WAKEUP1_SOURCE_SELECTION_0 , PWR_WAKEUP1_POLARITY_LOW },
85
+ #if defined(PWR_WAKEUP2_SOURCE_SELECTION_0 )
86
+ {PA_4 , PWR_WAKEUP_PIN2 , PWR_WAKEUP2_SOURCE_SELECTION_0 , PWR_WAKEUP2_POLARITY_LOW },
87
+ #endif
88
+ #if defined(PWR_WAKEUP3_SOURCE_SELECTION_0 )
89
+ {PE_6 , PWR_WAKEUP_PIN3 , PWR_WAKEUP3_SOURCE_SELECTION_0 , PWR_WAKEUP3_POLARITY_LOW },
90
+ #endif
91
+ {PA_2 , PWR_WAKEUP_PIN4 , PWR_WAKEUP4_SOURCE_SELECTION_0 , PWR_WAKEUP4_POLARITY_LOW },
92
+ #if defined(PWR_WAKEUP5_SOURCE_SELECTION_0 )
93
+ {PC_5 , PWR_WAKEUP_PIN5 , PWR_WAKEUP5_SOURCE_SELECTION_0 , PWR_WAKEUP5_POLARITY_LOW },
94
+ #endif
95
+ #if defined(PWR_WAKEUP8_SOURCE_SELECTION_0 )
96
+ /* STM32U5xx */
97
+ {PB_5 , PWR_WAKEUP_PIN6 , PWR_WAKEUP6_SOURCE_SELECTION_0 , PWR_WAKEUP6_POLARITY_LOW },
98
+ {PB_15 , PWR_WAKEUP_PIN7 , PWR_WAKEUP7_SOURCE_SELECTION_0 , PWR_WAKEUP7_POLARITY_LOW },
99
+ {PF_2 , PWR_WAKEUP_PIN8 , PWR_WAKEUP8_SOURCE_SELECTION_0 , PWR_WAKEUP8_POLARITY_LOW },
100
+ #else
101
+ /* STM32WBAxx */
102
+ {PA_12 , PWR_WAKEUP_PIN6 , PWR_WAKEUP6_SOURCE_SELECTION_0 , PWR_WAKEUP6_POLARITY_LOW },
103
+ {PB_14 , PWR_WAKEUP_PIN7 , PWR_WAKEUP7_SOURCE_SELECTION_0 , PWR_WAKEUP7_POLARITY_LOW },
104
+ #endif
105
+ /* PWR_WAKEUPx_SOURCE_SELECTION_1 */
106
+ #if defined(PWR_WAKEUP1_SOURCE_SELECTION_1 )
107
+ {PB_2 , PWR_WAKEUP_PIN1 , PWR_WAKEUP1_SOURCE_SELECTION_1 , PWR_WAKEUP1_POLARITY_LOW },
108
+ #endif
109
+ #if defined(PWR_WAKEUP2_SOURCE_SELECTION_1 )
110
+ {PC_13 , PWR_WAKEUP_PIN2 , PWR_WAKEUP2_SOURCE_SELECTION_1 , PWR_WAKEUP2_POLARITY_LOW },
111
+ #endif
112
+ {PA_1 , PWR_WAKEUP_PIN3 , PWR_WAKEUP3_SOURCE_SELECTION_1 , PWR_WAKEUP3_POLARITY_LOW },
113
+ #if defined(PWR_WAKEUP4_SOURCE_SELECTION_1 )
114
+ {PB_1 , PWR_WAKEUP_PIN4 , PWR_WAKEUP4_SOURCE_SELECTION_1 , PWR_WAKEUP4_POLARITY_LOW },
115
+ #endif
116
+ #if defined(PWR_WAKEUP5_SOURCE_SELECTION_1 )
117
+ {PA_3 , PWR_WAKEUP_PIN5 , PWR_WAKEUP5_SOURCE_SELECTION_1 , PWR_WAKEUP5_POLARITY_LOW },
118
+ #endif
119
+ {PA_5 , PWR_WAKEUP_PIN6 , PWR_WAKEUP6_SOURCE_SELECTION_1 , PWR_WAKEUP6_POLARITY_LOW },
120
+ {PA_6 , PWR_WAKEUP_PIN7 , PWR_WAKEUP7_SOURCE_SELECTION_1 , PWR_WAKEUP7_POLARITY_LOW },
121
+ {PA_7 , PWR_WAKEUP_PIN8 , PWR_WAKEUP8_SOURCE_SELECTION_1 , PWR_WAKEUP8_POLARITY_LOW },
122
+ /* PWR_WAKEUPx_SOURCE_SELECTION_2 */
123
+ #if defined(PWR_WAKEUP1_SOURCE_SELECTION_2 )
124
+ {PE_4 , PWR_WAKEUP_PIN1 , PWR_WAKEUP1_SOURCE_SELECTION_2 , PWR_WAKEUP1_POLARITY_LOW },
125
+ #endif
126
+ #if defined(PWR_WAKEUP2_SOURCE_SELECTION_2 )
127
+ {PE_5 , PWR_WAKEUP_PIN2 , PWR_WAKEUP2_SOURCE_SELECTION_2 , PWR_WAKEUP2_POLARITY_LOW },
128
+ #endif
129
+ #if defined(PWR_WAKEUP3_SOURCE_SELECTION_2 )
130
+ {PB_6 , PWR_WAKEUP_PIN3 , PWR_WAKEUP3_SOURCE_SELECTION_2 , PWR_WAKEUP3_POLARITY_LOW },
131
+ #endif
132
+ #if defined(PWR_WAKEUP4_SOURCE_SELECTION_2 )
133
+ {PB_7 , PWR_WAKEUP_PIN4 , PWR_WAKEUP4_SOURCE_SELECTION_2 , PWR_WAKEUP4_POLARITY_LOW }, /* Only for STM32U5 */
134
+ #endif
135
+ #if defined(PWR_WAKEUP5_SOURCE_SELECTION_2 )
136
+ {PB_7 , PWR_WAKEUP_PIN5 , PWR_WAKEUP5_SOURCE_SELECTION_2 , PWR_WAKEUP5_POLARITY_LOW }, /* Only for STM32WBA */
137
+ {PB_8 , PWR_WAKEUP_PIN5 , PWR_WAKEUP5_SOURCE_SELECTION_2 , PWR_WAKEUP5_POLARITY_LOW }, /* Only for STM32U5 */
138
+ #endif
139
+ #if defined(PWR_WAKEUP6_SOURCE_SELECTION_2 )
140
+ {PE_7 , PWR_WAKEUP_PIN6 , PWR_WAKEUP6_SOURCE_SELECTION_2 , PWR_WAKEUP6_POLARITY_LOW },
141
+ #endif
142
+ #if defined(PWR_WAKEUP7_SOURCE_SELECTION_2 )
143
+ {PE_8 , PWR_WAKEUP_PIN7 , PWR_WAKEUP7_SOURCE_SELECTION_2 , PWR_WAKEUP7_POLARITY_LOW },
144
+ #endif
145
+ #if defined(PWR_WAKEUP8_SOURCE_SELECTION_2 )
146
+ {PB_9 , PWR_WAKEUP_PIN8 , PWR_WAKEUP8_SOURCE_SELECTION_2 , PWR_WAKEUP8_POLARITY_LOW }, /* Only for STM32WBA */
147
+ {PB_10 , PWR_WAKEUP_PIN8 , PWR_WAKEUP8_SOURCE_SELECTION_2 , PWR_WAKEUP8_POLARITY_LOW }, /* Only for STM32U5 */
148
+ #endif
149
+ {NC , 0 , 0 , 0 }
150
+ #endif /* PWR_WAKEUP_SELECT_0 */
151
+ };
152
+ #endif /* PWR_WAKEUP_SELECT_0 || PWR_WAKEUP1_SOURCE_SELECTION_0 */
153
+
154
+
43
155
#if defined(PWR_FLAG_WUF )
44
156
#define PWR_FLAG_WU PWR_FLAG_WUF
45
157
#elif defined(PWR_WAKEUP_ALL_FLAG )
@@ -88,21 +200,15 @@ void LowPower_init()
88
200
*/
89
201
void LowPower_EnableWakeUpPin (uint32_t pin , uint32_t mode )
90
202
{
203
+ PinName p = digitalPinToPinName (pin );
204
+ #if !defined(PWR_WAKEUP_SELECT_0 ) && !defined(PWR_WAKEUP1_SOURCE_SELECTION_0 )
91
205
#if !defined(PWR_WAKEUP_PIN1_HIGH )
92
206
UNUSED (mode );
93
207
#endif
94
208
uint32_t wkup_pin = 0 ;
95
- PinName p = digitalPinToPinName (pin );
96
209
if (p != NC ) {
97
- #ifdef PWR_WAKEUP_PIN1
98
- if ((p == SYS_WKUP1 )
99
- #ifdef PWR_WAKEUP_PIN1_1
100
- || (p == SYS_WKUP1_1 )
101
- #endif
102
- #ifdef PWR_WAKEUP_PIN1_2
103
- || (p == SYS_WKUP1_2 )
104
- #endif
105
- ) {
210
+ #if defined(PWR_WAKEUP_PIN1 )
211
+ if (p == SYS_WKUP1 ) {
106
212
wkup_pin = PWR_WAKEUP_PIN1 ;
107
213
#ifdef PWR_WAKEUP_PIN1_HIGH
108
214
if (mode != RISING ) {
@@ -112,14 +218,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
112
218
}
113
219
#endif /* PWR_WAKEUP_PIN1 */
114
220
#ifdef PWR_WAKEUP_PIN2
115
- if ((p == SYS_WKUP2 )
116
- #ifdef PWR_WAKEUP_PIN2_1
117
- || (p == SYS_WKUP2_1 )
118
- #endif
119
- #ifdef PWR_WAKEUP_PIN2_2
120
- || (p == SYS_WKUP2_2 )
121
- #endif
122
- ) {
221
+ if (p == SYS_WKUP2 ) {
123
222
wkup_pin = PWR_WAKEUP_PIN2 ;
124
223
#ifdef PWR_WAKEUP_PIN2_HIGH
125
224
if (mode != RISING ) {
@@ -129,14 +228,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
129
228
}
130
229
#endif /* PWR_WAKEUP_PIN2 */
131
230
#ifdef PWR_WAKEUP_PIN3
132
- if ((p == SYS_WKUP3 )
133
- #ifdef PWR_WAKEUP_PIN3_1
134
- || (p == SYS_WKUP3_1 )
135
- #endif
136
- #ifdef PWR_WAKEUP_PIN3_2
137
- || (p == SYS_WKUP3_2 )
138
- #endif
139
- ) {
231
+ if (p == SYS_WKUP3 ) {
140
232
wkup_pin = PWR_WAKEUP_PIN3 ;
141
233
#ifdef PWR_WAKEUP_PIN3_HIGH
142
234
if (mode != RISING ) {
@@ -146,14 +238,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
146
238
}
147
239
#endif /* PWR_WAKEUP_PIN3 */
148
240
#ifdef PWR_WAKEUP_PIN4
149
- if ((p == SYS_WKUP4 )
150
- #ifdef PWR_WAKEUP_PIN4_1
151
- || (p == SYS_WKUP4_1 )
152
- #endif
153
- #ifdef PWR_WAKEUP_PIN4_2
154
- || (p == SYS_WKUP4_2 )
155
- #endif
156
- ) {
241
+ if (p == SYS_WKUP4 ) {
157
242
wkup_pin = PWR_WAKEUP_PIN4 ;
158
243
#ifdef PWR_WAKEUP_PIN4_HIGH
159
244
if (mode != RISING ) {
@@ -163,14 +248,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
163
248
}
164
249
#endif /* PWR_WAKEUP_PIN4 */
165
250
#ifdef PWR_WAKEUP_PIN5
166
- if ((p == SYS_WKUP5 )
167
- #ifdef PWR_WAKEUP_PIN5_1
168
- || (p == SYS_WKUP5_1 )
169
- #endif
170
- #ifdef PWR_WAKEUP_PIN5_2
171
- || (p == SYS_WKUP5_2 )
172
- #endif
173
- ) {
251
+ if (p == SYS_WKUP5 ) {
174
252
wkup_pin = PWR_WAKEUP_PIN5 ;
175
253
#ifdef PWR_WAKEUP_PIN5_HIGH
176
254
if (mode != RISING ) {
@@ -180,14 +258,7 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
180
258
}
181
259
#endif /* PWR_WAKEUP_PIN5 */
182
260
#ifdef PWR_WAKEUP_PIN6
183
- if ((p == SYS_WKUP6 )
184
- #ifdef PWR_WAKEUP_PIN6_1
185
- || (p == SYS_WKUP6_1 )
186
- #endif
187
- #ifdef PWR_WAKEUP_PIN6_2
188
- || (p == SYS_WKUP6_2 )
189
- #endif
190
- ) {
261
+ if (p == SYS_WKUP6 ) {
191
262
wkup_pin = PWR_WAKEUP_PIN6 ;
192
263
#ifdef PWR_WAKEUP_PIN6_HIGH
193
264
if (mode != RISING ) {
@@ -197,33 +268,66 @@ void LowPower_EnableWakeUpPin(uint32_t pin, uint32_t mode)
197
268
}
198
269
#endif /* PWR_WAKEUP_PIN6 */
199
270
#ifdef PWR_WAKEUP_PIN7
200
- if ((p == SYS_WKUP7 )
201
- #ifdef PWR_WAKEUP_PIN7_1
202
- || (p == SYS_WKUP7_1 )
203
- #endif
204
- #ifdef PWR_WAKEUP_PIN7_2
205
- || (p == SYS_WKUP7_2 )
206
- #endif
207
- ) {
271
+ if (p == SYS_WKUP7 ) {
208
272
wkup_pin = PWR_WAKEUP_PIN7 ;
273
+ #ifdef PWR_WAKEUP_PIN7_HIGH
274
+ if (mode != RISING ) {
275
+ wkup_pin = PWR_WAKEUP_PIN7_LOW ;
276
+ }
277
+ #endif
209
278
}
210
279
#endif /* PWR_WAKEUP_PIN7 */
211
280
#ifdef PWR_WAKEUP_PIN8
212
- if ((p == SYS_WKUP8 )
213
- #ifdef PWR_WAKEUP_PIN8_1
214
- || (p == SYS_WKUP8_1 )
215
- #endif
216
- #ifdef PWR_WAKEUP_PIN8_2
217
- || (p == SYS_WKUP8_2 )
218
- #endif
219
- ) {
281
+ if (p == SYS_WKUP8 ) {
220
282
wkup_pin = PWR_WAKEUP_PIN8 ;
283
+ #ifdef PWR_WAKEUP_PIN8_HIGH
284
+ if (mode != RISING ) {
285
+ wkup_pin = PWR_WAKEUP_PIN8_LOW ;
286
+ }
287
+ #endif
221
288
}
222
289
#endif /* PWR_WAKEUP_PIN8 */
223
290
if (IS_PWR_WAKEUP_PIN (wkup_pin )) {
224
291
HAL_PWR_EnableWakeUpPin (wkup_pin );
225
292
}
226
293
}
294
+ #else
295
+ /* Two cases:
296
+ * 1- STM32U5 and STM32WBA provides a compatible way to configure
297
+ * the wakeup pin using HAL_PWR_EnableWakeUpPin but only selection 0
298
+ * pins are managed.
299
+ * 2- STM32U3 uses HAL_PWR_EnableWakeUpLine.
300
+ */
301
+ /* First find index of the pin if valid */
302
+ WakePinSel * WakeupPinSel_idx = (WakePinSel * ) WakeupPinSel ;
303
+
304
+ /* Read through PinMapAnalogSwitch array */
305
+ while (WakeupPinSel_idx -> pin != NC ) {
306
+ /* Check whether pin is or is associated to dualpad Analog Input */
307
+ if (WakeupPinSel_idx -> pin == p ) {
308
+ break ;
309
+ }
310
+ WakeupPinSel_idx ++ ;
311
+ }
312
+ if (WakeupPinSel_idx -> pin != NC ) {
313
+ #if defined(PWR_WAKEUP1_SOURCE_SELECTION_0 )
314
+ uint32_t wkup_pin = WakeupPinSel_idx -> wkup_pin | WakeupPinSel_idx -> selection ;
315
+ if (mode != RISING ) {
316
+ wkup_pin |= PWR_WAKEUP1_POLARITY_LOW ;
317
+ }
318
+ if (IS_PWR_WAKEUP_PIN (wkup_pin )) {
319
+ HAL_PWR_EnableWakeUpPin (wkup_pin );
320
+ }
321
+ #else
322
+ if (IS_PWR_WAKEUP_LINE (WakeupPinSel_idx -> wkup_pin )) {
323
+ HAL_PWR_EnableWakeUpLine (WakeupPinSel_idx -> wkup_pin , WakeupPinSel_idx -> selection , (mode != RISING ) ? PWR_WAKEUP_POLARITY_LOW : PWR_WAKEUP_POLARITY_HIGH );
324
+ /* Enable the NVIC for Wake-up pin */
325
+ HAL_NVIC_SetPriority (PWR_IRQn , 0 , 0x00 );
326
+ HAL_NVIC_EnableIRQ (PWR_IRQn );
327
+ }
328
+ #endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 */
329
+ }
330
+ #endif /* !PWR_WAKEUP_SELECT_0 && !PWR_WAKEUP1_SOURCE_SELECTION_0 */
227
331
}
228
332
229
333
#if defined(PWR_CSR_REGLPF )
0 commit comments