Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define USBULPI_PHYCR
#define USBULPI_D07
#define USBULPI_New
#define USBULPI_RW
#define USBULPI_S_BUSY
#define USBULPI_S_DONE
#define Pattern_55
#define Pattern_AA
#define PHY_PWR_DOWN
#define PHY_ADDRESS
#define USB_OTG_READ_REG32
#define USB_OTG_WRITE_REG32
Private variables
RTCHandle
Private function prototypes
SleepMode_Measure()
StopMode_Measure()
StopUnderDriveMode_Measure()
StandbyMode_Measure()
StandbyRTCMode_Measure()
StandbyRTCBKPSRAMMode_Measure()
SYSCLKConfig_STOP()
USB_ULPI_Read(uint32_t)
USB_ULPI_Write(uint32_t, uint32_t)
USB_ULPI_MspInit()
USB_PhyEnterLowPowerMode()
USB_PhyExitFromLowPowerMode()
ETH_PhyEnterPowerDownMode()
ETH_PhyExitFromPowerDownMode()
Files
loading...
SourceVuSTM32 Libraries and SamplesPWR_CurrentConsumptionSrc/stm32f4xx_lp_modes.c
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file PWR/PWR_CurrentConsumption/stm32f4xx_lp_modes.c * @author MCD Application Team * @brief This file provides firmware functions to manage the following * functionalities of the STM32F4xx Low Power Modes: * - Sleep Mode * - STOP mode with RTC * - Under-Drive STOP mode with RTC * - STANDBY mode without RTC and BKPSRAM * - STANDBY mode with RTC * - STANDBY mode with RTC and BKPSRAM ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup PWR_CurrentConsumption * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* ULPI PHY */ #define USBULPI_PHYCR ((uint32_t)(0x40040000 + 0x034)) #define USBULPI_D07 ((uint32_t)0x000000FF) #define USBULPI_New ((uint32_t)0x02000000) #define USBULPI_RW ((uint32_t)0x00400000) #define USBULPI_S_BUSY ((uint32_t)0x04000000) #define USBULPI_S_DONE ((uint32_t)0x08000000) #define Pattern_55 ((uint32_t)0x00000055) #define Pattern_AA ((uint32_t)0x000000AA) #define PHY_PWR_DOWN PHY_POWERDOWN #define PHY_ADDRESS DP83848_PHY_ADDRESS /* default ADDR for PHY: DP83848 */ #define USB_OTG_READ_REG32(reg) (*(__IO uint32_t *)(reg)) #define USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)(reg) = (value)) 12 defines Private define/* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* RTC handler declaration */ RTC_HandleTypeDef RTCHandle; Private variables /* Private function prototypes -----------------------------------------------*/ static void SYSCLKConfig_STOP(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief This function configures the system to enter Sleep mode for * current consumption measurement purpose. * Sleep Mode * ========== * - System Running at PLL (168MHz) * - Flash 5 wait state * - Instruction and Data caches ON * - Prefetch ON * - Code running from Internal FLASH * - All peripherals disabled. * - Wakeup using EXTI Line (Key Button) * @param None * @retval None *//* ... */ void SleepMode_Measure(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct); HAL_GPIO_Init(GPIOK, &GPIO_InitStruct); /* Disable GPIOs clock */ __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOB_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_GPIOD_CLK_DISABLE(); __HAL_RCC_GPIOE_CLK_DISABLE(); __HAL_RCC_GPIOF_CLK_DISABLE(); __HAL_RCC_GPIOG_CLK_DISABLE(); __HAL_RCC_GPIOH_CLK_DISABLE(); __HAL_RCC_GPIOI_CLK_DISABLE(); __HAL_RCC_GPIOJ_CLK_DISABLE(); __HAL_RCC_GPIOK_CLK_DISABLE(); /* Disable USB Clock */ __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); __HAL_RCC_USB_OTG_HS_ULPI_CLK_DISABLE(); /* Disable Ethernet Clock */ __HAL_RCC_ETH_CLK_DISABLE(); /* Configure KEY Button */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); /* 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(); /* Request to enter SLEEP mode */ HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* Resume Tick interrupt if disabled prior to sleep mode entry */ HAL_ResumeTick(); /* Exit USB Phy from LowPower mode */ USB_PhyExitFromLowPowerMode(); /* Exit Ethernet Phy from LowPower mode */ ETH_PhyExitFromPowerDownMode(); /* Configure LED4 */ BSP_LED_Init(LED4); /* Turns selected LED On */ BSP_LED_On(LED4); /* Add a delay of 2 seconds after exit from Sleep mode */ HAL_Delay(2000); }{ ... } /** * @brief This function configures the system to enter Stop mode with RTC * clocked by LSE or LSI for current consumption measurement purpose. * STOP Mode with RTC clocked by LSE/LSI * ===================================== * - RTC Clocked by LSE or LSI * - Regulator in LP mode * - Under drive feature enabled * - HSI, HSE OFF and LSI OFF if not used as RTC Clock source * - No IWDG * - FLASH in deep power down mode * - Automatic Wakeup using RTC clocked by LSE/LSI (~20s) * @param None * @retval None *//* ... */ void StopMode_Measure(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct); HAL_GPIO_Init(GPIOK, &GPIO_InitStruct); /* Disable GPIOs clock */ __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOB_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_GPIOD_CLK_DISABLE(); __HAL_RCC_GPIOE_CLK_DISABLE(); __HAL_RCC_GPIOF_CLK_DISABLE(); __HAL_RCC_GPIOG_CLK_DISABLE(); __HAL_RCC_GPIOH_CLK_DISABLE(); __HAL_RCC_GPIOI_CLK_DISABLE(); __HAL_RCC_GPIOJ_CLK_DISABLE(); __HAL_RCC_GPIOK_CLK_DISABLE(); /* Disable USB Clock */ __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); __HAL_RCC_USB_OTG_HS_ULPI_CLK_DISABLE(); /* Disable Ethernet Clock */ __HAL_RCC_ETH_CLK_DISABLE(); /*## Configure the RTC peripheral###########################################*/ /* Configure RTC prescaler and RTC data registers as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain *//* ... */ RTCHandle.Instance = RTC; RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&RTCHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_RTC_Init(&RTCHandle) != HAL_OK) { ... } /*## Configure the Wake up timer ###########################################*/ /* RTC Wakeup Interrupt Generation: Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 20s the WakeUpCounter is set to 0xA017: RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~32.768KHz) = ~0,488 ms Wakeup Time = ~20s = 0,488ms * WakeUpCounter ==> WakeUpCounter = ~20s/0,488ms = 40983 = 0xA017 *//* ... */ /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /* Enable Wake-up timer */ HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0xA000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); /* FLASH Deep Power Down Mode enabled */ HAL_PWREx_EnableFlashPowerDown(); /*## Enter Stop Mode #######################################################*/ HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) *//* ... */ SYSCLKConfig_STOP(); /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /* Exit USB Phy from low power mode */ USB_PhyExitFromLowPowerMode(); /* Exit Ethernet Phy from low power mode */ ETH_PhyExitFromPowerDownMode(); /* Configure LED4 */ BSP_LED_Init(LED4); /* Toggle LED4 */ BSP_LED_On(LED4); }{ ... } /** * @brief This function configures the system to enter Under-Drive stop mode with RTC * clocked by LSE or LSI for current consumption measurement purpose. * STOP Mode with RTC clocked by LSE/LSI * ===================================== * - RTC Clocked by LSE or LSI * - Regulator in LP mode * - Under drive feature enabled * - HSI, HSE OFF and LSI OFF if not used as RTC Clock source * - No IWDG * - FLASH in deep power down mode * - Automatic Wakeup using RTC clocked by LSE/LSI (~20s) * @param None * @retval None *//* ... */ void StopUnderDriveMode_Measure(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Configure all GPIO as analog to reduce current consumption on non used IOs */ /* Enable GPIOs clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct); HAL_GPIO_Init(GPIOK, &GPIO_InitStruct); /* Disable GPIOs clock */ __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOB_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_GPIOD_CLK_DISABLE(); __HAL_RCC_GPIOE_CLK_DISABLE(); __HAL_RCC_GPIOF_CLK_DISABLE(); __HAL_RCC_GPIOG_CLK_DISABLE(); __HAL_RCC_GPIOH_CLK_DISABLE(); __HAL_RCC_GPIOI_CLK_DISABLE(); __HAL_RCC_GPIOJ_CLK_DISABLE(); __HAL_RCC_GPIOK_CLK_DISABLE(); /* Disable USB Clock */ __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); __HAL_RCC_USB_OTG_HS_ULPI_CLK_DISABLE(); /* Disable Ethernet Clock */ __HAL_RCC_ETH_CLK_DISABLE(); /*## Configure the RTC peripheral###########################################*/ /* Configure RTC prescaler and RTC data registers as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain *//* ... */ RTCHandle.Instance = RTC; RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&RTCHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_RTC_Init(&RTCHandle) != HAL_OK) { ... } /*## Configure the Wake up timer ###########################################*/ /* RTC Wakeup Interrupt Generation: Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 20s the WakeUpCounter is set to 0xA017: RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~32.768KHz) = ~0,488 ms Wakeup Time = ~20s = 0,488ms * WakeUpCounter ==> WakeUpCounter = ~20s/0,488ms = 40983 = 0xA017 *//* ... */ /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /* Enable Wake-up timer */ HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0xA000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); /* FLASH Deep Power Down Mode enabled */ HAL_PWREx_EnableFlashPowerDown(); /*## Enter under-drive Stop Mode ###########################################*/ HAL_PWREx_EnterUnderDriveSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) *//* ... */ SYSCLKConfig_STOP(); /* Exit USB Phy from low power mode */ USB_PhyExitFromLowPowerMode(); /* Exit Ethernet Phy from low power mode */ ETH_PhyExitFromPowerDownMode(); /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /* Configure LED4 */ BSP_LED_Init(LED4); /* Toggle LED4 */ BSP_LED_On(LED4); }{ ... } /** * @brief This function configures the system to enter Standby mode for * current consumption measurement purpose. * STANDBY Mode * ============ * - Backup SRAM and RTC OFF * - IWDG and LSI OFF * - Wakeup using WakeUp Pin (PA.00) * @param None * @retval None *//* ... */ void StandbyMode_Measure(void) { /* Enable Power Clock*/ __HAL_RCC_PWR_CLK_ENABLE(); /* Allow access to Backup */ HAL_PWR_EnableBkUpAccess(); /* Reset RTC Domain */ __HAL_RCC_BACKUPRESET_FORCE(); __HAL_RCC_BACKUPRESET_RELEASE(); /* Disable all used wakeup sources: Pin1(PA.0) */ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); /* Clear all related wakeup flags */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Re-enable all used wakeup sources: Pin1(PA.0) */ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /*## Enter Standby Mode ####################################################*/ /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); }{ ... } /** * @brief This function configures the system to enter Standby mode with RTC * clocked by LSE or LSI for current consumption measurement purpose. * STANDBY Mode with RTC clocked by LSE/LSI * ======================================== * - RTC Clocked by LSE/LSI * - IWDG OFF * - Backup SRAM OFF * - Automatic Wakeup using RTC clocked by LSE/LSI (after ~20s) * @param None * @retval None *//* ... */ void StandbyRTCMode_Measure(void) { /*## Configure the RTC peripheral###########################################*/ /* Configure RTC prescaler and RTC data registers as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain *//* ... */ RTCHandle.Instance = RTC; RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&RTCHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_RTC_Init(&RTCHandle) != HAL_OK) { ... } /*## Configure the Wake up timer ###########################################*/ /* RTC Wakeup Interrupt Generation: Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 20s the WakeUpCounter is set to 0xA017: RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~32.768KHz) = ~0,488 ms Wakeup Time = ~20s = 0,488ms * WakeUpCounter ==> WakeUpCounter = ~20s/0,488ms = 40983 = 0xA017 *//* ... */ /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /*## Clear all related wakeup flags ########################################*/ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Clear RTC Wake Up timer Flag */ __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&RTCHandle, RTC_FLAG_WUTF); /*## Setting the Wake up time ##############################################*/ HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0xA000-1, RTC_WAKEUPCLOCK_RTCCLK_DIV16); /*## Enter Standby Mode ####################################################*/ /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); }{ ... } /** * @brief This function configures the system to enter Standby mode with RTC * clocked by LSE or LSI and with Backup SRAM ON for current consumption * measurement purpose. * STANDBY Mode with RTC clocked by LSE/LSI and BKPSRAM * ==================================================== * - RTC Clocked by LSE or LSI * - Backup SRAM ON * - IWDG OFF * - Automatic Wakeup using RTC clocked by LSE/LSI (after ~20s) * @param None * @retval None *//* ... */ void StandbyRTCBKPSRAMMode_Measure(void) { /*## Configure the RTC peripheral###########################################*/ /* Configure RTC prescaler and RTC data registers as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain *//* ... */ RTCHandle.Instance = RTC; RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&RTCHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); }if (HAL_RTC_Init(&RTCHandle) != HAL_OK) { ... } /*## Configure the Wake up timer ###########################################*/ /* RTC Wakeup Interrupt Generation: Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 20s the WakeUpCounter is set to 0xA017: RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~32.768KHz) = ~0,488 ms Wakeup Time = ~20s = 0,488ms * WakeUpCounter ==> WakeUpCounter = ~20s/0,488ms = 40983 = 0xA017 *//* ... */ /* Disable Wake-up timer */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); /*## Clear all related wakeup flags ########################################*/ /* Clear PWR wake up Flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); /* Clear RTC Wake Up timer Flag */ __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&RTCHandle, RTC_FLAG_WUTF); /*## Setting the Wake up time ##############################################*/ HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0xA000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); /* Enable BKPRAM Clock */ __HAL_RCC_BKPSRAM_CLK_ENABLE(); /* Enable the Backup SRAM low power Regulator */ HAL_PWREx_EnableBkUpReg(); /*## Enter Standby Mode ####################################################*/ /* Request to enter STANDBY mode */ HAL_PWR_EnterSTANDBYMode(); }{ ... } /** * @brief Configures system clock after wake-up from STOP: enable HSE, PLL * and select PLL as system clock source. * @param None * @retval None *//* ... */ static void SYSCLKConfig_STOP(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; uint32_t pFLatency = 0; /* Get the Oscillators configuration according to the internal RCC registers */ HAL_RCC_GetOscConfig(&RCC_OscInitStruct); /* After wake-up from STOP reconfigure the system clock: Enable HSE and PLL */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); }if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { ... } /* Get the Clocks configuration according to the internal RCC registers */ HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers *//* ... */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) { Error_Handler(); }if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) { ... } }{ ... } /** * @brief Read CR value * @param Addr the Address of the ULPI Register * @retval Returns value of PHY CR register *//* ... */ uint32_t USB_ULPI_Read(uint32_t Addr) { __IO uint32_t val = 0; __IO uint32_t timeout = 100; /* Can be tuned based on the Clock or etc... */ USB_OTG_WRITE_REG32(USBULPI_PHYCR, USBULPI_New | (Addr << 16)); val = USB_OTG_READ_REG32(USBULPI_PHYCR); while (((val & USBULPI_S_DONE) == 0) && (timeout--)) { val = USB_OTG_READ_REG32(USBULPI_PHYCR); }while (((val & USBULPI_S_DONE) == 0) && (timeout--)) { ... } val = USB_OTG_READ_REG32(USBULPI_PHYCR); return (val & 0x000000ff); }{ ... } /** * @brief Write CR value * @param Addr the Address of the ULPI Register * @param Data Data to write * @retval Returns value of PHY CR register *//* ... */ uint32_t USB_ULPI_Write(uint32_t Addr, uint32_t Data) /* Parameter is the Address of the ULPI Register & Date to write */ { __IO uint32_t val; __IO uint32_t timeout = 10; /* Can be tuned based on the Clock or etc... */ USB_OTG_WRITE_REG32(USBULPI_PHYCR, USBULPI_New | USBULPI_RW | (Addr << 16) | (Data & 0x000000ff)); val = USB_OTG_READ_REG32(USBULPI_PHYCR); while (((val & USBULPI_S_DONE) == 0) && (timeout--)) { val = USB_OTG_READ_REG32(USBULPI_PHYCR); }while (((val & USBULPI_S_DONE) == 0) && (timeout--)) { ... } val = USB_OTG_READ_REG32(USBULPI_PHYCR); return 0; ...} /** * @brief Configures GPIO for USB ULPI * @param None * @retval 0 *//* ... */ void USB_ULPI_MspInit(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Enable GPIOs clock */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); /* Common for all IOs */ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; /* D0 PA3*/ GPIO_InitStruct.Pin = GPIO_PIN_3; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* CLK PA5*/ GPIO_InitStruct.Pin = GPIO_PIN_5; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* D1 D2 D3 D4 D5 D6 D7 :PB0/1/5/10/11/12/13 */ GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\ GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\ GPIO_PIN_13; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* NXT PH4*/ GPIO_InitStruct.Pin = GPIO_PIN_4; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /* STP PC0*/ GPIO_InitStruct.Pin = GPIO_PIN_0; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* DIR PI11 */ GPIO_InitStruct.Pin = GPIO_PIN_11; HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); }{ ... } /** * @brief This function configures the USB PHY to enter the low power mode * @param None * @retval None *//* ... */ void USB_PhyEnterLowPowerMode(void) { static __IO uint32_t regval = 0; /* USB ULPI MspInit */ USB_ULPI_MspInit(); /* disable ULPI_CLK by accessing ULPI_PHY */ /* read Vendor ID : (Low, High) 0x24,0x04 for USB3300 */ regval = USB_ULPI_Read(0x00); if(regval != 0x24) { while(regval != 0x24) { USB_ULPI_MspInit(); regval = USB_ULPI_Read(0x00); }while (regval != 0x24) { ... } }if (regval != 0x24) { ... } regval = USB_ULPI_Read(0x01); if(regval != 0x04) { Error_Handler(); }if (regval != 0x04) { ... } /* read Product ID */ regval = USB_ULPI_Read(0x02); if(regval != 0x04) { Error_Handler(); }if (regval != 0x04) { ... } regval = USB_ULPI_Read(0x03); if(regval != 0x00) { Error_Handler(); }if (regval != 0x00) { ... } /* Write to scratch Register the Pattern_55 */ USB_ULPI_Write(0x16, 0x55); /* Read to scratch Register and check-it again the written Pattern */ regval = USB_ULPI_Read(0x16); if(regval != 0x55) { Error_Handler(); }if (regval != 0x55) { ... } /* Write to scratch Register the Pattern_AA */ USB_ULPI_Write(0x16, 0xAA); /* Read to scratch Register and check-it again the written Pattern */ regval = USB_ULPI_Read(0x16); if(regval != 0xAA) { Error_Handler(); }if (regval != 0xAA) { ... } /* read InterfaceControl reg */ regval = USB_ULPI_Read(0x07); /* write InterfaceControl reg,to disable PullUp on stp, to avoid USB_PHY wake up when MCU entering standby *//* ... */ USB_ULPI_Write(0x07, regval | 0x80) ; /* read InterfaceControl reg */ regval = USB_ULPI_Read(0x07); if(regval != 0x80) { Error_Handler(); }if (regval != 0x80) { ... } /* read FunctionControl reg */ regval = USB_ULPI_Read(0x04); if(regval != 0x45) { Error_Handler(); }if (regval != 0x45) { ... } /* write FunctionControl reg,to put PHY into LowPower mode */ USB_ULPI_Write(0x04, regval & (~0x40)); /* read FunctionControl reg again */ regval = USB_ULPI_Read(0x04); if(regval != 0x00) { Error_Handler(); }if (regval != 0x00) { ... } }{ ... } /** * @brief This function wakeup the USB PHY from the Low power mode * @param None * @retval None *//* ... */ void USB_PhyExitFromLowPowerMode(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Enable GPIO clock for OTG USB STP pin (optional, clock should already be enabled at this phase) */ __HAL_RCC_GPIOC_CLK_ENABLE(); /* Set OTG STP pin as GP Output */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Set OTG STP pin to High state during 4 milliseconds */ HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); /* Delay 4 ms */ HAL_Delay(4); }{ ... } /** * @brief This function configures the ETH PHY to enter the power down mode * This function should be called before entering the low power mode. * @param None * @retval None *//* ... */ void ETH_PhyEnterPowerDownMode(void) { ETH_HandleTypeDef heth; GPIO_InitTypeDef GPIO_InitStruct; uint32_t phyregval = 0; /* This part of code is used only when the ETH peripheral is disabled when the ETH is used in the application this initialization code is called in HAL_ETH_MspInit() function ***********************//* ... */ /* Enable GPIO clocks*/ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); /* Configure PA2: ETH_MDIO */ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Alternate = GPIO_AF11_ETH; GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Configure PC1: ETH_MDC */ GPIO_InitStruct.Pin = GPIO_PIN_1; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Enable the ETH peripheral clocks */ __HAL_RCC_ETH_CLK_ENABLE(); /* Set ETH Handle parameters */ heth.Instance = ETH; heth.Init.PhyAddress = PHY_ADDRESS; /* Configure MDC clock: the MDC Clock Range configuration depend on the system clock: 180Mhz/102 = 1.76Mhz *//* ... */ /* MDC: a periodic clock that provides the timing reference for the MDIO data transfer at the maximum frequency of 1.76MHz.*//* ... */ heth.Instance->MACMIIAR = (uint32_t)ETH_MACMIIAR_CR_Div102; /*****************************************************************/ /* ETH PHY configuration in Power Down mode **********************/ /* Read ETH PHY control register */ HAL_ETH_ReadPHYRegister(&heth, PHY_BCR, &phyregval); /* Set Power down mode bit */ phyregval |= PHY_PWR_DOWN; /* Write new value to ETH PHY control register */ HAL_ETH_WritePHYRegister(&heth, PHY_BCR, phyregval); ... /*****************************************************************/ /* Disable periph CLKs */ __HAL_RCC_GPIOA_CLK_DISABLE(); __HAL_RCC_GPIOC_CLK_DISABLE(); __HAL_RCC_ETH_CLK_DISABLE(); }{ ... } /** * @brief This function wakeup the ETH PHY from the power down mode * When exiting from StandBy mode and the ETH is used in the example * its better to call this function at the end of HAL_ETH_MspInit() * then remove the code that initialize the ETH CLKs ang GPIOs. * @param None * @retval None *//* ... */ void ETH_PhyExitFromPowerDownMode(void) { ETH_HandleTypeDef heth; GPIO_InitTypeDef GPIO_InitStruct; uint32_t phyregval = 0; /* ETH CLKs and GPIOs initialization ******************************/ /* To be removed when the function is called from HAL_ETH_MspInit() when exiting from Standby mode *//* ... */ /* Enable GPIO clocks*/ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); /* Configure PA2 */ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Alternate = GPIO_AF11_ETH; GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Configure PC1*/ GPIO_InitStruct.Pin = GPIO_PIN_1; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Enable ETH CLK */ __HAL_RCC_ETH_CLK_ENABLE(); /*****************************************************************/ /* ETH PHY configuration to exit Power Down mode *****************/ /* Set ETH Handle parameters */ heth.Instance = ETH; heth.Init.PhyAddress = PHY_ADDRESS; /* Configure MDC clock: the MDC Clock Range configuration depend on the system clock: 180Mhz/102 = 1.76Mhz *//* ... */ /* MDC: a periodic clock that provides the timing reference for the MDIO data transfer at the maximum frequency of 1.76Mhz. *//* ... */ heth.Instance->MACMIIAR = (uint32_t)ETH_MACMIIAR_CR_Div102; /* Read ETH PHY control register */ HAL_ETH_ReadPHYRegister(&heth, PHY_BCR, &phyregval); /* check if the PHY is already in power down mode */ if ((phyregval & PHY_PWR_DOWN) != RESET) { /* Disable Power down mode */ phyregval &= ~ PHY_PWR_DOWN; /* Write value to ETH PHY control register */ HAL_ETH_WritePHYRegister(&heth, PHY_BCR, phyregval); }if ((phyregval & PHY_PWR_DOWN) != RESET) { ... } ... /*****************************************************************/ }{ ... } /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.