summaryrefslogtreecommitdiff
path: root/bsp/apm32/libraries/APM32F4xx_Library/APM32F4xx_StdPeriphDriver/src/apm32f4xx_rcm.c
blob: eb8908a17eaab0ad02c070fd0468b1da0f883304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
/*!
 * @file        apm32f4xx_rcm.c
 *
 * @brief       This file provides all the RCM firmware functions
 *
 * @version     V1.0.2
 *
 * @date        2022-06-23
 *
 * @attention
 *
 *  Copyright (C) 2021-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be usefull and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

#include "apm32f4xx_rcm.h"

/** @addtogroup APM32F4xx_StdPeriphDriver
  @{
*/

/** @defgroup RCM_Driver
  * @brief RCM driver modules
  @{
*/

/** @defgroup RCM_Functions
  @{
*/

/*!
 * @brief     Resets the clock configuration to the default state
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_Reset(void)
{
    /* Open HSI clock */
    RCM->CTRL_B.HSIEN = BIT_SET;
    /* Clear CFG register */
    RCM->CFG = (uint32_t)0x00000000;
    /* Reset HSEON, CSSON, PLLON, PLLI2S bits */
    RCM->CTRL &= (uint32_t)0xEAF6FFFF;

    /* Reset PLL1CFG register */
    RCM->PLL1CFG = 0x24003010;
    /* Reset PLL2CFG register */
    RCM->PLL2CFG = 0x20003000;

    /* Reset HSEBCFG bit */
    RCM->CTRL_B.HSEBCFG = BIT_RESET;

    /* Disable all interrupts and clear pending bits */
    RCM->INT = 0x00000000;
}

/*!
 * @brief     Configs the HSE oscillator
 *
 * @param     state: state of the HSE
 *                   This parameter can be one of the following values:
 *                   @arg RCM_HSE_CLOSE  : Turn off the HSE oscillator
 *                   @arg RCM_HSE_OPEN   : Turn on the HSE oscillator
 *                   @arg RCM_HSE_BYPASS : HSE oscillator bypassed with external clock
 *
 * @retval    None
 *
 * @note      When HSE is not used directly or through the PLL as system clock, it can be stopped.
 */
void RCM_ConfigHSE(RCM_HSE_T state)
{
    /* Reset HSEEN bit */
    RCM->CTRL_B.HSEEN = BIT_RESET;

    /* Reset HSEBCFG bit */
    RCM->CTRL_B.HSEBCFG = BIT_RESET;

    if (state == RCM_HSE_OPEN)
    {
        RCM->CTRL_B.HSEEN = BIT_SET;
    }
    else if (state == RCM_HSE_BYPASS)
    {
        RCM->CTRL_B.HSEBCFG = BIT_SET;
        RCM->CTRL_B.HSEEN = BIT_SET;
    }
}

/*!
 * @brief     Waits for HSE to be ready
 *
 * @param     None
 *
 * @retval    SUCCESS: HSE oscillator is ready
 *            ERROR  : HSE oscillator is not ready
 */

uint8_t RCM_WaitHSEReady(void)
{
    __IO uint32_t cnt;

    for (cnt = 0; cnt < HSE_STARTUP_TIMEOUT; cnt++)
    {
        if (RCM->CTRL_B.HSERDYFLG == BIT_SET)
        {
            return SUCCESS;
        }
    }

    return ERROR;
}

/*!
 * @brief     Config HSI trimming value
 *
 * @param     HSITrim: HSI trimming value
 *                     This parameter must be a number between 0 and 0x1F.
 *
 * @retval    None
 */
void RCM_ConfigHSITrim(uint8_t HSITrim)
{
    RCM->CTRL_B.HSITRIM = HSITrim;
}

/*!
 * @brief     Enable the HSI
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_EnableHSI(void)
{
    RCM->CTRL_B.HSIEN = BIT_SET;
}

/*!
 * @brief     Disable the HSI
 *
 * @param     None
 *
 * @retval    None
 *
 * @note      When HSI is not used directly or through the PLL as system clock, it can be stopped.
 */

void RCM_DisableHSI(void)
{
    RCM->CTRL_B.HSIEN = BIT_RESET;
}

/*!
 * @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 RCM_LSE_CLOSE  : Close the LSE
 *                    @arg RCM_LSE_OPEN   : Open the LSE
 *                    @arg RCM_LSE_BYPASS : LSE bypass
 *
 * @retval    None
 */
void RCM_ConfigLSE(RCM_LSE_T state)
{
    RCM->BDCTRL_B.LSEEN = BIT_RESET;
    RCM->BDCTRL_B.LSEBCFG = BIT_RESET;

    if (state == RCM_LSE_OPEN)
    {
        RCM->BDCTRL_B.LSEEN = BIT_SET;
    }
    else if (state == RCM_LSE_BYPASS)
    {
        RCM->BDCTRL_B.LSEBCFG = BIT_SET;
        RCM->BDCTRL_B.LSEEN = BIT_SET;
    }
}

/*!
 * @brief     Enables the Internal Low Speed oscillator (LSI)
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_EnableLSI(void)
{
    RCM->CSTS_B.LSIEN = BIT_SET;
}

/*!
 * @brief     Disables the Internal Low Speed oscillator (LSI)
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_DisableLSI(void)
{
    RCM->CSTS_B.LSIEN = BIT_RESET;
}

/*!
 * @brief     Configures the main PLL clock source, multiplication and division factors
 *
 * @param     pllSelect: PLL entry clock source select
 *                       This parameter can be one of the following values:
 *                       @arg RCM_PLLSEL_HSI: HSI oscillator clock selected as PLL clock entry
 *                       @arg RCM_PLLSEL_HSE: HSE oscillator clock selected as PLL clock entry
 *
 * @param     inputDiv: specifies the Division factor for PLL VCO input clock
 *                      This parameter must be a number between 0 and 63
 *
 * @param     vcoMul: specifies the Multiplication factor for PLL VCO output clock
 *                    This parameter must be a number between 50 and 432
 *
 * @param     sysDiv: specifies the Division factor for main system clock (SYSCLK)
 *                    This parameter can be one of the following values:
 *                    @arg RCM_PLL_SYS_DIV_2 : system clock Division factor is 2
 *                    @arg RCM_PLL_SYS_DIV_4 : system clock Division factor is 4
 *                    @arg RCM_PLL_SYS_DIV_6 : system clock Division factor is 6
 *                    @arg RCM_PLL_SYS_DIV_8 : system clock Division factor is 8
 *
 * @param     appDiv: specifies the Division factor for OTG FS, SDIO and RNG clocks
 *                    This parameter must be a number between 4 and 15
 *
 * @retval    None
 */
void RCM_ConfigPLL1(uint32_t pllSelect, uint32_t inputDiv, uint32_t vcoMul,
                    RCM_PLL_SYS_DIV_T sysDiv, uint32_t appDiv)
{
    RCM->PLL1CFG_B.PLL1CLKS = pllSelect;
    RCM->PLL1CFG_B.PLLB = inputDiv;
    RCM->PLL1CFG_B.PLL1A = vcoMul;
    RCM->PLL1CFG_B.PLL1C = sysDiv;
    RCM->PLL1CFG_B.PLLD = appDiv;
}

/*!
 * @brief      Enables the PLL1
 *
 * @param      None
 *
 * @retval     None
 */
void RCM_EnablePLL1(void)
{
    RCM->CTRL_B.PLL1EN = BIT_SET;
}

/*!
 * @brief      Disable the PLL
 *
 * @param      None
 *
 * @retval     None
 *
 * @note       When PLL1 is not used as system clock, it can be stopped.
 */
void RCM_DisablePLL1(void)
{
    RCM->CTRL_B.PLL1EN = BIT_RESET;
}

