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
|
////////////////////////////////////////////////////////////////////////////////
/// @file hal_rcc.c
/// @author AE TEAM
/// @brief THIS FILE PROVIDES ALL THE RCC FIRMWARE FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>© COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////
// Define to prevent recursive inclusion
#define _HAL_RCC_C_
// Files includes
#include "mm32_reg.h"
#include "hal_rcc.h"
u8 tbPresc[] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Hardware_Abstract_Layer
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup RCC_HAL
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup RCC_Exported_Functions
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @brief Resets the RCC clock configuration to default state.
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_DeInit()
{
SET_BIT(RCC->CR, RCC_CR_HSION);
CLEAR_BIT(RCC->CFGR, RCC_CFGR_SW);
CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON | RCC_CR_PLLON );
CLEAR_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLL_DN | RCC_PLLCFGR_PLL_DP);
CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
CLEAR_REG(RCC->CFGR);
CLEAR_REG(RCC->CIR);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the External High Speed oscillator (HSE).
/// @param state: specifies the new state of HSE.
/// This parameter can be one of the following values:
/// @arg RCC_HSE_OFF: HSE oscillator OFF
/// @arg RCC_HSE_ON: HSE oscillator ON
/// @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_HSEConfig(RCCHSE_TypeDef state)
{
RCC->CR &= ~(RCC_CR_HSEBYP | RCC_CR_HSEON);
switch (state) {
case RCC_HSE_Bypass:
RCC->CR |= RCC_CR_HSEBYP;
RCC->CR |= RCC_CR_HSEON;
break;
case RCC_HSE_ON:
RCC->CR |= RCC_CR_HSEON;
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Checks whether the specified RCC flag is set or not.
/// @param flag: specifies the flag to check.
/// This parameter can be one of the following values:
/// @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
/// @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
/// @arg RCC_FLAG_PLLRDY: PLL clock ready
/// @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
/// @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
/// @arg RCC_FLAG_PINRST: Pin reset
/// @arg RCC_FLAG_PORRST: POR/PDR reset
/// @arg RCC_FLAG_SFTRST: Software reset
/// @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
/// @arg RCC_FLAG_WWDGRST: Window Watchdog reset
/// @arg RCC_FLAG_LPWRRST: Low Power reset
/// @retval The new state of flag (SET or RESET).
////////////////////////////////////////////////////////////////////////////////
FlagStatus RCC_GetFlagStatus(RCC_FLAG_TypeDef flag)
{
return ((((flag >> 5) == CR_REG_INDEX) ? RCC->CR : (((flag >> 5) == BDCR_REG_INDEX) ? RCC->BDCR : RCC->CSR)) &
(1 << (flag & 0x1F)))
? SET : RESET;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Waits for HSE start-up.
/// @param None.
/// @retval An ErrorStatus enumuration value:
/// - SUCCESS: HSE oscillator is stable and ready to use
/// - ERROR: HSE oscillator not yet ready
////////////////////////////////////////////////////////////////////////////////
ErrorStatus RCC_WaitForHSEStartUp(void)
{
u32 StartUpCounter = 0;
FlagStatus HSEStatus;
do {
HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);
StartUpCounter++;
} while ((HSEStatus == RESET) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
return (ErrorStatus)(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET) ? SUCCESS : ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Waits for flag start-up.
/// @param flag: specifies the flag to check.
/// This parameter can be one of the following values:
/// @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
/// @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
/// @arg RCC_FLAG_PLLRDY: PLL clock ready
/// @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
/// @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
/// @arg RCC_FLAG_PINRST: Pin reset
/// @arg RCC_FLAG_PORRST: POR/PDR reset
/// @arg RCC_FLAG_SFTRST: Software reset
/// @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
/// @arg RCC_FLAG_WWDGRST: Window Watchdog reset
/// @retval An ErrorStatus enumuration value:
/// - SUCCESS: HSE oscillator is stable and ready to use
/// - ERROR: HSE oscillator not yet ready
////////////////////////////////////////////////////////////////////////////////
ErrorStatus RCC_WaitForFlagStartUp(RCC_FLAG_TypeDef flag)
{
u32 StartUpCounter = 0;
while (RCC_GetFlagStatus(flag) == RESET) {
if (StartUpCounter++ > HSE_STARTUP_TIMEOUT) {
return ERROR;
}
}
return SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Internal High Speed oscillator (HSI).
/// @param state: new state of the HSI.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_HSICmd(FunctionalState state)
{
MODIFY_REG(RCC->CR, RCC_CR_HSION, (state << RCC_CR_HSION_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the system clock (SYSCLK).
/// @param sys_clk_source: specifies the clock source used as system
/// clock. This parameter can be one of the following values:
/// @arg RCC_HSI: specifies HSI as system clock
/// @arg RCC_HSE: specifies HSE as system clock
/// @arg RCC_PLL: specifies PLL as system clock
/// @arg RCC_LSI: specifies LSI as system clock
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_SYSCLKConfig(SYSCLK_TypeDef sys_clk_source)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (sys_clk_source << RCC_CFGR_SW_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the PLL clock source and DM DN factor.
/// This function must be used only when the PLL is disabled.
/// @param plldn: specifies the PLL multiplication factor.
/// This parameter can be RCC_PLLMul_x where x:[31:26]
/// @param plldm: specifies the PLL Divsior factor.
/// This parameter can be RCC_Divsior_x where x:[22:20]
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_PLLDMDNConfig(u32 plldn, u32 plldm)
{
MODIFY_REG(RCC->PLLCFGR, (RCC_PLLCFGR_PLL_DN | RCC_PLLCFGR_PLL_DP), ((plldn << RCC_PLLCFGR_PLL_DN_Pos) | (plldm << RCC_PLLCFGR_PLL_DP_Pos)));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the PLL.
/// The PLL can not be disabled if it is used as system clock.
/// @param state: new state of the PLL.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_PLLCmd(FunctionalState state)
{
MODIFY_REG(RCC->CR, RCC_CR_PLLON, (state << RCC_CR_PLLON_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the PLL clock source and multiplication factor.
/// This function must be used only when the PLL is disabled.
/// @param pll_src: specifies the PLL entry clock source.
/// This parameter can be one of the following values:
/// @arg RCC_HSI_Div4: HSI oscillator clock divided
/// by 4 selected as PLL clock entry
/// @arg RCC_HSE_Div1: HSE oscillator clock selected
/// as PLL clock entry
/// @arg RCC_HSE_Div2: HSE oscillator clock divided
/// by 2 selected as PLL clock entry
/// @param pll_mul: specifies the PLL multiplication factor.
/// This parameter can be RCC_PLLMul_x where x:[31:26][22:20]
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_PLLConfig(RCC_PLLSource_TypeDef pll_src, RCC_PLLMul_TypeDef pll_mul)
{
const u8 DNDM_Item[] = {0x07, 0x03, 0x05, 0x01, 0x07, 0x01, 0x09, 0x01, // Frclk*8/4 ; Frclk*6/2 ; Frclk*8/2 ; Frclk*10/2;
0x0B, 0x01, 0x0D, 0x01, 0x0F, 0x01, 0x11, 0x01, // Frclk*12/2; Frclk*14/2; Frclk*16/2; Frclk*18/2;
0x13, 0x01, 0x15, 0x01, 0x17, 0x01, 0x19, 0x01, // Frclk*20/2; Frclk*22/2; Frclk*24/2; Frclk*26/2;
0x1B, 0x01, 0x1D, 0x01, 0x1F, 0x01
}; // Frclk*28/2; Frclk*30/2; // Frclk*32/2;
MODIFY_REG(RCC->PLLCFGR, (RCC_PLLCFGR_PLLXTPRE | RCC_PLLCFGR_PLLSRC), pll_src);
RCC_PLLDMDNConfig((u32)DNDM_Item[pll_mul >> 17], (u32)DNDM_Item[(pll_mul >> 17) + 1]);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the USB clock (USBCLK).
/// @param usb_clk_src: specifies the USB clock source.
/// This clock is derived from the PLL output.
/// This parameter can be one of the following values:
/// @arg RCC_USBCLKSource_PLLCLK_Div1: PLL clock selected as USB clock source
/// @arg RCC_USBCLKSource_PLLCLK_Div2: PLL clock divided by 2 selected as USB
/// clock source
/// @arg RCC_USBCLKSource_PLLCLK_Div3: PLL clock divided by 3 selected as USB
/// clock source
/// @arg RCC_USBCLKSource_PLLCLK_Div4: PLL clock divided by 4 selected as USB
/// clock source
/// @arg RCC_USBCLKSource_PLLCLK_Div5: PLL clock divided by 5 selected as USB
/// clock source
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_USBCLKConfig(RCC_USBCLKSOURCE_TypeDef usb_clk_src)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_USBPRE, (usb_clk_src << RCC_CFGR_USBPRE_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the clock source used as system clock.
/// @param None.
/// @retval The clock source used as system clock. The returned value can
/// be one of the following:
/// - 0x00: HSI/6 used as system clock
/// - 0x04: HSE used as system clock
/// - 0x08: PLL used as system clock
////////////////////////////////////////////////////////////////////////////////
u8 RCC_GetSYSCLKSource(void)
{
return ((u8)READ_BIT(RCC->CFGR, RCC_CFGR_SWS));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the AHB clock (hclk).
/// @param sys_clk: defines the AHB clock divider. This clock is derived
/// from the system clock (SYSCLK).
/// This parameter can be one of the following values:
/// @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK
/// @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2
/// @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4
/// @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8
/// @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16
/// @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64
/// @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128
/// @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256
/// @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_HCLKConfig(RCC_AHB_CLK_TypeDef sys_clk)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, sys_clk);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the Low Speed APB clock (pclk1).
/// @param hclk: defines the APB1 clock divider. This clock is derived from
/// the AHB clock (hclk).
/// This parameter can be one of the following values:
/// @arg RCC_HCLK_Div1: APB1 clock = hclk
/// @arg RCC_HCLK_Div2: APB1 clock = hclk/2
/// @arg RCC_HCLK_Div4: APB1 clock = hclk/4
/// @arg RCC_HCLK_Div8: APB1 clock = hclk/8
/// @arg RCC_HCLK_Div16: APB1 clock = hclk/16
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_PCLK1Config(RCC_APB1_APB2_CLK_TypeDef hclk)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, hclk);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the High Speed APB clock (pclk2).
/// @param hclk: defines the APB2 clock divider. This clock is derived from
/// the AHB clock (hclk).
/// This parameter can be one of the following values:
/// @arg RCC_HCLK_Div1: APB2 clock = hclk
/// @arg RCC_HCLK_Div2: APB2 clock = hclk/2
/// @arg RCC_HCLK_Div4: APB2 clock = hclk/4
/// @arg RCC_HCLK_Div8: APB2 clock = hclk/8
/// @arg RCC_HCLK_Div16: APB2 clock = hclk/16
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_PCLK2Config(RCC_APB1_APB2_CLK_TypeDef hclk)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (hclk << 3));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the ADC clock (ADCCLK).
/// @param pclk2: defines the ADC clock divider. This clock is derived from
/// the APB2 clock (pclk2).
/// This parameter can be one of the following values:
/// @arg RCC_PCLK2_Div2: ADC clock = pclk2/2
/// @arg RCC_PCLK2_Div4: ADC clock = pclk2/4
/// @arg RCC_PCLK2_Div6: ADC clock = pclk2/6
/// @arg RCC_PCLK2_Div8: ADC clock = pclk2/8
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ADCCLKConfig(RCC_ADCCLKSOURCE_TypeDef pclk2)
{
MODIFY_REG(RCC->CFGR, ADC_CFGR_PRE, pclk2);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the External Low Speed oscillator (LSE).
/// @param state: specifies the new state of the LSE.
/// This parameter can be one of the following values:
/// @arg RCC_LSE_OFF: LSE oscillator OFF
/// @arg RCC_LSE_ON: LSE oscillator ON
/// @arg RCC_LSE_Bypass: LSE oscillator bypassed with external
/// clock
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_LSEConfig(RCC_LSE_TypeDef state)
{
RCC->BDCR &= ~(RCC_BDCR_LSEBYP | RCC_BDCR_LSEON);
switch (state) {
case RCC_LSE_Bypass:
RCC->BDCR |= RCC_BDCR_LSEBYP;
RCC->BDCR |= RCC_BDCR_LSEON;
break;
case RCC_LSE_ON:
RCC->BDCR |= RCC_BDCR_LSEON;
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the RTC clock (RTCCLK).
/// Once the RTC clock is selected it can be changed unless the
/// Backup domain is reset.
/// @param rtc_clk_src: specifies the RTC clock source.
/// This parameter can be one of the following values:
/// @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
/// @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
/// @arg RCC_RTCCLKSource_HSE_Div128: HSE clock divided by 128
/// selected as RTC clock
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_RTCCLKConfig(RCC_RTCCLKSOURCE_TypeDef rtc_clk_src)
{
MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, rtc_clk_src);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the RTC clock.
/// This function must be used only after the RTC clock was
/// selected using the RCC_RTCCLKConfig function.
/// @param state: new state of the RTC clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_RTCCLKCmd(FunctionalState state)
{
MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCEN, (state << RCC_BDCR_RTCEN_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Internal Low Speed oscillator (LSI).
/// LSI can not be disabled if the IWDG is running.
/// @param state: new state of the LSI.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_LSICmd(FunctionalState state)
{
// u32 j;
MODIFY_REG(RCC->CSR, RCC_CSR_LSION | RCC_CSR_LSIOENLV, RCC_CSR_LSIOENLV | (state << RCC_CSR_LSION_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the clock frequency of different on chip clocks.
/// @param None.
/// @retval sys_clk : System clock frequency
////////////////////////////////////////////////////////////////////////////////
u32 RCC_GetSysClockFreq(void)
{
u32 result;
u32 clock, mul, div;
switch (RCC->CFGR & RCC_CFGR_SWS) {
case RCC_CFGR_SWS_LSI:
result = LSI_VALUE;
break;
case RCC_CFGR_SWS_HSE:
result = HSE_VALUE;
break;
case RCC_CFGR_SWS_PLL:
clock = READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC) ? (READ_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLXTPRE) ? (HSE_VALUE >> 1) : HSE_VALUE)
: HSI_VALUE_PLL_ON;
mul = ((RCC->PLLCFGR & (u32)RCC_PLLCFGR_PLL_DN) >> RCC_PLLCFGR_PLL_DN_Pos) + 1;
div = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL_DP) >> RCC_PLLCFGR_PLL_DP_Pos) + 1;
result = clock * mul / div;
break;
default:
result = HSI_VALUE;
break;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the hclk frequency of different on chip clocks.
/// @param None.
/// @retval hclk frequency
////////////////////////////////////////////////////////////////////////////////
u32 RCC_GetHCLKFreq(void)
{
return (RCC_GetSysClockFreq() >> tbPresc[(RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos]);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the pclk1 frequency of different on chip clocks.
/// @param None.
/// @retval pclk1 frequency
////////////////////////////////////////////////////////////////////////////////
u32 RCC_GetPCLK1Freq(void)
{
return (RCC_GetHCLKFreq() >> tbPresc[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_Pos]);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the pclk2 frequency of different on chip clocks.
/// @param None.
/// @retval pclk2 frequency
////////////////////////////////////////////////////////////////////////////////
u32 RCC_GetPCLK2Freq(void)
{
return (RCC_GetHCLKFreq() >> tbPresc[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_Pos]);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the frequency of different on chip clocks.
/// @param clk: pointer to a RCC_ClocksTypeDef structure which
/// will hold the clocks frequency.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_GetClocksFreq(RCC_ClocksTypeDef* clk)
{
u8 tbADCPresc[] = {2, 4, 6, 8};
clk->SYSCLK_Frequency = RCC_GetSysClockFreq();
clk->HCLK_Frequency = RCC_GetHCLKFreq();
clk->PCLK1_Frequency = RCC_GetPCLK1Freq();
clk->PCLK2_Frequency = RCC_GetPCLK2Freq();
clk->ADCCLK_Frequency = clk->PCLK2_Frequency / tbADCPresc[(RCC->CFGR & ADC_CFGR_PRE) >> ADC_CFGR_PRE_Pos];
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the AHB peripheral clock.
/// @param ahb_periph: specifies the AHB peripheral to gates its clock.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHBPeriphClockCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHBENR |= ahb_periph) : (RCC->AHBENR &= ~ahb_periph);
}
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHB2PeriphClockCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHB2ENR |= ahb_periph) : (RCC->AHB2ENR &= ~ahb_periph);
}
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHB3PeriphClockCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHB3ENR |= ahb_periph) : (RCC->AHB3ENR &= ~ahb_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the High Speed APB (APB2) peripheral clock.
/// @param apb2_periph: specifies the APB2 peripheral to gates its
/// clock.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB2PeriphClockCmd(u32 apb2_periph, FunctionalState state)
{
(state) ? (RCC->APB2ENR |= apb2_periph) : (RCC->APB2ENR &= ~apb2_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Low Speed APB (APB1) peripheral clock.
/// @param apb1_periph: specifies the APB1 peripheral to gates its
/// clock.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB1PeriphClockCmd(u32 apb1_periph, FunctionalState state)
{
(state) ? (RCC->APB1ENR |= apb1_periph) : (RCC->APB1ENR &= ~apb1_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases High Speed APB (APB2) peripheral reset.
/// @param apb2_periph: specifies the APB2 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral reset.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB2PeriphResetCmd(u32 apb2_periph, FunctionalState state)
{
(state) ? (RCC->APB2RSTR |= apb2_periph) : (RCC->APB2RSTR &= ~apb2_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed APB (APB1) peripheral reset.
/// @param apb1_periph: specifies the APB1 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB1PeriphResetCmd(u32 apb1_periph, FunctionalState state)
{
(state) ? (RCC->APB1RSTR |= apb1_periph) : (RCC->APB1RSTR &= ~apb1_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed AHB peripheral reset.
/// @param ahb_periph: specifies the AHB peripheral to reset.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHBPeriphResetCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHBRSTR |= ahb_periph) : (RCC->AHBRSTR &= ~ahb_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed AHB2 peripheral reset.
/// @param ahb_periph: specifies the AHB peripheral to reset.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHB2PeriphResetCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHB2RSTR |= ahb_periph) : (RCC->AHB2RSTR &= ~ahb_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed AHB2 peripheral reset.
/// @param ahb_periph: specifies the AHB peripheral to reset.
/// This parameter can be any combination of the following values:
/// @param state: new state of the specified peripheral clock.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHB3PeriphResetCmd(u32 ahb_periph, FunctionalState state)
{
(state) ? (RCC->AHB3RSTR |= ahb_periph) : (RCC->AHB3RSTR &= ~ahb_periph);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases the Backup domain reset.
/// @param state: new state of the Backup domain reset.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_BackupResetCmd(FunctionalState state)
{
MODIFY_REG(RCC->BDCR, RCC_BDCR_BDRST, (state << RCC_BDCR_BDRST_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Clock Security System.
/// @param state: new state of the Clock Security System..
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ClockSecuritySystemCmd(FunctionalState state)
{
MODIFY_REG(RCC->CR, RCC_CR_CSSON, (state << RCC_CR_CSSON_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Selects the clock source to output on MCO pin.
/// @param mco_src: specifies the clock source to output.
/// This parameter can be one of the following values:
/// @arg RCC_MCO_NoClock: No clock selected
/// @arg RCC_MCO_LSI: LSI oscillator clock selected
/// @arg RCC_MCO_LSE: LSE oscillator clock selected
/// @arg RCC_MCO_SYSCLK: System clock selected
/// @arg RCC_MCO_HSI: HSI oscillator clock selected
/// @arg RCC_MCO_HSE: HSE oscillator clock selected
/// @arg RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_MCOConfig(RCC_MCO_TypeDef mco_src)
{
MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, mco_src);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Clears the RCC reset flags.
/// The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST,
/// RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST,
/// RCC_FLAG_LPWRRST
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ClearFlag(void)
{
SET_BIT(RCC->CSR, RCC_CSR_RMVF);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified RCC interrupts.
/// @param it: specifies the RCC interrupt sources to be enabled or
/// disabled.
/// This parameter can be any combination of the following values:
/// @arg RCC_IT_LSIRDY: LSI ready interrupt
/// @arg RCC_IT_LSERDY: LSE ready interrupt
/// @arg RCC_IT_HSIRDY: HSI ready interrupt
/// @arg RCC_IT_HSERDY: HSE ready interrupt
/// @arg RCC_IT_PLLRDY: PLL ready interrupt
/// @param state: new state of the specified RCC interrupts.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ITConfig(RCC_IT_TypeDef it, FunctionalState state)
{
(state) ? SET_BIT(RCC->CIR, it << RCC_CIR_LSIRDYIE_Pos) : CLEAR_BIT(RCC->CIR, it << RCC_CIR_LSIRDYIE_Pos);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Checks whether the specified RCC interrupt has occurred or not.
/// @param it: specifies the RCC interrupt source to check.
/// This parameter can be one of the following values:
/// @arg RCC_IT_LSIRDY: LSI ready interrupt
/// @arg RCC_IT_LSERDY: LSE ready interrupt
/// @arg RCC_IT_HSIRDY: HSI ready interrupt
/// @arg RCC_IT_HSERDY: HSE ready interrupt
/// @arg RCC_IT_PLLRDY: PLL ready interrupt
/// @arg RCC_IT_CSS: Clock Security System interrupt
/// @retval The new state of it (SET or RESET).
////////////////////////////////////////////////////////////////////////////////
ITStatus RCC_GetITStatus(RCC_IT_TypeDef it)
{
return (ITStatus)READ_BIT(RCC->CIR, (it << RCC_CIR_LSIRDYF_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Clears the RCC�?interrupt pending bits.
/// @param it: specifies the interrupt pending bit to clear.
/// This parameter can be any combination of the following values:
/// @arg RCC_IT_LSIRDY: LSI ready interrupt
/// @arg RCC_IT_LSERDY: LSE ready interrupt
/// @arg RCC_IT_HSIRDY: HSI ready interrupt
/// @arg RCC_IT_HSERDY: HSE ready interrupt
/// @arg RCC_IT_PLLRDY: PLL ready interrupt
/// @arg RCC_IT_CSS: Clock Security System interrupt
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ClearITPendingBit(u8 it)
{
SET_BIT(RCC->CIR, (it << RCC_CIR_LSIRDYC_Pos));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed APB (APB1) peripheral reset.
/// @param apb1_periph: specifies the APB1 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB1PeriphReset(u32 apb1_periph)
{
RCC->APB1RSTR |= apb1_periph;
RCC->APB1RSTR &= ~apb1_periph;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed APB (APB2) peripheral reset.
/// @param apb2_periph: specifies the APB2 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_APB2PeriphReset(u32 apb2_periph)
{
RCC->APB2RSTR |= apb2_periph;
RCC->APB2RSTR &= ~apb2_periph;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases High Speed AHB (AHB1) peripheral reset.
/// @param ahb1_periph: specifies the AHB1 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_AHBPeriphReset(u32 ahb1_periph)
{
RCC->AHBRSTR |= ahb1_periph;
RCC->AHBRSTR &= ~ahb1_periph;
}
////////////////////////////////////////////////////////////////////////////////
//
// New Function Interface
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases Low Speed APB (APB1) peripheral reset.
/// @param apb1_periph: specifies the APB1 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_APB1PeriphReset(u32 apb1_periph)
{
RCC->APB1RSTR |= apb1_periph;
RCC->APB1RSTR &= ~apb1_periph;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief
/// @param
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_BackupReset()
{
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases High Speed APB (APB2) peripheral reset.
/// @param apb2_periph: specifies the APB2 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_APB2PeriphReset(u32 apb2_periph)
{
RCC->APB2RSTR |= apb2_periph;
RCC->APB2RSTR &= ~apb2_periph;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Forces or releases High Speed AHB (AHB1) peripheral reset.
/// @param ahb1_periph: specifies the AHB1 peripheral to reset.
/// This parameter can be any combination of the following values:
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_AHBPeriphReset(u32 ahb1_periph)
{
RCC->AHBRSTR |= ahb1_periph;
RCC->AHBRSTR &= ~ahb1_periph;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Disable systick
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_SystickDisable()
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enable systick
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exRCC_SystickEnable(u32 sys_tick_period)
{
SysTick_Config(RCC_GetHCLKFreq() / 1000000 * sys_tick_period);
}
/*
(state) ? (RCC->AHBENR |= ahb_periph) : (RCC->AHBENR &= ~ahb_periph);
(state) ? (RCC->APB1ENR |= apb1_periph) : (RCC->APB1ENR &= ~apb1_periph);
(state) ? (RCC->APB2ENR |= apb2_periph) : (RCC->APB2ENR &= ~apb2_periph);
*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified ADC peripheral Clock.
/// @param peripheral:select the ADC peripheral.
/// @param state: new state of the ADC peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_ADC_ClockCmd(ADC_TypeDef* peripheral, FunctionalState state)
{
switch (*(vu32*)&peripheral) {
case ADC1_BASE:
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_ADC1) : (RCC->APB2ENR &= ~RCC_APB2ENR_ADC1);
break;
case ADC2_BASE:
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_ADC2) : (RCC->APB2ENR &= ~RCC_APB2ENR_ADC2);
break;
case ADC3_BASE:
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_ADC3) : (RCC->APB2ENR &= ~RCC_APB2ENR_ADC3);
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified BKP peripheral Clock.
/// @param peripheral:select the BKP peripheral.
/// @param state: new state of the BKP peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_BKP_ClockCmd(BKP_TypeDef* peripheral, FunctionalState state)
{
if(BKP == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_BKP) : (RCC->APB1ENR &= ~RCC_APB1ENR_BKP);
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_PWR) : (RCC->APB1ENR &= ~RCC_APB1ENR_PWR);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified CAN peripheral Clock.
/// @param peripheral:select the CAN peripheral.
/// @param state: new state of the CAN peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_CAN_ClockCmd(CAN_TypeDef* peripheral, FunctionalState state)
{
if(CAN1 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_CAN) : (RCC->APB1ENR &= ~RCC_APB1ENR_CAN);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified COMP peripheral Clock.
/// @param peripheral:select the COMP peripheral.
/// @param state: new state of the COMP peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_COMP_ClockCmd(COMP_TypeDef* peripheral, FunctionalState state)
{
if(COMP == peripheral) {
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_COMP) : (RCC->APB2ENR &= ~RCC_APB2ENR_COMP);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified CRC peripheral Clock.
/// @param peripheral:select the CRC peripheral.
/// @param state: new state of the CRC peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_CRC_ClockCmd(CRC_TypeDef* peripheral, FunctionalState state)
{
if(CRC == peripheral) {
(state) ? (RCC->AHBENR |= RCC_AHBENR_CRC) : (RCC->AHBENR &= ~RCC_AHBENR_CRC);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified DAC peripheral Clock.
/// @param peripheral:select the DAC peripheral.
/// @param state: new state of the DAC peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_DAC_ClockCmd(DAC_TypeDef* peripheral, FunctionalState state)
{
if(DAC == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_DAC) : (RCC->APB1ENR &= ~RCC_APB1ENR_DAC);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified DMA peripheral Clock.
/// @param peripheral:select the DMA peripheral.
/// @param state: new state of the DMA peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_DMA_ClockCmd(DMA_TypeDef* peripheral, FunctionalState state)
{
if(DMA1 == peripheral) {
(state) ? (RCC->AHBENR |= RCC_AHBENR_DMA1) : (RCC->AHBENR &= ~RCC_AHBENR_DMA1);
}
if(DMA2 == peripheral) {
(state) ? (RCC->AHBENR |= RCC_AHBENR_DMA2) : (RCC->AHBENR &= ~RCC_AHBENR_DMA2);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the specified GPIO peripheral Clock.
/// @param peripheral:select the GPIO peripheral.
/// @param state: new state of the GPIO peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_GPIO_ClockCmd(GPIO_TypeDef* peripheral, FunctionalState state)
{
switch (*(vu32*)&peripheral) {
case (u32)GPIOA:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOA) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOA);
break;
case (u32)GPIOB:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOB) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOB);
break;
case (u32)GPIOC:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOC) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOC);
break;
case (u32)GPIOD:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOD) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOD);
break;
case (u32)GPIOE:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOE) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOE);
break;
case (u32)GPIOF:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOF) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOF);
break;
case (u32)GPIOG:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOG) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOG);
break;
case (u32)GPIOH:
(state) ? (RCC->AHBENR |= RCC_AHBENR_GPIOH) : (RCC->AHBENR &= ~RCC_AHBENR_GPIOH);
break;
default:
break;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Deinitializes the uart peripheral registers to their
/// default reset values.
/// @param peripheral: Select the UART or the UART peripheral.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void RCC_UART_ClockCmd(UART_TypeDef* peripheral, FunctionalState state)
{
if(UART2 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART2) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART2);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART2);
}
if(UART1 == peripheral) {
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_UART1) : (RCC->APB2ENR &= ~RCC_APB2ENR_UART1);//exRCC_APB2PeriphReset(RCC_APB2ENR_UART1);
}
if(UART3 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART3) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART3);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART3);
}
if(UART4 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART4) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART4);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART4);
}
if(UART5 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART5) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART5);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART5);
}
if(UART6 == peripheral) {
(state) ? (RCC->APB2ENR |= RCC_APB2ENR_UART6) : (RCC->APB2ENR &= ~RCC_APB2ENR_UART6);//exRCC_APB2PeriphReset(RCC_APB2ENR_UART6);
}
if(UART7 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART7) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART7);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART7);
}
if(UART8 == peripheral) {
(state) ? (RCC->APB1ENR |= RCC_APB1ENR_UART8) : (RCC->APB1ENR &= ~RCC_APB1ENR_UART8);//exRCC_APB1PeriphReset(RCC_APB1ENR_UART8);
}
}
/// @}
/// @}
/// @}
|