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
72
73
77
78
79
80
81
86
98
106
107
108
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
228
229
230
231
232
233
234
235
236
237
245
246
247
248
249
250
251
252
253
254
255
256
257
264
265
266
267
268
269
270
271
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
297
298
303
304
305
306
307
308
309
310
311
312
313
314
315
316
323
324
325
326
327
328
329
330
331
332
333
334
335
336
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
369
370
371
372
373
374
375
376
377
378
379
386
387
388
389
390
391
392
393
394
395
396
397
398
403
404
405
406
407
408
409
410
411
412
419
420
421
422
423
424
425
426
427
428
429
430
437
438
439
440
441
442
443
444
451
452
453
454
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
511
512
513
514
515
516
517
518
519
520
521
528
529
530
531
532
533
537
538
539
540
541
542
549
550
556
557
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
600
601
602
603
604
605
608
609
610
611
612
613
614
615
617
621
622
623
624
625
626
628
632
633
637
638
639
640
641
642
643
644
645
646
647
648
656
657
666
667
675
676
677
678
679
680
681
688
689
690
691
692
693
694
695
696
698
702
703
704
711
712
717
718
719
720
721
722
723
724
725
726
727
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
845
846
850
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
898
903
904
905
907
908
913
918
919
920
921
922
923
928
929
930
931
932
933
934
935
936
937
938
939
940
941
945
946
952
957
958
964
969
970
977
978
979
982
996
1008
1022
1032
1033
1037
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1061
1064
1067
1070
1073
1074
1075
1076
1077
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1099
1105
1106
1109
1110
1113
1114
1115
1118
1119
1122
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_RCC_MODULE_ENABLED
/* ... */
Private define
#define __MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define MCO1_GPIO_PORT GPIOA
#define MCO1_PIN GPIO_PIN_8
#define __MCO2_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define MCO2_GPIO_PORT GPIOC
#define MCO2_PIN GPIO_PIN_9
6 defines
/* ... */
Private macro
/* ... */
/* ... */
Private variables
/* ... */
/* ... */
/* ... */
__weak HAL_StatusTypeDef HAL_RCC_DeInit(void)
{
return HAL_OK;
}{ ... }
/* ... */
__weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
{
uint32_t tickstart, pll_config;
if(RCC_OscInitStruct == NULL)
{
return HAL_ERROR;
}if (RCC_OscInitStruct == NULL) { ... }
assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
{
assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSE) ||\
((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE)))
{
if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
{
return HAL_ERROR;
}if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF)) { ... }
}if ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSE) ||\ ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE))) { ... }
else
{
__HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
if((RCC_OscInitStruct->HSEState) != RCC_HSE_OFF)
{
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) { ... }
}if ((RCC_OscInitStruct->HSEState) != RCC_HSE_OFF) { ... }
else
{
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) { ... }
}else { ... }
}else { ... }
}if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) { ... }
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
{
assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSI) ||\
((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI)))
{
if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
{
return HAL_ERROR;
}if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON)) { ... }
else
{
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
}else { ... }
}if ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSI) ||\ ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI))) { ... }
else
{
if((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF)
{
__HAL_RCC_HSI_ENABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) { ... }
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
}if ((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF) { ... }
else
{
__HAL_RCC_HSI_DISABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) { ... }
}else { ... }
}else { ... }
}if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) { ... }
----------------------------- HSI Configuration
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
{
assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
if((RCC_OscInitStruct->LSIState)!= RCC_LSI_OFF)
{
__HAL_RCC_LSI_ENABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET) { ... }
}if ((RCC_OscInitStruct->LSIState)!= RCC_LSI_OFF) { ... }
else
{
__HAL_RCC_LSI_DISABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET) { ... }
}else { ... }
}if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) { ... }
------------------------------ LSI Configuration
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
{
FlagStatus pwrclkchanged = RESET;
assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
{
__HAL_RCC_PWR_CLK_ENABLE();
pwrclkchanged = SET;
}if (__HAL_RCC_PWR_IS_CLK_DISABLED()) { ... }
if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
{
SET_BIT(PWR->CR, PWR_CR_DBP);
tickstart = HAL_GetTick();
while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
{
if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE) { ... }
}while (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) { ... }
}if (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) { ... }
__HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
if((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
{
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) { ... }
}if ((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF) { ... }
else
{
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET) { ... }
}else { ... }
if(pwrclkchanged == SET)
{
__HAL_RCC_PWR_CLK_DISABLE();
}if (pwrclkchanged == SET) { ... }
}Set the new LSE configuration
if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) { ... }
assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
{
if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
{
if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
{
assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
assert_param(IS_RCC_PLLM_VALUE(RCC_OscInitStruct->PLL.PLLM));
assert_param(IS_RCC_PLLN_VALUE(RCC_OscInitStruct->PLL.PLLN));
assert_param(IS_RCC_PLLP_VALUE(RCC_OscInitStruct->PLL.PLLP));
assert_param(IS_RCC_PLLQ_VALUE(RCC_OscInitStruct->PLL.PLLQ));
__HAL_RCC_PLL_DISABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) { ... }
WRITE_REG(RCC->PLLCFGR, (RCC_OscInitStruct->PLL.PLLSource | \
RCC_OscInitStruct->PLL.PLLM | \
(RCC_OscInitStruct->PLL.PLLN << RCC_PLLCFGR_PLLN_Pos) | \
(((RCC_OscInitStruct->PLL.PLLP >> 1U) - 1U) << RCC_PLLCFGR_PLLP_Pos) | \
(RCC_OscInitStruct->PLL.PLLQ << RCC_PLLCFGR_PLLQ_Pos)));
__HAL_RCC_PLL_ENABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) { ... }
}if ((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON) { ... }
else
{
__HAL_RCC_PLL_DISABLE();
tickstart = HAL_GetTick();
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
{
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) { ... }
}else { ... }
}if (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL) { ... }
else
{
if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF)
{
return HAL_ERROR;
}if ((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) { ... }
else
{
pll_config = RCC->PLLCFGR;
#if defined (RCC_PLLCFGR_PLLR)
if (((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLM) != (RCC_OscInitStruct->PLL.PLLM) << RCC_PLLCFGR_PLLM_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLN) != (RCC_OscInitStruct->PLL.PLLN) << RCC_PLLCFGR_PLLN_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLP) != (((RCC_OscInitStruct->PLL.PLLP >> 1U) - 1U)) << RCC_PLLCFGR_PLLP_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLQ) != (RCC_OscInitStruct->PLL.PLLQ << RCC_PLLCFGR_PLLQ_Pos)) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLR) != (RCC_OscInitStruct->PLL.PLLR << RCC_PLLCFGR_PLLR_Pos)))/* ... */
#else
if (((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_OFF) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLSRC) != RCC_OscInitStruct->PLL.PLLSource) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLM) != (RCC_OscInitStruct->PLL.PLLM) << RCC_PLLCFGR_PLLM_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLN) != (RCC_OscInitStruct->PLL.PLLN) << RCC_PLLCFGR_PLLN_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLP) != (((RCC_OscInitStruct->PLL.PLLP >> 1U) - 1U)) << RCC_PLLCFGR_PLLP_Pos) ||
(READ_BIT(pll_config, RCC_PLLCFGR_PLLQ) != (RCC_OscInitStruct->PLL.PLLQ << RCC_PLLCFGR_PLLQ_Pos)))/* ... */
#endif
{
return HAL_ERROR;
...}
}else { ... }
}else { ... }
}if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
{
uint32_t tickstart;
if(RCC_ClkInitStruct == NULL)
{
return HAL_ERROR;
}if (RCC_ClkInitStruct == NULL) { ... }
assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
assert_param(IS_FLASH_LATENCY(FLatency));
/* ... */
if(FLatency > __HAL_FLASH_GET_LATENCY())
{
__HAL_FLASH_SET_LATENCY(FLatency);
/* ... */
if(__HAL_FLASH_GET_LATENCY() != FLatency)
{
return HAL_ERROR;
}if (__HAL_FLASH_GET_LATENCY() != FLatency) { ... }
}if (FLatency > __HAL_FLASH_GET_LATENCY()) { ... }
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
{
/* ... */
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_HCLK_DIV16);
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) { ... }
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (RCC_HCLK_DIV16 << 3));
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) { ... }
assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) { ... }
-------------------------- HCLK Configuration
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
{
assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
{
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
{
return HAL_ERROR;
}if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) { ... }
}if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) { ... }
else if((RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) ||
(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLRCLK))
{
if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
{
return HAL_ERROR;
}if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) { ... }
}else if ((RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) || (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLRCLK)) { ... }
else
{
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
{
return HAL_ERROR;
}if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) { ... }
}else { ... }
__HAL_RCC_SYSCLK_CONFIG(RCC_ClkInitStruct->SYSCLKSource);
tickstart = HAL_GetTick();
while (__HAL_RCC_GET_SYSCLK_SOURCE() != (RCC_ClkInitStruct->SYSCLKSource << RCC_CFGR_SWS_Pos))
{
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) { ... }
}while (__HAL_RCC_GET_SYSCLK_SOURCE() != (RCC_ClkInitStruct->SYSCLKSource << RCC_CFGR_SWS_Pos)) { ... }
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) { ... }
if(FLatency < __HAL_FLASH_GET_LATENCY())
{
__HAL_FLASH_SET_LATENCY(FLatency);
/* ... */
if(__HAL_FLASH_GET_LATENCY() != FLatency)
{
return HAL_ERROR;
}if (__HAL_FLASH_GET_LATENCY() != FLatency) { ... }
}if (FLatency < __HAL_FLASH_GET_LATENCY()) { ... }
------------------------- SYSCLK Configuration
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
{
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) { ... }
-------------------------- PCLK1 Configuration
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
{
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3U));
}if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) { ... }
SystemCoreClock = HAL_RCC_GetSysClockFreq() >> AHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> RCC_CFGR_HPRE_Pos];
HAL_InitTick (uwTickPrio);
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
{
GPIO_InitTypeDef GPIO_InitStruct;
assert_param(IS_RCC_MCO(RCC_MCOx));
assert_param(IS_RCC_MCODIV(RCC_MCODiv));
if(RCC_MCOx == RCC_MCO1)
{
assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
__MCO1_CLK_ENABLE();
GPIO_InitStruct.Pin = MCO1_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
HAL_GPIO_Init(MCO1_GPIO_PORT, &GPIO_InitStruct);
MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE), (RCC_MCOSource | RCC_MCODiv));
#if defined(RCC_CFGR_MCO1EN)
__HAL_RCC_MCO1_ENABLE();
#endif
}if (RCC_MCOx == RCC_MCO1) { ... }
#if defined(RCC_CFGR_MCO2)
else
{
assert_param(IS_RCC_MCO2SOURCE(RCC_MCOSource));
__MCO2_CLK_ENABLE();
GPIO_InitStruct.Pin = MCO2_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
HAL_GPIO_Init(MCO2_GPIO_PORT, &GPIO_InitStruct);
MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE), (RCC_MCOSource | (RCC_MCODiv << 3U)));
#if defined(RCC_CFGR_MCO2EN)
__HAL_RCC_MCO2_ENABLE();
#endif
}else { ... }
/* ... */#endif
}{ ... }
/* ... */
void HAL_RCC_EnableCSS(void)
{
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)ENABLE;
}{ ... }
/* ... */
void HAL_RCC_DisableCSS(void)
{
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)DISABLE;
}{ ... }
/* ... */
__weak uint32_t HAL_RCC_GetSysClockFreq(void)
{
uint32_t pllm = 0U, pllvco = 0U, pllp = 0U;
uint32_t sysclockfreq = 0U;
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case RCC_CFGR_SWS_HSI:
{
sysclockfreq = HSI_VALUE;
break;
...}case RCC_CFGR_SWS_HSI:
case RCC_CFGR_SWS_HSE:
{
sysclockfreq = HSE_VALUE;
break;
...}case RCC_CFGR_SWS_HSE:
case RCC_CFGR_SWS_PLL:
{
/* ... */
pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
{
pllvco = (uint32_t) ((((uint64_t) HSE_VALUE * ((uint64_t) ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos)))) / (uint64_t)pllm);
}if (__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI) { ... }
else
{
pllvco = (uint32_t) ((((uint64_t) HSI_VALUE * ((uint64_t) ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos)))) / (uint64_t)pllm);
}else { ... }
pllp = ((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> RCC_PLLCFGR_PLLP_Pos) + 1U) *2U);
sysclockfreq = pllvco/pllp;
break;
...}case RCC_CFGR_SWS_PLL:
default:
{
sysclockfreq = HSI_VALUE;
break;
...}default
}switch (RCC->CFGR & RCC_CFGR_SWS) { ... }
return sysclockfreq;
}{ ... }
/* ... */
uint32_t HAL_RCC_GetHCLKFreq(void)
{
return SystemCoreClock;
}{ ... }
/* ... */
uint32_t HAL_RCC_GetPCLK1Freq(void)
{
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1)>> RCC_CFGR_PPRE1_Pos]);
}{ ... }
/* ... */
uint32_t HAL_RCC_GetPCLK2Freq(void)
{
return (HAL_RCC_GetHCLKFreq()>> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2)>> RCC_CFGR_PPRE2_Pos]);
}{ ... }
/* ... */
__weak void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
{
RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
Set all possible values for the Oscillator type parameter
if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
{
RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
}if ((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP) { ... }
else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
{
RCC_OscInitStruct->HSEState = RCC_HSE_ON;
}else if ((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON) { ... }
else
{
RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
}else { ... }
Get the HSE configuration
if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
{
RCC_OscInitStruct->HSIState = RCC_HSI_ON;
}if ((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION) { ... }
else
{
RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
}else { ... }
RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR &RCC_CR_HSITRIM) >> RCC_CR_HSITRIM_Pos);
Get the HSI configuration
if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
{
RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
}if ((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP) { ... }
else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
{
RCC_OscInitStruct->LSEState = RCC_LSE_ON;
}else if ((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON) { ... }
else
{
RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
}else { ... }
Get the LSE configuration
if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
{
RCC_OscInitStruct->LSIState = RCC_LSI_ON;
}if ((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION) { ... }
else
{
RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
}else { ... }
Get the LSI configuration
if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
{
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
}if ((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON) { ... }
else
{
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
}else { ... }
RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
RCC_OscInitStruct->PLL.PLLM = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
RCC_OscInitStruct->PLL.PLLN = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos);
RCC_OscInitStruct->PLL.PLLP = (uint32_t)((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) + RCC_PLLCFGR_PLLP_0) << 1U) >> RCC_PLLCFGR_PLLP_Pos);
RCC_OscInitStruct->PLL.PLLQ = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLQ) >> RCC_PLLCFGR_PLLQ_Pos);
}{ ... }
/* ... */
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
{
RCC_ClkInitStruct->ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
Set all possible values for the Clock type parameter
RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
Get the SYSCLK configuration
RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_HPRE);
Get the HCLK configuration
RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1);
Get the APB1 configuration
RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3U);
Get the APB2 configuration
*pFLatency = (uint32_t)(FLASH->ACR & FLASH_ACR_LATENCY);
}{ ... }
/* ... */
void HAL_RCC_NMI_IRQHandler(void)
{
if(__HAL_RCC_GET_IT(RCC_IT_CSS))
{
HAL_RCC_CSSCallback();
__HAL_RCC_CLEAR_IT(RCC_IT_CSS);
}if (__HAL_RCC_GET_IT(RCC_IT_CSS)) { ... }
}{ ... }
/* ... */
__weak void HAL_RCC_CSSCallback(void)
{
/* ... */
}{ ... }
/* ... */
/* ... */
/* ... */
#endif
/* ... */
/* ... */