/*!
 * @brief     Configures the RCM_PLL2CFG register
 *
 * @param     i2sVcoMul: specifies the multiplication factor for PLLI2S VCO output clock
 *                       This parameter must be a number between 50 and 432
 *
 * @param     i2sDiv: specifies the division factor for I2S clock
 *                    This parameter must be a number between 2 and 7
 *
 * @retval    None
 */
void RCM_ConfigPLL2(uint32_t i2sVcoMul, uint32_t i2sDiv)
{
    RCM->PLL2CFG_B.PLL2A = i2sVcoMul;
    RCM->PLL2CFG_B.PLL2C = i2sDiv;
}

/*!
 * @brief      Enables the PLL2
 *
 * @param      None
 *
 * @retval     None
 */
void RCM_EnablePLL2(void)
{
    RCM->CTRL_B.PLL2EN = BIT_SET;
}

/*!
 * @brief      Disable the PLL2
 *
 * @param      None
 *
 * @retval     None
 */
void RCM_DisablePLL2(void)
{
    RCM->CTRL_B.PLL2EN = BIT_RESET;
}

/*!
 * @brief     Enable the Clock Security System
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_EnableCSS(void)
{
    RCM->CTRL_B.CSSEN = BIT_SET;
}

/*!
 * @brief     Disable the Clock Security System
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_DisableCSS(void)
{
    RCM->CTRL_B.CSSEN = BIT_RESET;
}

/*!
 * @brief     Selects the clock source to output on MCO1 pin
 *
 * @param     mco1Div: specifies the clock source to output
 *                     This parameter can be one of the following values:
 *                     @arg RCM_MCO1_SEL_HSICLK : HSI clock selected as MCO1 source
 *                     @arg RCM_MCO1_SEL_LSECLK : LSE clock selected as MCO1 source
 *                     @arg RCM_MCO1_SEL_HSECLK : HSE clock selected as MCO1 source
 *                     @arg RCM_MCO1_SEL_PLLCLK : main PLL clock selected as MCO1 source
 *
 * @param     mco1Div: specifies the MCO1 prescaler
 *                     This parameter can be one of the following values:
 *                     @arg RCM_MCO1_DIV_1 : no division applied to MCO1 clock
 *                     @arg RCM_MCO1_DIV_2 : division by 2 applied to MCO1 clock
 *                     @arg RCM_MCO1_DIV_3 : division by 3 applied to MCO1 clock
 *                     @arg RCM_MCO1_DIV_4 : division by 4 applied to MCO1 clock
 *                     @arg RCM_MCO1_DIV_5 : division by 5 applied to MCO1 clock
 *
 * @retval    None
 */
void RCM_ConfigMCO1(RCM_MCO1_SEL_T mco1Select, RCM_MCO1_DIV_T mco1Div)
{
    RCM->CFG_B.MCO1SEL = mco1Select;
    RCM->CFG_B.MCO1PRE = mco1Div;
}

/*!
 * @brief     Selects the clock source to output on MCO2 pin
 *
 * @param     mco2Select: specifies the clock source to output
 *                        This parameter can be one of the following values:
 *                        @arg RCM_MCO2_SEL_SYSCLK  : SYS clock selected as MCO2 source
 *                        @arg RCM_MCO2_SEL_PLL2CLK : PLL2 clock selected as MCO2 source
 *                        @arg RCM_MCO2_SEL_HSECLK  : HSE clock selected as MCO2 source
 *                        @arg RCM_MCO2_SEL_PLLCLK  : PLL clock selected as MCO2 source
 *
 * @param     mco2Div: specifies the MCO2 prescaler
 *                     This parameter can be one of the following values:
 *                     @arg RCM_MCO2_DIV_1 : no division applied to MCO2 clock
 *                     @arg RCM_MCO2_DIV_2 : division by 2 applied to MCO2 clock
 *                     @arg RCM_MCO2_DIV_3 : division by 3 applied to MCO2 clock
 *                     @arg RCM_MCO2_DIV_4 : division by 4 applied to MCO2 clock
 *                     @arg RCM_MCO2_DIV_5 : division by 5 applied to MCO2 clock
 *
 * @retval    None
 */
void RCM_ConfigMCO2(RCM_MCO2_SEL_T mco2Select, RCM_MCO2_DIV_T mco2Div)
{
    RCM->CFG_B.MCO2SEL = mco2Select;
    RCM->CFG_B.MCO2PRE = mco2Div;
}

/*!
 * @brief    Configures the system clock source
 *
 * @param    sysClkSelect: specifies the clock source used as system clock
 *                         This parameter can be one of the following values:
 *                         @arg RCM_SYSCLK_SEL_HSI : HSI is selected as system clock source
 *                         @arg RCM_SYSCLK_SEL_HSE : HSE is selected as system clock source
 *                         @arg RCM_SYSCLK_SEL_PLL : PLL is selected as system clock source
 *
 * @retva    None
 */
void RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_T sysClkSelect)
{
    RCM->CFG_B.SCLKSEL = sysClkSelect;
}

/*!
 * @brief     Returns the clock source which is used as system clock
 *
 * @param     None
 *
 * @retval    The clock source used as system clock
 */
RCM_SYSCLK_SEL_T RCM_ReadSYSCLKSource(void)
{
    return (RCM_SYSCLK_SEL_T)RCM->CFG_B.SCLKSWSTS;
}

/*!
 * @brief     Configs the AHB clock prescaler.
 *
 * @param     AHBDiv : Specifies the AHB clock prescaler from the system clock.
 *                     This parameter can be one of the following values:
 *                     @arg RCM_AHB_DIV_1   : HCLK = SYSCLK
 *                     @arg RCM_AHB_DIV_2   : HCLK = SYSCLK / 2
 *                     @arg RCM_AHB_DIV_4   : HCLK = SYSCLK / 4
 *                     @arg RCM_AHB_DIV_8   : HCLK = SYSCLK / 8
 *                     @arg RCM_AHB_DIV_16  : HCLK = SYSCLK / 16
 *                     @arg RCM_AHB_DIV_64  : HCLK = SYSCLK / 64
 *                     @arg RCM_AHB_DIV_128 : HCLK = SYSCLK / 128
 *                     @arg RCM_AHB_DIV_256 : HCLK = SYSCLK / 256
 *                     @arg RCM_AHB_DIV_512 : HCLK = SYSCLK / 512
 *
 * @retval    None
 */
void RCM_ConfigAHB(RCM_AHB_DIV_T AHBDiv)
{
    RCM->CFG_B.AHBPSC = AHBDiv;
}

/*!
 * @brief     Configs the APB1 clock prescaler.
 *
 * @param     APB1Div: Specifies the APB1 clock prescaler from the AHB clock.
 *                     This parameter can be one of the following values:
 *                     @arg RCM_APB_DIV_1  : PCLK1 = HCLK
 *                     @arg RCM_APB_DIV_2  : PCLK1 = HCLK / 2
 *                     @arg RCM_APB_DIV_4  : PCLK1 = HCLK / 4
 *                     @arg RCM_APB_DIV_8  : PCLK1 = HCLK / 8
 *                     @arg RCM_APB_DIV_16 : PCLK1 = HCLK / 16
 *
 * @retval    None
 */
void RCM_ConfigAPB1(RCM_APB_DIV_T APB1Div)
{
    RCM->CFG_B.APB1PSC = APB1Div;
}

/*!
 * @brief     Configs the APB2 clock prescaler
 *
 * @param     APB2Div: Specifies the APB2 clock prescaler from the AHB clock.
 *                     This parameter can be one of the following values:
 *                     @arg RCM_APB_DIV_1  : PCLK2 = HCLK
 *                     @arg RCM_APB_DIV_2  : PCLK2 = HCLK / 2
 *                     @arg RCM_APB_DIV_4  : PCLK2 = HCLK / 4
 *                     @arg RCM_APB_DIV_8  : PCLK2 = HCLK / 8
 *                     @arg RCM_APB_DIV_16 : PCLK2 = HCLK / 16
 *
 * @retval    None
 */
