-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathlow_power.c
More file actions
1033 lines (978 loc) · 30.7 KB
/
low_power.c
File metadata and controls
1033 lines (978 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
******************************************************************************
* @file LowPower.c
* @author Frederic Pillon
* @brief Provides a Low Power interface
*
******************************************************************************
* @attention
*
* Copyright (c) 2020-2021, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#include "low_power.h"
#include "stm32yyxx_ll_cortex.h"
#include "stm32yyxx_ll_pwr.h"
#if defined(HAL_PWR_MODULE_ENABLED) && !defined(HAL_PWR_MODULE_ONLY)
#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) \
&& (defined(UART_IT_WUF) || defined(LPUART1_BASE))
#define UART_WKUP_SUPPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(UART_WKUP_SUPPORT)
/* Save UART handler for callback */
static UART_HandleTypeDef *WakeUpUart = NULL;
#endif
/* Save callback pointer */
static void (*WakeUpUartCb)(void) = NULL;
#if defined(PWR_WAKEUP_SELECT_0) || defined(PWR_WAKEUP1_SOURCE_SELECTION_0)
typedef struct {
PinName pin;
uint32_t wkup_pin;
uint32_t selection;
#if defined(PWR_WAKEUP1_SOURCE_SELECTION_0)
uint32_t low;
#endif
} WakePinSel;
const WakePinSel WakeupPinSel[] = {
#if defined(PWR_WAKEUP_SELECT_0)
/* PWR_WAKEUP_SELECT_0 */
{PA_0, PWR_WAKEUP_LINE1, PWR_WAKEUP_SELECT_0},
{PA_4, PWR_WAKEUP_LINE2, PWR_WAKEUP_SELECT_0},
{PE_6, PWR_WAKEUP_LINE3, PWR_WAKEUP_SELECT_0},
{PA_2, PWR_WAKEUP_LINE4, PWR_WAKEUP_SELECT_0},
{PC_5, PWR_WAKEUP_LINE5, PWR_WAKEUP_SELECT_0},
{PB_5, PWR_WAKEUP_LINE6, PWR_WAKEUP_SELECT_0},
{PB_15, PWR_WAKEUP_LINE7, PWR_WAKEUP_SELECT_0},
/* PWR_WAKEUP_SELECT_1 */
{PB_2, PWR_WAKEUP_LINE1, PWR_WAKEUP_SELECT_1},
{PC_13, PWR_WAKEUP_LINE2, PWR_WAKEUP_SELECT_1},
{PA_1, PWR_WAKEUP_LINE3, PWR_WAKEUP_SELECT_1},
{PB_1, PWR_WAKEUP_LINE4, PWR_WAKEUP_SELECT_1},
{PA_3, PWR_WAKEUP_LINE5, PWR_WAKEUP_SELECT_1},
{PA_5, PWR_WAKEUP_LINE6, PWR_WAKEUP_SELECT_1},
{PA_6, PWR_WAKEUP_LINE7, PWR_WAKEUP_SELECT_1},
{PA_7, PWR_WAKEUP_LINE8, PWR_WAKEUP_SELECT_1},
/* PWR_WAKEUP_SELECT_2 */
{PE_4, PWR_WAKEUP_LINE1, PWR_WAKEUP_SELECT_2},
{PE_5, PWR_WAKEUP_LINE2, PWR_WAKEUP_SELECT_2},
{PB_6, PWR_WAKEUP_LINE3, PWR_WAKEUP_SELECT_2},
{PB_7, PWR_WAKEUP_LINE4, PWR_WAKEUP_SELECT_2},
{PB_8, PWR_WAKEUP_LINE5, PWR_WAKEUP_SELECT_2},
{PE_7, PWR_WAKEUP_LINE6, PWR_WAKEUP_SELECT_2},
{PE_8, PWR_WAKEUP_LINE7, PWR_WAKEUP_SELECT_2},
{PB_10, PWR_WAKEUP_LINE8, PWR_WAKEUP_SELECT_2},
{NC, 0, 0}
#else /* PWR_WAKEUP_SELECT_0 */
/* PWR_WAKEUPx_SOURCE_SELECTION_0 */
{PA_0, PWR_WAKEUP_PIN1, PWR_WAKEUP1_SOURCE_SELECTION_0, PWR_WAKEUP1_POLARITY_LOW},
#if defined(PWR_WAKEUP2_SOURCE_SELECTION_0)
{PA_4, PWR_WAKEUP_PIN2, PWR_WAKEUP2_SOURCE_SELECTION_0, PWR_WAKEUP2_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP3_SOURCE_SELECTION_0)
{PE_6, PWR_WAKEUP_PIN3, PWR_WAKEUP3_SOURCE_SELECTION_0, PWR_WAKEUP3_POLARITY_LOW},
#endif
{PA_2, PWR_WAKEUP_PIN4, PWR_WAKEUP4_SOURCE_SELECTION_0, PWR_WAKEUP4_POLARITY_LOW},
#if defined(PWR_WAKEUP5_SOURCE_SELECTION_0)
{PC_5, PWR_WAKEUP_PIN5, PWR_WAKEUP5_SOURCE_SELECTION_0, PWR_WAKEUP5_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP8_SOURCE_SELECTION_0)
/* STM32U5xx */
{PB_5, PWR_WAKEUP_PIN6, PWR_WAKEUP6_SOURCE_SELECTION_0, PWR_WAKEUP6_POLARITY_LOW},
{PB_15, PWR_WAKEUP_PIN7, PWR_WAKEUP7_SOURCE_SELECTION_0, PWR_WAKEUP7_POLARITY_LOW},
{PF_2, PWR_WAKEUP_PIN8, PWR_WAKEUP8_SOURCE_SELECTION_0, PWR_WAKEUP8_POLARITY_LOW},
#else
/* STM32WBAxx */
{PA_12, PWR_WAKEUP_PIN6, PWR_WAKEUP6_SOURCE_SELECTION_0, PWR_WAKEUP6_POLARITY_LOW},
{PB_14, PWR_WAKEUP_PIN7, PWR_WAKEUP7_SOURCE_SELECTION_0, PWR_WAKEUP7_POLARITY_LOW},
#endif
/* PWR_WAKEUPx_SOURCE_SELECTION_1 */
#if defined(PWR_WAKEUP1_SOURCE_SELECTION_1)
{PB_2, PWR_WAKEUP_PIN1, PWR_WAKEUP1_SOURCE_SELECTION_1, PWR_WAKEUP1_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP2_SOURCE_SELECTION_1)
{PC_13, PWR_WAKEUP_PIN2, PWR_WAKEUP2_SOURCE_SELECTION_1, PWR_WAKEUP2_POLARITY_LOW},
#endif
{PA_1, PWR_WAKEUP_PIN3, PWR_WAKEUP3_SOURCE_SELECTION_1, PWR_WAKEUP3_POLARITY_LOW},
#if defined(PWR_WAKEUP4_SOURCE_SELECTION_1)
{PB_1, PWR_WAKEUP_PIN4, PWR_WAKEUP4_SOURCE_SELECTION_1, PWR_WAKEUP4_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP5_SOURCE_SELECTION_1)
{PA_3, PWR_WAKEUP_PIN5, PWR_WAKEUP5_SOURCE_SELECTION_1, PWR_WAKEUP5_POLARITY_LOW},
#endif
{PA_5, PWR_WAKEUP_PIN6, PWR_WAKEUP6_SOURCE_SELECTION_1, PWR_WAKEUP6_POLARITY_LOW},
{PA_6, PWR_WAKEUP_PIN7, PWR_WAKEUP7_SOURCE_SELECTION_1, PWR_WAKEUP7_POLARITY_LOW},
{PA_7, PWR_WAKEUP_PIN8, PWR_WAKEUP8_SOURCE_SELECTION_1, PWR_WAKEUP8_POLARITY_LOW},
/* PWR_WAKEUPx_SOURCE_SELECTION_2 */
#if defined(PWR_WAKEUP1_SOURCE_SELECTION_2)
{PE_4, PWR_WAKEUP_PIN1, PWR_WAKEUP1_SOURCE_SELECTION_2, PWR_WAKEUP1_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP2_SOURCE_SELECTION_2)
{PE_5, PWR_WAKEUP_PIN2, PWR_WAKEUP2_SOURCE_SELECTION_2, PWR_WAKEUP2_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP3_SOURCE_SELECTION_2)
{PB_6, PWR_WAKEUP_PIN3, PWR_WAKEUP3_SOURCE_SELECTION_2, PWR_WAKEUP3_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP4_SOURCE_SELECTION_2)
{PB_7, PWR_WAKEUP_PIN4, PWR_WAKEUP4_SOURCE_SELECTION_2, PWR_WAKEUP4_POLARITY_LOW}, /* Only for STM32U5 */
#endif
#if defined(PWR_WAKEUP5_SOURCE_SELECTION_2)
{PB_7, PWR_WAKEUP_PIN5, PWR_WAKEUP5_SOURCE_SELECTION_2, PWR_WAKEUP5_POLARITY_LOW}, /* Only for STM32WBA */
{PB_8, PWR_WAKEUP_PIN5, PWR_WAKEUP5_SOURCE_SELECTION_2, PWR_WAKEUP5_POLARITY_LOW}, /* Only for STM32U5 */
#endif
#if defined(PWR_WAKEUP6_SOURCE_SELECTION_2)
{PE_7, PWR_WAKEUP_PIN6, PWR_WAKEUP6_SOURCE_SELECTION_2, PWR_WAKEUP6_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP7_SOURCE_SELECTION_2)
{PE_8, PWR_WAKEUP_PIN7, PWR_WAKEUP7_SOURCE_SELECTION_2, PWR_WAKEUP7_POLARITY_LOW},
#endif
#if defined(PWR_WAKEUP8_SOURCE_SELECTION_2)
{PB_9, PWR_WAKEUP_PIN8, PWR_WAKEUP8_SOURCE_SELECTION_2, PWR_WAKEUP8_POLARITY_LOW}, /* Only for STM32WBA */
{PB_10, PWR_WAKEUP_PIN8, PWR_WAKEUP8_SOURCE_SELECTION_2, PWR_WAKEUP8_POLARITY_LOW}, /* Only for STM32U5 */
#endif
{NC, 0, 0, 0}
#endif /* PWR_WAKEUP_SELECT_0 */
};
#endif /* PWR_WAKEUP_SELECT_0 || PWR_WAKEUP1_SOURCE_SELECTION_0 */
#if defined(PWR_FLAG_WUF)
#define PWR_FLAG_WU PWR_FLAG_WUF
#elif defined(PWR_WAKEUP_ALL_FLAG)
#define PWR_FLAG_WU PWR_WAKEUP_ALL_FLAG
#elif defined(PWR_WU_FLAG_ALL)
#define PWR_FLAG_WU PWR_WU_FLAG_ALL
#endif
#if defined(PWR_FLAG_SBF)
#define PWR_FLAG_SB PWR_FLAG_SBF
#endif
/**
* @brief Initialize low power mode
* @param None
* @retval None
*/
void LowPower_init()
{
#if defined(__HAL_RCC_PWR_CLK_ENABLE)
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
#endif
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP)
/* Allow access to Backup domain */
HAL_PWR_EnableBkUpAccess();
#endif
#ifdef __HAL_RCC_WAKEUPSTOP_CLK_CONFIG
/* Ensure that HSI is wake-up system clock */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
#endif
#ifdef PWR_FLAG_SB
/* Check if the system was resumed from StandBy mode */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
}
#endif
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
}
/**
* @brief Configure a pin as wakeup source if compatible.
* @param pin: pin to configure
* @param mode: pin mode (edge or state). The configuration have to be compatible.
* @retval None
*/
void LowPower_EnableWakeUpPin(pin_size_t pin, PinStatus mode)
{
PinName p = digitalPinToPinName(pin);
#if defined(PWR_WAKEUP_SELECT_0) || defined(PWR_WAKEUP1_SOURCE_SELECTION_0)
/* Two cases:
* 1- STM32U5 and STM32WBA provides a compatible way to configure
* the wakeup pin using HAL_PWR_EnableWakeUpPin but only selection 0
* pins are managed.
* 2- STM32U3 uses HAL_PWR_EnableWakeUpLine.
*/
/* First find index of the pin if valid */
WakePinSel *WakeupPinSel_idx = (WakePinSel *) WakeupPinSel;
/* Read through PinMapAnalogSwitch array */
while (WakeupPinSel_idx->pin != NC) {
/* Check whether pin is or is associated to dualpad Analog Input */
if (WakeupPinSel_idx->pin == p) {
break;
}
WakeupPinSel_idx ++;
}
if (WakeupPinSel_idx->pin != NC) {
#if defined(PWR_WAKEUP1_SOURCE_SELECTION_0)
uint32_t wkup_pin = WakeupPinSel_idx->wkup_pin | WakeupPinSel_idx->selection;
if (mode != RISING) {
wkup_pin |= PWR_WAKEUP1_POLARITY_LOW;
}
if (IS_PWR_WAKEUP_PIN(wkup_pin)) {
HAL_PWR_EnableWakeUpPin(wkup_pin);
}
#else
if (IS_PWR_WAKEUP_LINE(WakeupPinSel_idx->wkup_pin)) {
HAL_PWR_EnableWakeUpLine(WakeupPinSel_idx->wkup_pin, WakeupPinSel_idx->selection, (mode != RISING) ? PWR_WAKEUP_POLARITY_LOW : PWR_WAKEUP_POLARITY_HIGH);
/* Enable the NVIC for Wake-up pin */
HAL_NVIC_SetPriority(PWR_IRQn, 0, 0x00);
HAL_NVIC_EnableIRQ(PWR_IRQn);
}
#endif /* PWR_WAKEUP1_SOURCE_SELECTION_0 */
}
#elif defined(PWR_WAKEUP_PA0)
uint32_t wkup_pin = 0;
if (p != NC) {
#if defined(PWR_WAKEUP_PB0)
if (p == PB_0) {
wkup_pin = PWR_WAKEUP_PB0;
}
#endif
#ifdef PWR_WAKEUP_PB1
if (p == PB_1) {
wkup_pin = PWR_WAKEUP_PB1;
}
#endif
#ifdef PWR_WAKEUP_PB2
if (p == PB_2) {
wkup_pin = PWR_WAKEUP_PB0;
}
#endif
#ifdef PWR_WAKEUP_PB3
if (p == PB_3) {
wkup_pin = PWR_WAKEUP_PB3;
}
#endif
#ifdef PWR_WAKEUP_PB4
if (p == PB_4) {
wkup_pin = PWR_WAKEUP_PB4;
}
#endif
#ifdef PWR_WAKEUP_PB5
if (p == PB_5) {
wkup_pin = PWR_WAKEUP_PB5;
}
#endif
#ifdef PWR_WAKEUP_PB6
if (p == PB_6) {
wkup_pin = PWR_WAKEUP_PB6;
}
#endif
#ifdef PWR_WAKEUP_PB7
if (p == PB_7) {
wkup_pin = PWR_WAKEUP_PB7;
}
#endif
#ifdef PWR_WAKEUP_PA8
if (p == PA_8) {
wkup_pin = PWR_WAKEUP_PA8;
}
#endif
#ifdef PWR_WAKEUP_PA9
if (p == PA_9) {
wkup_pin = PWR_WAKEUP_PA9;
}
#endif
#ifdef PWR_WAKEUP_PA10
if (p == PA_10) {
wkup_pin = PWR_WAKEUP_PA10;
}
#endif
#ifdef PWR_WAKEUP_PA11
if (p == PA_11) {
wkup_pin = PWR_WAKEUP_PA11;
}
#endif
#ifdef PWR_WAKEUP_PA0
if (p == PA_0) {
wkup_pin = PWR_WAKEUP_PA0;
}
#endif
#ifdef PWR_WAKEUP_PA1
if (p == PA_1) {
wkup_pin = PWR_WAKEUP_PA1;
}
#endif
#ifdef PWR_WAKEUP_PA2
if (p == PA_2) {
wkup_pin = PWR_WAKEUP_PA2;
}
#endif
#ifdef PWR_WAKEUP_PA3
if (p == PA_3) {
wkup_pin = PWR_WAKEUP_PA3;
}
#endif
#ifdef PWR_WAKEUP_PA4
if (p == PA_4) {
wkup_pin = PWR_WAKEUP_PA4;
}
#endif
#ifdef PWR_WAKEUP_PA5
if (p == PA_5) {
wkup_pin = PWR_WAKEUP_PA5;
}
#endif
#ifdef PWR_WAKEUP_PA6
if (p == PA_6) {
wkup_pin = PWR_WAKEUP_PA6;
}
#endif
#ifdef PWR_WAKEUP_PA7
if (p == PA_7) {
wkup_pin = PWR_WAKEUP_PA7;
}
#endif
#ifdef PWR_WAKEUP_PB8
if (p == PB_8) {
wkup_pin = PWR_WAKEUP_PB8;
}
#endif
#ifdef PWR_WAKEUP_PB9
if (p == PB_9) {
wkup_pin = PWR_WAKEUP_PB9;
}
#endif
#ifdef PWR_WAKEUP_PB10
if (p == PB_10) {
wkup_pin = PWR_WAKEUP_PB10;
}
#endif
#ifdef PWR_WAKEUP_PB11
if (p == PB_11) {
wkup_pin = PWR_WAKEUP_PB11;
}
#endif
#ifdef PWR_WAKEUP_PA12
if (p == PA_12) {
wkup_pin = PWR_WAKEUP_PA12;
}
#endif
#ifdef PWR_WAKEUP_PA13
if (p == PA_13) {
wkup_pin = PWR_WAKEUP_PA13;
}
#endif
#ifdef PWR_WAKEUP_PA14
if (p == PA_14) {
wkup_pin = PWR_WAKEUP_PA14;
}
#endif
#ifdef PWR_WAKEUP_PA15
if (p == PA_15) {
wkup_pin = PWR_WAKEUP_PA15;
}
#endif
if (IS_PWR_WAKEUP_PIN(wkup_pin)) {
HAL_PWR_EnableWakeUpPin(wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG);
}
}
#elif defined(PWR_WAKEUP_PORTA)
/* Get GPIO port from pinname*/
GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(p));
uint32_t wkup_pin = 0;
uint32_t wkup_port = 0;
switch (STM_PIN(p)) {
case 0:
wkup_pin = PWR_WAKEUP_PIN0;
break;
case 1:
wkup_pin = PWR_WAKEUP_PIN1;
break;
case 2:
wkup_pin = PWR_WAKEUP_PIN2;
break;
case 3:
wkup_pin = PWR_WAKEUP_PIN3;
break;
case 4:
wkup_pin = PWR_WAKEUP_PIN4;
break;
case 5:
wkup_pin = PWR_WAKEUP_PIN5;
break;
case 6:
wkup_pin = PWR_WAKEUP_PIN6;
break;
case 7:
wkup_pin = PWR_WAKEUP_PIN7;
break;
case 8:
wkup_pin = PWR_WAKEUP_PIN8;
break;
case 9:
wkup_pin = PWR_WAKEUP_PIN9;
break;
case 10:
wkup_pin = PWR_WAKEUP_PIN10;
break;
case 11:
wkup_pin = PWR_WAKEUP_PIN11;
break;
case 12:
wkup_pin = PWR_WAKEUP_PIN12;
break;
case 13:
wkup_pin = PWR_WAKEUP_PIN13;
break;
case 14:
wkup_pin = PWR_WAKEUP_PIN14;
break;
case 15:
wkup_pin = PWR_WAKEUP_PIN15;
break;
default:
port = NULL;
break;
}
if (port == (GPIO_TypeDef *)GPIOA_BASE) {
wkup_port = PWR_WAKEUP_PORTA;
} else if (port == (GPIO_TypeDef *)GPIOB_BASE) {
wkup_port = PWR_WAKEUP_PORTB;
}
if (IS_PWR_WAKEUP_SOURCE(wkup_pin)) {
HAL_PWR_EnableWakeUpPin(wkup_port, wkup_pin, ((mode == RISING) || (mode == HIGH)) ? PWR_WUP_FALLEDG : PWR_WUP_RISIEDG);
}
#else
#if !defined(PWR_WAKEUP_PIN1_HIGH)
UNUSED(mode);
#endif
uint32_t wkup_pin = 0;
if (p != NC) {
#if defined(PWR_WAKEUP_PIN1)
if (p == SYS_WKUP1) {
wkup_pin = PWR_WAKEUP_PIN1;
#ifdef PWR_WAKEUP_PIN1_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN1_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN1 */
#ifdef PWR_WAKEUP_PIN2
if (p == SYS_WKUP2) {
wkup_pin = PWR_WAKEUP_PIN2;
#ifdef PWR_WAKEUP_PIN2_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN2_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN2 */
#ifdef PWR_WAKEUP_PIN3
if (p == SYS_WKUP3) {
wkup_pin = PWR_WAKEUP_PIN3;
#ifdef PWR_WAKEUP_PIN3_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN3_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN3 */
#ifdef PWR_WAKEUP_PIN4
if (p == SYS_WKUP4) {
wkup_pin = PWR_WAKEUP_PIN4;
#ifdef PWR_WAKEUP_PIN4_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN4_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN4 */
#ifdef PWR_WAKEUP_PIN5
if (p == SYS_WKUP5) {
wkup_pin = PWR_WAKEUP_PIN5;
#ifdef PWR_WAKEUP_PIN5_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN5_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN5 */
#ifdef PWR_WAKEUP_PIN6
if (p == SYS_WKUP6) {
wkup_pin = PWR_WAKEUP_PIN6;
#ifdef PWR_WAKEUP_PIN6_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN6_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN6 */
#ifdef PWR_WAKEUP_PIN7
if (p == SYS_WKUP7) {
wkup_pin = PWR_WAKEUP_PIN7;
#ifdef PWR_WAKEUP_PIN7_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN7_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN7 */
#ifdef PWR_WAKEUP_PIN8
if (p == SYS_WKUP8) {
wkup_pin = PWR_WAKEUP_PIN8;
#ifdef PWR_WAKEUP_PIN8_HIGH
if (mode != RISING) {
wkup_pin = PWR_WAKEUP_PIN8_LOW;
}
#endif
}
#endif /* PWR_WAKEUP_PIN8 */
if (IS_PWR_WAKEUP_PIN(wkup_pin)) {
HAL_PWR_EnableWakeUpPin(wkup_pin);
}
}
#endif /* !PWR_WAKEUP_SELECT_0 && !PWR_WAKEUP1_SOURCE_SELECTION_0 */
}
#if defined(PWR_CSR_REGLPF)
/**
* @brief For STM32L0 and STM32L1, running in LowPower Sleep requires
* to slow down frequency to MSI range1.
* @retval None
*/
void SystemClock_Decrease(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_1;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
Error_Handler();
}
}
#elif defined(STM32L4xx) || defined(STM32L5xx) || defined(STM32WBxx) || defined(STM32WLxx)
/**
* @brief For STM32L4, STM32L5, STM32WB and STM32WL
* running in LowPower Sleep requires to slow down frequency to 2MHz max.
* @retval None
*/
void SystemClock_Decrease(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
/** Configure the main internal regulator output voltage
*/
#if (defined(STM32WBxx) && defined(PWR_CR1_VOS)) || !defined(STM32WBxx)
#if defined(STM32L4xx) || defined(STM32WBxx)
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
#elif defined(STM32L5xx) || defined(STM32WLxx)
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2) != HAL_OK)
#endif
{
Error_Handler();
}
#endif
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/** Initializes the CPU and buses clocks
*/
#if defined(STM32WBxx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
| RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
#elif defined(STM32WLxx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3 | RCC_CLOCKTYPE_HCLK
| RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1
| RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
#elif defined(STM32L4xx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
#endif
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
Error_Handler();
}
}
#elif defined(STM32G0xx) || defined(STM32G4xx) || defined(STM32U0xx)
/**
* @brief For STM32G0 and STM32G4
* running in LowPower Sleep requires to slow down frequency to 2MHz max.
* @retval None
*/
void SystemClock_Decrease(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
#if defined(STM32G0xx)
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
#endif
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
#if defined(STM32G4xx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
#elif defined(STM32G0xx) || defined(STM32U0xx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1;
#endif
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV8;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
Error_Handler();
}
}
#endif
/**
* @brief Enable the sleep mode.
* @param None
* @retval None
*/
void LowPower_sleep(uint32_t regulator)
{
#if defined(PWR_LOWPOWERREGULATOR_ON) && \
(defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF))
// When LowPower regulator sleep mode is used, it is necessary to decrease CPU Frequency
if (regulator == PWR_LOWPOWERREGULATOR_ON) {
SystemClock_Decrease();
}
#endif
/*
* Suspend Tick increment to prevent wakeup by Systick interrupt.
* Otherwise the Systick interrupt will wake up the device within
* 1ms (HAL time base)
*/
HAL_SuspendTick();
/* Enter Sleep Mode , wake up is done once User push-button is pressed */
#if defined(PWR_SLEEPENTRY_WFI)
HAL_PWR_EnterSLEEPMode(regulator, PWR_SLEEPENTRY_WFI);
#else
(void)regulator;
HAL_PWR_EnterSLEEPMode();
#endif
#if defined(PWR_LOWPOWERREGULATOR_ON) && \
(defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF))
// In case of LowPower Regulator used for sleep, restore Main regulator on exit
if (regulator == PWR_LOWPOWERREGULATOR_ON) {
#if defined(__HAL_RCC_PWR_CLK_ENABLE)
__HAL_RCC_PWR_CLK_ENABLE();
#endif
HAL_PWREx_DisableLowPowerRunMode();
// Restore systemClock which has been decreased by SystemClock_Decrease()
SystemClock_Config();
}
#endif
/* Resume Tick interrupt if disabled prior to SLEEP mode entry */
HAL_ResumeTick();
if (WakeUpUartCb != NULL) {
WakeUpUartCb();
}
}
/**
* @brief Enable the stop mode.
* @param obj : pointer to serial_t structure
* @retval None
*/
void LowPower_stop(serial_t *obj)
{
__disable_irq();
#if defined(UART_WKUP_SUPPORT)
if (WakeUpUart != NULL) {
HAL_UARTEx_EnableStopMode(WakeUpUart);
}
#endif
#if defined(STM32WB0x) || defined(STM32WL3x)
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_DEEPSTOPF);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
PWR_DEEPSTOPTypeDef configDEEPSTOP;
configDEEPSTOP.deepStopMode = PWR_DEEPSTOP_WITH_SLOW_CLOCK_ON;
/* Enter the Deepstop mode */
HAL_PWR_ConfigDEEPSTOP(&configDEEPSTOP);
HAL_PWR_EnterDEEPSTOPMode();
#else
#if defined(PWR_CR_ULP)
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
#endif
#if defined(PWR_CR1_ULPMEN) || defined(PWR_CR3_ULPMEN) || \
(defined(PWR_CR3_ENULP) && defined(STM32U0xx))
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPowerMode();
#endif
#if defined(PWR_CR_FWU)
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
#endif
#ifdef __HAL_RCC_WAKEUPSTOP_CLK_CONFIG
/* Select MSI or HSI as system clock source after Wake Up from Stop mode */
#ifdef RCC_STOP_WAKEUPCLOCK_MSI
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
#else
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
#endif
#endif
#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
#if defined(LL_PWR_MODE_STOP2)
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
#else
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
#endif
#endif
/* Enter Stop mode */
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) || \
defined(LL_PWR_MODE_STOP2))
if ((WakeUpUart == NULL)
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)
#ifdef LPUART2_BASE
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART2_BASE)
#endif
#ifdef LPUART3_BASE
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART3_BASE)
#endif
) {
#if defined(PWR_CR1_RRSTP)
// STM32L4+ must keep SRAM3 content when entering STOP2 lowpower mode
HAL_PWREx_EnableSRAM3ContentRetention();
#endif /* PWR_CR1_RRSTP */
#if defined(STM32H7xx)
#if defined(PWR_LOWPOWERREGULATOR_ON)
HAL_PWREx_EnterSTOP2Mode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
#else
HAL_PWREx_EnterSTOP2Mode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
#endif
#elif defined(STM32U3xx)
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERMODE_STOP2, PWR_STOPENTRY_WFI);
#else
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
#endif
} else
#endif
{
#if defined(PWR_LOWPOWERREGULATOR_ON)
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
#else
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
#endif
}
#endif /* STM32WB0x */
/* Exit Stop mode reset clocks */
SystemClock_ConfigFromStop();
#if defined(UART_WKUP_SUPPORT)
if (WakeUpUart != NULL) {
/* In case of WakeUp from UART, reset its clock source to HSI */
uart_config_lowpower(obj);
HAL_UARTEx_DisableStopMode(WakeUpUart);
}
#else
UNUSED(obj);
#endif
__enable_irq();
HAL_Delay(10);
if (WakeUpUartCb != NULL) {
WakeUpUartCb();
}
}
/**
* @brief Enable the standby mode. The board reset when leaves this mode.
* @param None
* @retval None
*/
void LowPower_standby()
{
#if !defined(STM32WB0x) && !defined(STM32WL3x)
__disable_irq();
/* Clear wakeup flags */
#if defined(PWR_FLAG_WU)
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
#elif defined(PWR_CPUCR_CSSF)
__HAL_PWR_CLEAR_FLAG(PWR_CPUCR_CSSF);
#elif defined(PWR_MPUCR_CSSF)
__HAL_PWR_CLEAR_FLAG(PWR_MPUCR_CSSF);
#endif
#if defined(PWR_CR_ULP)
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
#endif
#if defined(PWR_CR_FWU)
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
#endif
#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
#endif
HAL_PWR_EnterSTANDBYMode();
#endif /* !STM32WB0x || STM32WL3x */
}
/**
* @brief Enable the shutdown mode.The board reset when leaves this mode.
* If shutdown mode not available, use standby mode instead.
* @param boolean true if RTC is configured, in that case LSE is required
* @retval None
*/
void LowPower_shutdown(bool isRTC)
{
__disable_irq();
/* Clear wakeup flags */
#if defined(PWR_FLAG_WU)
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
#elif defined(PWR_CPUCR_CSSF)
__HAL_PWR_CLEAR_FLAG(PWR_CPUCR_CSSF);
#elif defined(PWR_MPUCR_CSSF)
__HAL_PWR_CLEAR_FLAG(PWR_MPUCR_CSSF);
#endif
#if !defined(STM32WB0x)
#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
#endif
#if defined(LL_PWR_SHUTDOWN_MODE) || defined(LL_PWR_MODE_SHUTDOWN)
/* LSE must be on to use shutdown mode within RTC else fallback to standby */
if ((!isRTC) || (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET)) {
#if defined(STM32U0xx)
HAL_PWR_EnterSHUTDOWNMode();
#else
HAL_PWREx_EnterSHUTDOWNMode();
#endif
} else
#else
UNUSED(isRTC);
#endif
{
LowPower_standby();
}
#else
(void)isRTC; // Avoid unused variable warning
PWR_SHUTDOWNTypeDef ConfigSHUTDOWN;
HAL_PWR_ConfigSHUTDOWN(&ConfigSHUTDOWN);
LL_PWR_DisableDEEPSTOP2();
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
LL_LPM_EnableDeepSleep();
__WFI();
#endif /* !STM32WB0x */
}
/**
* @brief Configure the UART as a wakeup source. A callback can be called when
* the chip leaves the low power mode. See board datasheet to check
* with which low power mode the UART is compatible.
* Warning This function will change UART clock source to HSI
* @param serial: pointer to serial
* @param callback: pointer to callback
* @retval None
*/
void LowPower_EnableWakeUpUart(serial_t *serial, voidFuncPtr callback)
{
#if defined(UART_WKUP_SUPPORT)
#ifdef IS_UART_WAKEUP_SELECTION
UART_WakeUpTypeDef WakeUpSelection;
if (serial == NULL) {
return;
}
/* Save Uart handler and Serial object */
WakeUpUart = &(serial->handle);
/* make sure that no UART transfer is on-going */
while (__HAL_UART_GET_FLAG(WakeUpUart, USART_ISR_BUSY) == SET);
/* make sure that UART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while (__HAL_UART_GET_FLAG(WakeUpUart, USART_ISR_REACK) == RESET);
/* set the wake-up event:
* specify wake-up on RXNE flag
*/
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;