void RCM_ConfigAPB2(RCM_APB_DIV_T APB2Div)
{
    RCM->CFG_B.APB2PSC = APB2Div;
}

/*!
 * @brief     Configs the SDRAM clock prescaler
 *
 * @param     SDRAMDiv: Specifies the SDRAM clock prescaler from the DMC clock.
 *                     This parameter can be one of the following values:
 *                     @arg RCM_SDRAM_DIV_1 : SDRAM clock = DMC clock
 *                     @arg RCM_SDRAM_DIV_2 : SDRAM clock = DMC clock / 2
 *                     @arg RCM_SDRAM_DIV_4 : SDRAM clock = DMC clock / 4
 *
 * @retval    None
 */
void RCM_ConfigSDRAM(RCM_SDRAM_DIV_T SDRAMDiv)
{
    RCM->CFG_B.SDRAMPSC = SDRAMDiv;
}

/*!
 * @brief     Reads the frequency of SYSCLK
 *
 * @param     None
 *
 * @retval    Return the frequency of SYSCLK
 */
uint32_t RCM_ReadSYSCLKFreq(void)
{
    uint32_t sysClock, pllMull, pllSource, pllvco;

    /* get sys clock */
    sysClock = RCM->CFG_B.SCLKSWSTS;

    switch (sysClock)
    {
    /* sys clock is HSI */
    case RCM_SYSCLK_SEL_HSI:
        sysClock = HSI_VALUE;
        break;

    /* sys clock is HSE */
    case RCM_SYSCLK_SEL_HSE:
        sysClock = HSE_VALUE;
        break;

    /* sys clock is PLL */
    case RCM_SYSCLK_SEL_PLL:
        pllMull = RCM->PLL1CFG_B.PLLB;
        pllSource = RCM->PLL1CFG_B.PLL1CLKS;

        /* PLL entry clock source is HSE */
        if (pllSource == BIT_SET)
        {
            /* HSE used as PLL clock source */
            pllvco = (HSE_VALUE / pllMull) * (RCM->PLL1CFG_B.PLL1A);
        }
        else
        {
            /* HSI used as PLL clock source */
            pllvco = (HSI_VALUE / pllMull) * (RCM->PLL1CFG_B.PLL1A);
        }

        sysClock = pllvco / ((RCM->PLL1CFG_B.PLL1C + 1) * 2);
        break;

    default:
        sysClock  = HSI_VALUE;
        break;
    }

    return sysClock;
}

/*!
 * @brief     Reads the frequency of HCLK(AHB)
 *
 * @param     None
 *
 * @retval    Return the frequency of HCLK
 */
uint32_t RCM_ReadHCLKFreq(void)
{
    uint32_t divider;
    uint32_t sysClk, hclk;
    uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};

    sysClk = RCM_ReadSYSCLKFreq();
    divider = AHBPrescTable[RCM->CFG_B.AHBPSC];
    hclk = sysClk >> divider;

    return hclk;
}

/*!
 * @brief     Reads the frequency of PCLK1 And PCLK2
 *
 * @param     PCLK1 : Return the frequency of PCLK1
 *
 * @param     PCLK1 : Return the frequency of PCLK2
 *
 * @retval    None
 */
void RCM_ReadPCLKFreq(uint32_t *PCLK1, uint32_t *PCLK2)
{
    uint32_t hclk, divider;
    uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};

    hclk = RCM_ReadHCLKFreq();

    if (PCLK1)
    {
        divider = APBPrescTable[RCM->CFG_B.APB1PSC];
        *PCLK1 = hclk >> divider;
    }

    if (PCLK2)
    {
        divider = APBPrescTable[RCM->CFG_B.APB2PSC];
        *PCLK2 = hclk >> divider;
    }
}

/*!
 * @brief     Configures the RTC clock source
 *
 * @param     rtcClkSelect : specifies the RTC clock source.
 *                           This parameter can be one of the following values:
 *                           @arg RCM_RTCCLK_LSE        : RTCCLK = LSE clock
 *                           @arg RCM_RTCCLK_LSI        : RTCCLK = LSI clock
 *                           @arg RCM_RTCCLK_HSE_DIVX   : X:[2:31]
 *
 * @retval    None
 */
void RCM_ConfigRTCCLK(RCM_RTCCLK_T rtcClkSelect)
{
    if (rtcClkSelect <= 1)
    {
        RCM->BDCTRL_B.RTCSRCSEL = (rtcClkSelect + 1);
    }

    else
    {
        RCM->BDCTRL_B.RTCSRCSEL = 3;
        RCM->CFG_B.RTCPSC = rtcClkSelect;
    }
}

/*!
 * @brief     Enables the RTC clock
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_EnableRTCCLK(void)
{
    RCM->BDCTRL_B.RTCCLKEN = BIT_SET;
}

/*!
 * @brief     Disables the RTC clock
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_DisableRTCCLK(void)
{
    RCM->BDCTRL_B.RTCCLKEN = BIT_RESET;
}
/*!
 * @brief     Enable the Backup domain reset
 *
 * @param     None
 *
 * @retval    None
 *
 * @note
 */
void RCM_EnableBackupReset(void)
{
    RCM->BDCTRL_B.BDRST = BIT_SET;
}

/*!
 * @brief     Disable the Backup domain reset
 *
 * @param     None
 *
 * @retval    None
 */
void RCM_DisableBackupReset(void)
{
    RCM->BDCTRL_B.BDRST = BIT_RESET;
}

/*!
 * @brief     Configures the I2S clock source (I2SCLK)
 *
 * @param     i2sClkSource: specifies the I2S clock source
 *                          This parameter can be one of the following values:
 *                          @arg RCM_I2S_CLK_PLLI2S : PLLI2S is selected as I2S clock source
 *                          @arg RCM_I2S_CLK_EXT    : EXT is selected as I2S clock source
 *
 * @retval    None
 */
void RCM_ConfigI2SCLK(RCM_I2S_CLK_T i2sClkSource)
{
    RCM->CFG_B.I2SSEL = i2sClkSource;
}

/*!
 * @brief    Enables AHB1 peripheral clock
 *
 * @param    AHB1Periph : Enable the specifies clock of AHB peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Enable GPIOA clock
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Enable GPIOB clock
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Enable GPIOC clock
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Enable GPIOD clock
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Enable GPIOE clock
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Enable GPIOF clock
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Enable GPIOG clock
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Enable GPIOI clock
 *                       @arg RCM_AHB1_PERIPH_CRC         : Enable CRC clock
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Enable BKPSRAM interface clock
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Enable CCM data RAM interface clock
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Enable DMA1 clock
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Enable DMA2 clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Enable Ethernet MAC clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Enable Ethernet Transmission clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Enable Ethernet Reception clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Enable Ethernet PTP clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Enable USB OTG HS clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Enable USB OTG HS ULPI clock
 *
 * @retval    None
 */
void RCM_EnableAHB1PeriphClock(uint32_t AHB1Periph)
{
    RCM->AHB1CLKEN |= AHB1Periph;
}

/*!
 * @brief    Disable AHB1 peripheral clock
 *
 * @param    AHB1Periph : Disable the specifies clock of AHB1 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Disable GPIOA clock
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Disable GPIOB clock
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Disable GPIOC clock
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Disable GPIOD clock
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Disable GPIOE clock
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Disable GPIOF clock
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Disable GPIOG clock
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Disable GPIOI clock
 *                       @arg RCM_AHB1_PERIPH_CRC         : Disable CRC clock
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Disable BKPSRAM interface clock
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Disable CCM data RAM interface clock
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Disable DMA1 clock
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Disable DMA2 clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Disable Ethernet MAC clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Disable Ethernet Transmission clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Disable Ethernet Reception clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Disable Ethernet PTP clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Disable USB OTG HS clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Disable USB OTG HS ULPI clock
 *
 * @retval    None
 */
void RCM_DisableAHB1PeriphClock(uint32_t AHB1Periph)
{
    RCM->AHB1CLKEN &= (uint32_t)~AHB1Periph;
}

/*!
 * @brief    Enables AHB2 peripheral clock
 *
 * @param    AHB2Periph : Enable the specifies clock of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Enable DCI clock
 *                       @arg RCM_AHB2_PERIPH_FPU       : Enable FPU clock
 *                       @arg RCM_AHB2_PERIPH_BN        : Enable BN clock
 *                       @arg RCM_AHB2_PERIPH_SM        : Enable SM clock
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Enable CRYP clock
 *                       @arg RCM_AHB2_PERIPH_HASH      : Enable HASH clock
 *                       @arg RCM_AHB2_PERIPH_RNG       : Enable RNG clock
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Enable OTG FS clock
 *
 * @retval    None
 */
void RCM_EnableAHB2PeriphClock(uint32_t AHB2Periph)
{
    RCM->AHB2CLKEN |= AHB2Periph;
}

/*!
 * @brief    Disable AHB2 peripheral clock
 *
 * @param    AHB2Periph : Disable the specifies clock of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Disable DCI clock
 *                       @arg RCM_AHB2_PERIPH_FPU       : Disable FPU clock
 *                       @arg RCM_AHB2_PERIPH_BN        : Disable BN clock
 *                       @arg RCM_AHB2_PERIPH_SM        : Disable SM clock
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Disable CRYP clock
 *                       @arg RCM_AHB2_PERIPH_HASH      : Disable HASH clock
 *                       @arg RCM_AHB2_PERIPH_RNG       : Disable RNG clock
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Disable OTG FS clock
 *
 * @retval    None
 */
void RCM_DisableAHB2PeriphClock(uint32_t AHB2Periph)
{
    RCM->AHB2CLKEN &= (uint32_t)~AHB2Periph;
}

/*!
 * @brief    Enable the Low Speed APB (APB1) peripheral clock
 *
 * @param    APB1Periph : Enable specifies clock of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Enable TMR2 clock
 *                        @arg RCM_APB1_PERIPH_TMR3   : Enable TMR3 clock
 *                        @arg RCM_APB1_PERIPH_TMR4   : Enable TMR4 clock
 *                        @arg RCM_APB1_PERIPH_TMR5   : Enable TMR5 clock
 *                        @arg RCM_APB1_PERIPH_TMR6   : Enable TMR6 clock
 *                        @arg RCM_APB1_PERIPH_TMR7   : Enable TMR7 clock
 *                        @arg RCM_APB1_PERIPH_TMR12  : Enable TMR12 clock
 *                        @arg RCM_APB1_PERIPH_TMR13  : Enable TMR13 clock
 *                        @arg RCM_APB1_PERIPH_TMR14  : Enable TMR14 clock
 *                        @arg RCM_APB1_PERIPH_WWDT   : Enable WWDT clock
 *                        @arg RCM_APB1_PERIPH_SPI2   : Enable SPI2 clock
 *                        @arg RCM_APB1_PERIPH_SPI3   : Enable SPI3 clock
 *                        @arg RCM_APB1_PERIPH_USART2 : Enable USART2 clock
 *                        @arg RCM_APB1_PERIPH_USART3 : Enable USART3 clock
 *                        @arg RCM_APB1_PERIPH_UART4  : Enable UART4 clock
 *                        @arg RCM_APB1_PERIPH_UART5  : Enable UART5 clock
 *                        @arg RCM_APB1_PERIPH_I2C1   : Enable I2C1 clock
 *                        @arg RCM_APB1_PERIPH_I2C2   : Enable I2C2 clock
 *                        @arg RCM_APB1_PERIPH_I2C3   : Enable I2C3 clock
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Enable FMPI2C1 clock
 *                        @arg RCM_APB1_PERIPH_CAN1   : Enable CAN1 clock
 *                        @arg RCM_APB1_PERIPH_CAN2   : Enable CAN2 clock
 *                        @arg RCM_APB1_PERIPH_PMU    : Enable PMU clock
 *                        @arg RCM_APB1_PERIPH_DAC    : Enable DAC clock
 *                        @arg RCM_APB1_PERIPH_UART7  : Enable UART7 clock
 *                        @arg RCM_APB1_PERIPH_UART8  : Enable UART8 clock
 *
 * @retval   None
 */
void RCM_EnableAPB1PeriphClock(uint32_t APB1Periph)
{
    RCM->APB1CLKEN |= APB1Periph;
}

/*!
 * @brief    Disable the Low Speed APB (APB1) peripheral clock
 *
 * @param    APB1Periph : Disable specifies clock of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Disable TMR2 clock
 *                        @arg RCM_APB1_PERIPH_TMR3   : Disable TMR3 clock
 *                        @arg RCM_APB1_PERIPH_TMR4   : Disable TMR4 clock
 *                        @arg RCM_APB1_PERIPH_TMR5   : Disable TMR5 clock
 *                        @arg RCM_APB1_PERIPH_TMR6   : Disable TMR6 clock
 *                        @arg RCM_APB1_PERIPH_TMR7   : Disable TMR7 clock
 *                        @arg RCM_APB1_PERIPH_TMR12  : Disable TMR12 clock
 *                        @arg RCM_APB1_PERIPH_TMR13  : Disable TMR13 clock
 *                        @arg RCM_APB1_PERIPH_TMR14  : Disable TMR14 clock
 *                        @arg RCM_APB1_PERIPH_WWDT   : Disable WWDT clock
 *                        @arg RCM_APB1_PERIPH_SPI2   : Disable SPI2 clock
 *                        @arg RCM_APB1_PERIPH_SPI3   : Disable SPI3 clock
 *                        @arg RCM_APB1_PERIPH_USART2 : Disable USART2 clock
 *                        @arg RCM_APB1_PERIPH_USART3 : Disable USART3 clock
 *                        @arg RCM_APB1_PERIPH_UART4  : Disable UART4 clock
 *                        @arg RCM_APB1_PERIPH_UART5  : Disable UART5 clock
 *                        @arg RCM_APB1_PERIPH_I2C1   : Disable I2C1 clock
 *                        @arg RCM_APB1_PERIPH_I2C2   : Disable I2C2 clock
 *                        @arg RCM_APB1_PERIPH_I2C3   : Disable I2C3 clock
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Disable FMPI2C1 clock
 *                        @arg RCM_APB1_PERIPH_CAN1   : Disable CAN1 clock
 *                        @arg RCM_APB1_PERIPH_CAN2   : Disable CAN2 clock
 *                        @arg RCM_APB1_PERIPH_PMU    : Disable PMU clock
 *                        @arg RCM_APB1_PERIPH_DAC    : Disable DAC clock
 *                        @arg RCM_APB1_PERIPH_UART7  : Disable UART7 clock
 *                        @arg RCM_APB1_PERIPH_UART8  : Disable UART8 clock
 *
 * @retval   None
 */
void RCM_DisableAPB1PeriphClock(uint32_t APB1Periph)
{
    RCM->APB1CLKEN &= (uint32_t)~APB1Periph;
}

/*!
 * @brief    Enable the High Speed APB (APB2) peripheral clock
 *
 * @param    APB2Periph : Enable specifies clock of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 clock
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 clock
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 clock
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 clock
 *                        @arg RCM_APB2_PERIPH_ADC1   : ADC1 clock
 *                        @arg RCM_APB2_PERIPH_ADC2   : ADC2 clock
 *                        @arg RCM_APB2_PERIPH_ADC3   : ADC3 clock
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO clock
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 clock
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 clock
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG clock
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 clock
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 clock
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 clock
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 clock
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 clock
 *
 * @retval   None
 */
void RCM_EnableAPB2PeriphClock(uint32_t APB2Periph)
{
    RCM->APB2CLKEN |= APB2Periph;
}

/*!
 * @brief    Disable the High Speed APB (APB2) peripheral clock
 *
 * @param    APB2Periph : Disable specifies clock of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 clock
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 clock
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 clock
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 clock
 *                        @arg RCM_APB2_PERIPH_ADC1   : ADC1 clock
 *                        @arg RCM_APB2_PERIPH_ADC2   : ADC2 clock
 *                        @arg RCM_APB2_PERIPH_ADC3   : ADC3 clock
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO clock
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 clock
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 clock
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG clock
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 clock
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 clock
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 clock
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 clock
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 clock
 *
 * @retval   None
 */
void RCM_DisableAPB2PeriphClock(uint32_t APB2Periph)
{
    RCM->APB2CLKEN &= (uint32_t)~APB2Periph;
}

/*!
 * @brief    Enables AHB1 peripheral reset
 *
 * @param    AHB1Periph : Enable the specifies reset of AHB peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Enable GPIOA reset
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Enable GPIOB reset
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Enable GPIOC reset
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Enable GPIOD reset
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Enable GPIOE reset
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Enable GPIOF reset
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Enable GPIOG reset
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Enable GPIOI reset
 *                       @arg RCM_AHB1_PERIPH_CRC         : Enable CRC reset
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Enable BKPSRAM interface reset
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Enable CCM data RAM interface reset
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Enable DMA1 reset
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Enable DMA2 reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Enable Ethernet MAC reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Enable Ethernet Transmission reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Enable Ethernet Reception reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Enable Ethernet PTP reset
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Enable USB OTG HS reset
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Enable USB OTG HS ULPI clock
 *
 * @retval    None
 */
void RCM_EnableAHB1PeriphReset(uint32_t AHB1Periph)
{
    RCM->AHB1RST |= AHB1Periph;
}

/*!
 * @brief    Disable AHB1 peripheral reset
 *
 * @param    AHB1Periph : Disable the specifies reset of AHB1 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Disable GPIOA reset
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Disable GPIOB reset
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Disable GPIOC reset
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Disable GPIOD reset
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Disable GPIOE reset
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Disable GPIOF reset
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Disable GPIOG reset
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Disable GPIOI reset
 *                       @arg RCM_AHB1_PERIPH_CRC         : Disable CRC reset
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Disable BKPSRAM interface reset
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Disable CCM data RAM interface reset
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Disable DMA1 reset
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Disable DMA2 reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Disable Ethernet MAC reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Disable Ethernet Transmission reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Disable Ethernet Reception reset
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Disable Ethernet PTP reset
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Disable USB OTG HS reset
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Disable USB OTG HS ULPI reset
 *
 * @retval    None
 */
void RCM_DisableAHB1PeriphReset(uint32_t AHB1Periph)
{
    RCM->AHB1RST &= (uint32_t)~AHB1Periph;
}

/*!
 * @brief    Enables AHB2 peripheral reset
 *
 * @param    AHB2Periph : Enable the specifies reset of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Enable DCI reset
 *                       @arg RCM_AHB2_PERIPH_FPU       : Enable FPU reset
 *                       @arg RCM_AHB2_PERIPH_BN        : Enable BN reset
 *                       @arg RCM_AHB2_PERIPH_SM        : Enable SM reset
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Enable CRYP reset
 *                       @arg RCM_AHB2_PERIPH_HASH      : Enable HASH reset
 *                       @arg RCM_AHB2_PERIPH_RNG       : Enable RNG reset
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Enable OTG FS reset
 *
 * @retval    None
 */
void RCM_EnableAHB2PeriphReset(uint32_t AHB2Periph)
{
    RCM->AHB2RST |= AHB2Periph;
}

/*!
 * @brief    Disable AHB2 peripheral reset
 *
 * @param    AHB2Periph : Disable the specifies reset of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Disable DCI reset
 *                       @arg RCM_AHB2_PERIPH_FPU       : Disable FPU reset
 *                       @arg RCM_AHB2_PERIPH_BN        : Disable BN reset
 *                       @arg RCM_AHB2_PERIPH_SM        : Disable SM reset
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Disable CRYP reset
 *                       @arg RCM_AHB2_PERIPH_HASH      : Disable HASH reset
 *                       @arg RCM_AHB2_PERIPH_RNG       : Disable RNG reset
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Disable OTG FS reset
 *
 * @retval    None
 */
void RCM_DisableAHB2PeriphReset(uint32_t AHB2Periph)
{
    RCM->AHB2RST &= (uint32_t)~AHB2Periph;
}

/*!
 * @brief    Enable the Low Speed APB (APB1) peripheral reset
 *
 * @param    APB1Periph : Enable specifies reset of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Enable TMR2 reset
 *                        @arg RCM_APB1_PERIPH_TMR3   : Enable TMR3 reset
 *                        @arg RCM_APB1_PERIPH_TMR4   : Enable TMR4 reset
 *                        @arg RCM_APB1_PERIPH_TMR5   : Enable TMR5 reset
 *                        @arg RCM_APB1_PERIPH_TMR6   : Enable TMR6 reset
 *                        @arg RCM_APB1_PERIPH_TMR7   : Enable TMR7 reset
 *                        @arg RCM_APB1_PERIPH_TMR12  : Enable TMR12 reset
 *                        @arg RCM_APB1_PERIPH_TMR13  : Enable TMR13 reset
 *                        @arg RCM_APB1_PERIPH_TMR14  : Enable TMR14 reset
 *                        @arg RCM_APB1_PERIPH_WWDT   : Enable WWDT reset
 *                        @arg RCM_APB1_PERIPH_SPI2   : Enable SPI2 reset
 *                        @arg RCM_APB1_PERIPH_SPI3   : Enable SPI3 reset
 *                        @arg RCM_APB1_PERIPH_USART2 : Enable USART2 reset
 *                        @arg RCM_APB1_PERIPH_USART3 : Enable USART3 reset
 *                        @arg RCM_APB1_PERIPH_UART4  : Enable UART4 reset
 *                        @arg RCM_APB1_PERIPH_UART5  : Enable UART5 reset
 *                        @arg RCM_APB1_PERIPH_I2C1   : Enable I2C1 reset
 *                        @arg RCM_APB1_PERIPH_I2C2   : Enable I2C2 reset
 *                        @arg RCM_APB1_PERIPH_I2C3   : Enable I2C3 reset
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Enable FMPI2C1 reset
 *                        @arg RCM_APB1_PERIPH_CAN1   : Enable CAN1 reset
 *                        @arg RCM_APB1_PERIPH_CAN2   : Enable CAN2 reset
 *                        @arg RCM_APB1_PERIPH_PMU    : Enable PMU reset
 *                        @arg RCM_APB1_PERIPH_DAC    : Enable DAC reset
 *                        @arg RCM_APB1_PERIPH_UART7  : Enable UART7 reset
 *                        @arg RCM_APB1_PERIPH_UART8  : Enable UART8 reset
 *
 * @retval   None
 */
void RCM_EnableAPB1PeriphReset(uint32_t APB1Periph)
{
    RCM->APB1RST |= APB1Periph;
}

/*!
 * @brief    Disable the Low Speed APB (APB1) peripheral reset
 *
 * @param    APB1Periph : Disable specifies reset of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Disable TMR2 reset
 *                        @arg RCM_APB1_PERIPH_TMR3   : Disable TMR3 reset
 *                        @arg RCM_APB1_PERIPH_TMR4   : Disable TMR4 reset
 *                        @arg RCM_APB1_PERIPH_TMR5   : Disable TMR5 reset
 *                        @arg RCM_APB1_PERIPH_TMR6   : Disable TMR6 reset
 *                        @arg RCM_APB1_PERIPH_TMR7   : Disable TMR7 reset
 *                        @arg RCM_APB1_PERIPH_TMR12  : Disable TMR12 reset
 *                        @arg RCM_APB1_PERIPH_TMR13  : Disable TMR13 reset
 *                        @arg RCM_APB1_PERIPH_TMR14  : Disable TMR14 reset
 *                        @arg RCM_APB1_PERIPH_WWDT   : Disable WWDT reset
 *                        @arg RCM_APB1_PERIPH_SPI2   : Disable SPI2 reset
 *                        @arg RCM_APB1_PERIPH_SPI3   : Disable SPI3 reset
 *                        @arg RCM_APB1_PERIPH_USART2 : Disable USART2 reset
 *                        @arg RCM_APB1_PERIPH_USART3 : Disable USART3 reset
 *                        @arg RCM_APB1_PERIPH_UART4  : Disable UART4 reset
 *                        @arg RCM_APB1_PERIPH_UART5  : Disable UART5 reset
 *                        @arg RCM_APB1_PERIPH_I2C1   : Disable I2C1 reset
 *                        @arg RCM_APB1_PERIPH_I2C2   : Disable I2C2 reset
 *                        @arg RCM_APB1_PERIPH_I2C3   : Disable I2C3 reset
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Disable FMPI2C1 reset
 *                        @arg RCM_APB1_PERIPH_CAN1   : Disable CAN1 reset
 *                        @arg RCM_APB1_PERIPH_CAN2   : Disable CAN2 reset
 *                        @arg RCM_APB1_PERIPH_PMU    : Disable PMU reset
 *                        @arg RCM_APB1_PERIPH_DAC    : Disable DAC reset
 *                        @arg RCM_APB1_PERIPH_UART7  : Disable UART7 reset
 *                        @arg RCM_APB1_PERIPH_UART8  : Disable UART8 reset
 *
 * @retval   None
 */
void RCM_DisableAPB1PeriphReset(uint32_t APB1Periph)
{
    RCM->APB1RST &= (uint32_t)~APB1Periph;
}

/*!
 * @brief    Enable the High Speed APB (APB2) peripheral reset
 *
 * @param    APB2Periph : Enable specifies reset of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 reset
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 reset
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 reset
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 reset
 *                        @arg RCM_APB2_PERIPH_ADC    : All of ADC reset
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO reset
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 reset
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 reset
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG reset
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 reset
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 reset
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 reset
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 reset
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 reset
 *
 * @retval   None
 */
void RCM_EnableAPB2PeriphReset(uint32_t APB2Periph)
{
    RCM->APB2RST |= APB2Periph;
}

/*!
 * @brief    Disable the High Speed APB (APB2) peripheral reset
 *
 * @param    APB2Periph : Disable specifies reset of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 reset
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 reset
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 reset
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 reset
 *                        @arg RCM_APB2_PERIPH_ADC1   : ADC1 reset
 *                        @arg RCM_APB2_PERIPH_ADC2   : ADC2 reset
 *                        @arg RCM_APB2_PERIPH_ADC3   : ADC3 reset
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO reset
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 reset
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 reset
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG reset
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 reset
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 reset
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 reset
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 reset
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 reset
 *
 * @retval   None
 */
void RCM_DisableAPB2PeriphReset(uint32_t APB2Periph)
{
    RCM->APB2RST &= (uint32_t)~APB2Periph;
}

/*!
 * @brief    Enables AHB1 peripheral clock during Low Power (Sleep) mode
 *
 * @param    AHB1Periph : Enable the specifies clock of AHB peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Enable GPIOA clock
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Enable GPIOB clock
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Enable GPIOC clock
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Enable GPIOD clock
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Enable GPIOE clock
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Enable GPIOF clock
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Enable GPIOG clock
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Enable GPIOI clock
 *                       @arg RCM_AHB1_PERIPH_CRC         : Enable CRC clock
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Enable BKPSRAM interface clock
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Enable CCM data RAM interface clock
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Enable DMA1 clock
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Enable DMA2 clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Enable Ethernet MAC clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Enable Ethernet Transmission clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Enable Ethernet Reception clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Enable Ethernet PTP clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Enable USB OTG HS clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Enable USB OTG HS ULPI clock
 *
 * @retval    None
 */
void RCM_EnableAHB1PeriphClockLPMode(uint32_t AHB1Periph)
{
    RCM->LPAHB1CLKEN |= AHB1Periph;
}

/*!
 * @brief    Disable AHB1 peripheral clock during Low Power (Sleep) mode
 *
 * @param    AHB1Periph : Disable the specifies clock of AHB1 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB1_PERIPH_GPIOA       : Disable GPIOA clock
 *                       @arg RCM_AHB1_PERIPH_GPIOB       : Disable GPIOB clock
 *                       @arg RCM_AHB1_PERIPH_GPIOC       : Disable GPIOC clock
 *                       @arg RCM_AHB1_PERIPH_GPIOD       : Disable GPIOD clock
 *                       @arg RCM_AHB1_PERIPH_GPIOE       : Disable GPIOE clock
 *                       @arg RCM_AHB1_PERIPH_GPIOF       : Disable GPIOF clock
 *                       @arg RCM_AHB1_PERIPH_GPIOG       : Disable GPIOG clock
 *                       @arg RCM_AHB1_PERIPH_GPIOI       : Disable GPIOI clock
 *                       @arg RCM_AHB1_PERIPH_CRC         : Disable CRC clock
 *                       @arg RCM_AHB1_PERIPH_BKPSRAM     : Disable BKPSRAM interface clock
 *                       @arg RCM_AHB1_PERIPH_CCMDATARAMEN: Disable CCM data RAM interface clock
 *                       @arg RCM_AHB1_PERIPH_DMA1        : Disable DMA1 clock
 *                       @arg RCM_AHB1_PERIPH_DMA2        : Disable DMA2 clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC     : Disable Ethernet MAC clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Tx  : Disable Ethernet Transmission clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_Rx  : Disable Ethernet Reception clock
 *                       @arg RCM_AHB1_PERIPH_ETH_MAC_PTP : Disable Ethernet PTP clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS      : Disable USB OTG HS clock
 *                       @arg RCM_AHB1_PERIPH_OTG_HS_ULPI : Disable USB OTG HS ULPI clock
 *
 * @retval    None
 */
void RCM_DisableAHB1PeriphClockLPMode(uint32_t AHB1Periph)
{
    RCM->LPAHB1CLKEN &= (uint32_t)~AHB1Periph;
}

/*!
 * @brief    Enables AHB2 peripheral clock during Low Power (Sleep) mode
 *
 * @param    AHB2Periph : Enable the specifies clock of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Enable DCI clock
 *                       @arg RCM_AHB2_PERIPH_FPU       : Enable FPU clock
 *                       @arg RCM_AHB2_PERIPH_BN        : Enable BN clock
 *                       @arg RCM_AHB2_PERIPH_SM        : Enable SM clock
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Enable CRYP clock
 *                       @arg RCM_AHB2_PERIPH_HASH      : Enable HASH clock
 *                       @arg RCM_AHB2_PERIPH_RNG       : Enable RNG clock
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Enable OTG FS clock
 *
 * @retval    None
 */
void RCM_EnableAHB2PeriphClockLPMode(uint32_t AHB2Periph)
{
    RCM->LPAHB2CLKEN |= AHB2Periph;
}

/*!
 * @brief    Disable AHB2 peripheral clock during Low Power (Sleep) mode
 *
 * @param    AHB2Periph : Disable the specifies clock of AHB2 peripheral
 *                       This parameter can be any combination of the following values:
 *                       @arg RCM_AHB2_PERIPH_DCI       : Disable DCI clock
 *                       @arg RCM_AHB2_PERIPH_FPU       : Disable FPU clock
 *                       @arg RCM_AHB2_PERIPH_BN        : Disable BN clock
 *                       @arg RCM_AHB2_PERIPH_SM        : Disable SM clock
 *                       @arg RCM_AHB2_PERIPH_CRYP      : Disable CRYP clock
 *                       @arg RCM_AHB2_PERIPH_HASH      : Disable HASH clock
 *                       @arg RCM_AHB2_PERIPH_RNG       : Disable RNG clock
 *                       @arg RCM_AHB2_PERIPH_OTG_FS    : Disable OTG FS clock
 *
 * @retval    None
 */
void RCM_DisableAHB2PeriphClockLPMode(uint32_t AHB2Periph)
{
    RCM->LPAHB2CLKEN &= (uint32_t)~AHB2Periph;
}

/*!
 * @brief    Enable the Low Speed APB (APB1) peripheral clock during Low Power (Sleep) mode
 *
 * @param    APB1Periph : Enable specifies clock of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Enable TMR2 clock
 *                        @arg RCM_APB1_PERIPH_TMR3   : Enable TMR3 clock
 *                        @arg RCM_APB1_PERIPH_TMR4   : Enable TMR4 clock
 *                        @arg RCM_APB1_PERIPH_TMR5   : Enable TMR5 clock
 *                        @arg RCM_APB1_PERIPH_TMR6   : Enable TMR6 clock
 *                        @arg RCM_APB1_PERIPH_TMR7   : Enable TMR7 clock
 *                        @arg RCM_APB1_PERIPH_TMR12  : Enable TMR12 clock
 *                        @arg RCM_APB1_PERIPH_TMR13  : Enable TMR13 clock
 *                        @arg RCM_APB1_PERIPH_TMR14  : Enable TMR14 clock
 *                        @arg RCM_APB1_PERIPH_WWDT   : Enable WWDT clock
 *                        @arg RCM_APB1_PERIPH_SPI2   : Enable SPI2 clock
 *                        @arg RCM_APB1_PERIPH_SPI3   : Enable SPI3 clock
 *                        @arg RCM_APB1_PERIPH_USART2 : Enable USART2 clock
 *                        @arg RCM_APB1_PERIPH_USART3 : Enable USART3 clock
 *                        @arg RCM_APB1_PERIPH_UART4  : Enable UART4 clock
 *                        @arg RCM_APB1_PERIPH_UART5  : Enable UART5 clock
 *                        @arg RCM_APB1_PERIPH_I2C1   : Enable I2C1 clock
 *                        @arg RCM_APB1_PERIPH_I2C2   : Enable I2C2 clock
 *                        @arg RCM_APB1_PERIPH_I2C3   : Enable I2C3 clock
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Enable FMPI2C1 clock
 *                        @arg RCM_APB1_PERIPH_CAN1   : Enable CAN1 clock
 *                        @arg RCM_APB1_PERIPH_CAN2   : Enable CAN2 clock
 *                        @arg RCM_APB1_PERIPH_PMU    : Enable PMU clock
 *                        @arg RCM_APB1_PERIPH_DAC    : Enable DAC clock
 *                        @arg RCM_APB1_PERIPH_UART7  : Enable UART7 clock
 *                        @arg RCM_APB1_PERIPH_UART8  : Enable UART8 clock
 *
 * @retval   None
 */
void RCM_EnableAPB1PeriphClockLPMode(uint32_t APB1Periph)
{
    RCM->LPAPB1CLKEN |= APB1Periph;
}

/*!
 * @brief    Disable the Low Speed APB (APB1) peripheral clock during Low Power (Sleep) mode
 *
 * @param    APB1Periph : Disable specifies clock of the APB1 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB1_PERIPH_TMR2   : Disable TMR2 clock
 *                        @arg RCM_APB1_PERIPH_TMR3   : Disable TMR3 clock
 *                        @arg RCM_APB1_PERIPH_TMR4   : Disable TMR4 clock
 *                        @arg RCM_APB1_PERIPH_TMR5   : Disable TMR5 clock
 *                        @arg RCM_APB1_PERIPH_TMR6   : Disable TMR6 clock
 *                        @arg RCM_APB1_PERIPH_TMR7   : Disable TMR7 clock
 *                        @arg RCM_APB1_PERIPH_TMR12  : Disable TMR12 clock
 *                        @arg RCM_APB1_PERIPH_TMR13  : Disable TMR13 clock
 *                        @arg RCM_APB1_PERIPH_TMR14  : Disable TMR14 clock
 *                        @arg RCM_APB1_PERIPH_WWDT   : Disable WWDT clock
 *                        @arg RCM_APB1_PERIPH_SPI2   : Disable SPI2 clock
 *                        @arg RCM_APB1_PERIPH_SPI3   : Disable SPI3 clock
 *                        @arg RCM_APB1_PERIPH_USART2 : Disable USART2 clock
 *                        @arg RCM_APB1_PERIPH_USART3 : Disable USART3 clock
 *                        @arg RCM_APB1_PERIPH_UART4  : Disable UART4 clock
 *                        @arg RCM_APB1_PERIPH_UART5  : Disable UART5 clock
 *                        @arg RCM_APB1_PERIPH_I2C1   : Disable I2C1 clock
 *                        @arg RCM_APB1_PERIPH_I2C2   : Disable I2C2 clock
 *                        @arg RCM_APB1_PERIPH_I2C3   : Disable I2C3 clock
 *                        @arg RCM_APB1_PERIPH_FMPI2C1: Disable FMPI2C1 clock
 *                        @arg RCM_APB1_PERIPH_CAN1   : Disable CAN1 clock
 *                        @arg RCM_APB1_PERIPH_CAN2   : Disable CAN2 clock
 *                        @arg RCM_APB1_PERIPH_PMU    : Disable PMU clock
 *                        @arg RCM_APB1_PERIPH_DAC    : Disable DAC clock
 *                        @arg RCM_APB1_PERIPH_UART7  : Disable UART7 clock
 *                        @arg RCM_APB1_PERIPH_UART8  : Disable UART8 clock
 *
 * @retval   None
 */
void RCM_DisableAPB1PeriphClockLPMode(uint32_t APB1Periph)
{
    RCM->LPAPB1CLKEN &= (uint32_t)~APB1Periph;
}

/*!
 * @brief    Enable the High Speed APB (APB2) peripheral clock during Low Power (Sleep) mode
 *
 * @param    APB2Periph : Enable specifies clock of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 clock
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 clock
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 clock
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 clock
 *                        @arg RCM_APB2_PERIPH_ADC1   : ADC1 clock
 *                        @arg RCM_APB2_PERIPH_ADC2   : ADC2 clock
 *                        @arg RCM_APB2_PERIPH_ADC3   : ADC3 clock
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO clock
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 clock
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 clock
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG clock
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 clock
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 clock
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 clock
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 clock
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 clock
 *
 * @retval   None
 */
void RCM_EnableAPB2PeriphClockLPMode(uint32_t APB2Periph)
{
    RCM->LPAPB2CLKEN |= APB2Periph;
}

/*!
 * @brief    Disable the High Speed APB (APB2) peripheral clock during Low Power (Sleep) mode
 *
 * @param    APB2Periph : Disable specifies clock of the APB2 peripheral.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_APB2_PERIPH_TMR1   : TMR1 clock
 *                        @arg RCM_APB2_PERIPH_TMR8   : TMR8 clock
 *                        @arg RCM_APB2_PERIPH_USART1 : USART1 clock
 *                        @arg RCM_APB2_PERIPH_USART6 : USART6 clock
 *                        @arg RCM_APB2_PERIPH_ADC1   : ADC1 clock
 *                        @arg RCM_APB2_PERIPH_ADC2   : ADC2 clock
 *                        @arg RCM_APB2_PERIPH_ADC3   : ADC3 clock
 *                        @arg RCM_APB2_PERIPH_SDIO   : SDIO clock
 *                        @arg RCM_APB2_PERIPH_SPI1   : SPI1 clock
 *                        @arg RCM_APB2_PERIPH_SPI4   : SPI4 clock
 *                        @arg RCM_APB2_PERIPH_SYSCFG : SYSCFG clock
 *                        @arg RCM_APB2_PERIPH_TMR9   : TMR9 clock
 *                        @arg RCM_APB2_PERIPH_TMR10  : TMR10 clock
 *                        @arg RCM_APB2_PERIPH_TMR11  : TMR11 clock
 *                        @arg RCM_APB2_PERIPH_SPI5   : SPI5 clock
 *                        @arg RCM_APB2_PERIPH_SPI6   : SPI6 clock
 *
 * @retval   None
 */
void RCM_DisableAPB2PeriphClockLPMode(uint32_t APB2Periph)
{
    RCM->LPAPB2CLKEN &= (uint32_t)~APB2Periph;
}

/*!
 * @brief     Enable RCM interrupts
 *
 * @param     interrupt : Enable specifies RCM interrupt sources.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_INT_LSIRDY  : LSI ready interrupt
 *                        @arg RCM_INT_LSERDY  : LSE ready interrupt
 *                        @arg RCM_INT_HSIRDY  : HSI ready interrupt
 *                        @arg RCM_INT_HSERDY  : HSE ready interrupt
 *                        @arg RCM_INT_PLL1RDY : PLL1 ready interrupt
 *                        @arg RCM_INT_PLL2RDY : PLL2 ready interrupt
 *
 * @retval    None
 */
void RCM_EnableInterrupt(uint32_t interrupt)
{
    uint32_t temp;

    temp = interrupt << 8;

    RCM->INT |= temp;
}

/*!
 * @brief     Disable RCM interrupts
 *
 * @param     interrupt : Disable specifies RCM interrupt sources.
 *                        This parameter can be any combination of the following values:
 *                        @arg RCM_INT_LSIRDY  : LSI ready interrupt
 *                        @arg RCM_INT_LSERDY  : LSE ready interrupt
 *                        @arg RCM_INT_HSIRDY  : HSI ready interrupt
 *                        @arg RCM_INT_HSERDY  : HSE ready interrupt
 *                        @arg RCM_INT_PLL1RDY : PLL1 ready interrupt
 *                        @arg RCM_INT_PLL2RDY : PLL2 ready interrupt
 *
 * @retval    None
 */
void RCM_DisableInterrupt(uint32_t interrupt)
{
    uint32_t temp;

    temp = interrupt << 8;

    RCM->INT &= (uint32_t)~temp;
}

/*!
 * @brief     Read the specified RCM flag status
 *
 * @param     flag : Returns specifies the flag status.
 *                   This parameter can be one of the following values:
 *                   @arg RCM_FLAG_HSIRDY  : HSI ready flag
 *                   @arg RCM_FLAG_HSERDY  : HSE ready flag
 *                   @arg RCM_FLAG_PLL1RDY : PLL1 ready flag
 *                   @arg RCM_FLAG_PLL2RDY : PLL2 ready flag
 *                   @arg RCM_FLAG_LSERDY  : LSE ready flag
 *                   @arg RCM_FLAG_LSIRDY  : LSI ready flag
 *                   @arg RCM_FLAG_BORRST  : POR/PDR or BOR reset
 *                   @arg RCM_FLAG_PINRST  : NRST PIN Reset Occur Flag
 *                   @arg RCM_FLAG_PORRST  : POR/PDR Reset Occur Flag
 *                   @arg RCM_FLAG_SWRST   : Software Reset Occur Flag
 *                   @arg RCM_FLAG_IWDTRST : Independent Watchdog Reset Occur Flag
 *                   @arg RCM_FLAG_WWDTRST : Window Watchdog Reset Occur Flag
 *                   @arg RCM_FLAG_LPRRST  : Low Power Reset Occur Flag
 *
 * @retval    The new state of flag (SET or RESET)
 */
uint8_t RCM_ReadStatusFlag(RCM_FLAG_T flag)
{
    uint32_t reg, bit;

    bit = (uint32_t)(1 << (flag & 0xff));

    reg = (flag >> 8) & 0xff;

    switch (reg)
    {
    case 0:
        reg = RCM->CTRL;
        break;

    case 1:
        reg = RCM->BDCTRL;
        break;

    case 2:
        reg = RCM->CSTS;
        break;

    default:
        break;
    }

    if (reg & bit)
    {
        return SET;
    }

    return RESET;
}

/*!
 * @brief     Clears all the RCM reset flags
 *
 * @param     None
 *
 * @retval    None
 *
 * @note      The reset flags are:
 *            RCM_FLAG_BORRST, RCM_FLAG_PINRST, RCM_FLAG_PWRST, RCM_FLAG_SWRST
 *            RCM_FLAG_IWDTRST, RCM_FLAG_WWDTRST, RCM_FLAG_LPRRST
 */
void RCM_ClearStatusFlag(void)
{
    RCM->CSTS_B.RSTFLGCLR = BIT_SET;
}

/*!
 * @brief     Reads the specified RCM interrupt Flag
 *
 * @param     flag : Reads specifies RCM interrupt flag.
 *                   This parameter can be one of the following values:
 *                   @arg RCM_INT_LSIRDY : LSI ready interrupt flag
 *                   @arg RCM_INT_LSERDY : LSE ready interrupt flag
 *                   @arg RCM_INT_HSIRDY : HSI ready interrupt flag
 *                   @arg RCM_INT_HSERDY : HSE ready interrupt flag
 *                   @arg RCM_INT_PLL1RDY: PLL1 ready interrupt flag
 *                   @arg RCM_INT_PLL2RDY: PLL2 ready interrupt flag
 *                   @arg RCM_INT_CSS    : Clock Security System interrupt flag
 *
 * @retval    The new state of intFlag (SET or RESET)
 */
uint8_t RCM_ReadIntFlag(RCM_INT_T flag)
{
    return (RCM->INT &flag) ? SET : RESET;
}

/*!
 * @brief     Clears the interrupt flag
 *
 * @param     flag : Clears specifies interrupt flag.
 *                   @arg RCM_INT_LSIRDY : Clear LSI ready interrupt flag
 *                   @arg RCM_INT_LSERDY : Clear LSE ready interrupt flag
 *                   @arg RCM_INT_HSIRDY : Clear HSI ready interrupt flag
 *                   @arg RCM_INT_HSERDY : Clear HSE ready interrupt flag
 *                   @arg RCM_INT_PLL1RDY: Clear PLL1 ready interrupt flag
 *                   @arg RCM_INT_PLL2RDY: Clear PLL2 ready interrupt flag
 *                   @arg RCM_INT_CSS    : Clear Clock Security System interrupt flag
 *
 * @retval    None
 */
void RCM_ClearIntFlag(uint32_t flag)
{
    uint32_t temp;

    temp = flag << 16;
    RCM->INT |= temp;
}

/**@} end of group RCM_Functions */
/**@} end of group RCM_Driver */
/**@} end of group APM32F4xx_StdPeriphDriver */