-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCC_interface.h
684 lines (648 loc) · 15.6 KB
/
RCC_interface.h
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
/*
* interface.h
*
* Created on: 4 Aug 2019
* Author: Yahia
*/
#ifndef RCC_INTERFACE_H_
#define RCC_INTERFACE_H_
#include "std_types.h"
#include "common_macros.h"
/* * * * * * * * * * * * * * *
* RCC Registers Structure *
* * * * * * * * * * * * * * */
typedef struct{
uint32 RCC_CR;
uint32 RCC_CFGR;
uint32 RCC_CIR;
uint32 RCC_APB2RSTR;
uint32 RCC_APB1RSTR;
uint32 RCC_AHBENR;
uint32 RCC_APB2ENR;
uint32 RCC_APB1ENR;
uint32 RCC_BDCR;
uint32 RCC_CSR;
}RCC_Registers;
/* RCC is a pointer to RCC_Registers structure
* RCC address is the base address of RCC module in STM32F103C8T6
* */
#define RCC ((RCC_Registers *)(0x40021000))
/* * * * * * * * * * * * * * *
* MCO Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the MCO
clock source.
* You can choose one value to pass it to:
void RCC_MCO_CLK(uint8 MCO_CLKSource)
as function argument.
* These Values can't be edited by the user.
* */
MCO_No_clock,
MCO_System_clock_selected = 4,
MCO_HSI_clock_selected,
MCO_HSE_clock_selected,
MCO_PLL_clock_divided_by_2_selected
};
/* * * * * * * * * * * *
* PLL CLK Source *
* * * * * * * * * * * */
enum{
/* These are the values that are used to choose Input
Clock source of PLL.
* You can choose one value to pass it to:
void RCC_EnablePLL(uint8 PLL_CLKSource, uint8 PLL_Value)
as the first argument.
* These Values can be edited by the user.
* */
Half_HSI,
Half_HSE,
HSE
};
/* * * * * * * * * * * * * * *
* PLL Multiplication Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the PLL
Multiplication factor.
* You can choose one value to pass it to:
void RCC_EnablePLL(uint8 PLL_CLKSource, uint8 PLL_Value)
as the second argument.
* These Values can't be edited by the user.
* */
PLL_input_clock_x2,
PLL_input_clock_x3,
PLL_input_clock_x4,
PLL_input_clock_x5,
PLL_input_clock_x6,
PLL_input_clock_x7,
PLL_input_clock_x8,
PLL_input_clock_x9,
PLL_input_clock_x10,
PLL_input_clock_x11,
PLL_input_clock_x12,
PLL_input_clock_x13,
PLL_input_clock_x14,
PLL_input_clock_x15,
PLL_input_clock_x16,
};
/* * * * * * * * * * * * * * *
* AHB Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the AHB
prescaler value.
* You can choose one value to pass it to:
void AHB_Prescaler(uint8 AHB_PrescalerValue)
as function argument.
* These Values can't be edited by the user.
* */
AHB_SYSCLK_not_divided,
AHB_SYSCLK_divided_by_2 = 8,
AHB_SYSCLK_divided_by_4,
AHB_SYSCLK_divided_by_8,
AHB_SYSCLK_divided_by_16,
AHB_SYSCLK_divided_by_64,
AHB_SYSCLK_divided_by_128,
AHB_SYSCLK_divided_by_256,
AHB_SYSCLK_divided_by_512
};
/* * * * * * * * * * * * * * *
* APB1 Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the APB1
prescaler value.
* You can choose one value to pass it to:
void APB1_Prescaler(uint8 APB1_PrescalerValue)
as function argument.
* These Values can't be edited by the user.
* */
APB1_HCLK_not_divided,
APB1_HCLK_divided_by_2 = 4,
APB1_HCLK_divided_by_4,
APB1_HCLK_divided_by_8,
APB1_HCLK_divided_by_16
};
/* * * * * * * * * * * * * * *
* APB2 Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the APB2
prescaler value.
* You can choose one value to pass it to:
void APB2_Prescaler(uint8 APB2_PrescalerValue)
as function argument.
* These Values can't be edited by the user.
* */
APB2_HCLK_not_divided,
APB2_HCLK_divided_by_2 = 4,
APB2_HCLK_divided_by_4,
APB2_HCLK_divided_by_8,
APB2_HCLK_divided_by_16
};
/* * * * * * * * * * * * * * *
* ADCs Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the ADCs
prescaler value.
* You can choose one value to pass it to:
void ADC_Prescaler(uint8 ADC_PrescalerValue)
as function argument.
* These Values can't be edited by the user.
* */
ADC_PCLK2_divided_by_2,
ADC_PCLK2_divided_by_4,
ADC_PCLK2_divided_by_6,
ADC_PCLK2_divided_by_8
};
/* * * * * * * * * * * * * * *
* USB Prescaler Factor *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the USB
prescaler value.
* You can choose one value to pass it to:
void USB_Prescaler(uint8 USB_PrescalerValue)
as function argument.
* These Values can't be edited by the user.
* */
USB_PLL_clock_is_divided_by_OneHalf,
USB_PLL_clock_is_not_divided
};
/* * * * * * * * * * * * * * *
* RCC_APB2RSTR Registers *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the module's ID
* You can choose one value to pass it to:
void Reset_Module(uint8 peripheralIdx)
as function argument.
* These Values can't be edited by the user.
* */
AFIORST,
IOPARST = 2,
IOPBRST,
IOPCRST,
IOPDRST,
IOPERST,
IOPFRST,
IOPGRST,
ADC1RST,
ADC2RST,
TIM1RST,
SPI1RST,
TIM8RST,
USART1RST,
ADC3RST,
TIM9RST = 19,
TIM10RST,
TIM11RST
};
/* * * * * * * * * * * * * * *
* RCC_APB1RSTR Registers *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to choose the module's ID
* You can choose one value to pass it to:
void Reset_Module(uint8 peripheralIdx)
as function argument.
* These Values can't be edited by the user.
* */
TIM2RST = 32,
TIM3RST,
TIM4RST,
TIM5RST,
TIM6RST,
TIM7RST,
TIM12RST,
TIM13RST,
TIM14RST,
WWDGRST = 43,
SPI2RST = 46,
SPI3RST,
USART2RST = 49,
USART3RST,
UART4RST,
UART5RST,
I2C1RST,
I2C2RST,
USBRST,
CANRST = 57,
BKPRST = 59,
PWRRST,
DACRST
};
/* * * * * * * * * * * * * * *
* RCC_AHBENR Registers *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to enable clock for a
* specific module.
* You can choose one value to pass it to:
void RCC_DisableCLK(uint8 peripheralIdx)
void RCC_EnableCLK(uint8 peripheralIdx)
as function argument.
* These Values can't be edited by the user.
* */
DMA1EN,
DMA2EN,
SRAMEN,
FLIFTEN = 4,
CRCEN = 6,
FSMCEN = 8,
SDIOEN = 10
};
/* * * * * * * * * * * * * * *
* RCC_APB2ENR Registers *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to enable clock for a
* specific module.
* You can choose one value to pass it to:
void RCC_DisableCLK(uint8 peripheralIdx)
void RCC_EnableCLK(uint8 peripheralIdx)
as function argument.
* These Values can't be edited by the user.
* */
AFIOEN = 32,
IOPAEN = 34,
IOPBEN,
IOPCEN,
IOPDEN,
IOPEEN,
IOPFEN,
IOPGEN,
ADC1EN,
ADC2EN,
TIM1REN,
SPI1EN,
TIM8EN,
USART1EN,
ADC3EN,
TIM9EN = 51,
TIM10EN,
TIM11EN
};
/* * * * * * * * * * * * * * *
* RCC_APB1ENR Registers *
* * * * * * * * * * * * * * */
enum{
/* These are the values that are used to enable clock for a
* specific module.
* You can choose one value to pass it to:
void RCC_DisableCLK(uint8 peripheralIdx)
void RCC_EnableCLK(uint8 peripheralIdx)
as function argument.
* These Values can't be edited by the user.
* */
TIM2EN = 64,
TIM3EN,
TIM4EN,
TIM5EN,
TIM6EN,
TIM7EN,
TIM12EN,
TIM13EN,
TIM14EN,
WWDGEN = 75,
SPI2EN = 78,
SPI3EN,
USART2EN = 81,
USART3EN,
UART4EN,
UART5EN,
I2C1EN,
I2C2EN,
USBEN,
CANEN = 89,
BKPEN = 91,
PWREN,
DACEN
};
/* void RCC_EnableHSI(void)
* Function Description: Configure RCC module to operate in
HSI(High Speed Internal) mode.
* Processor operate by the internal RC oscillator of the uC.
* Internal oscillator Has a Frequency of 8MHz.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_EnableHSI(void);
/* void RCC_EnableHSE(void)
* Function Description: Configure RCC module to operate in
HSE(High Speed External) mode.
* User has to connect External oscillator.
* External oscillator Has a range 4MHz:16MHz.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_EnableHSE(void);
/* void RCC_EnablePLL(uint8 PLL_CLKSource, uint8 PLL_Value)
* Function Description: Configure RCC module to operate in
PLL(Phase Locked Loop) mode.
* User can operate on either External oscillator, External
oscillator divided by 2 or the Internal RC oscillator
divided by 2.
* External oscillator Has a range 4MHz:16MHz.
* Internal oscillator Has a Frequency of 8MHz.
* Parameters(In) : - PLL_CLKSource --> The clock source to
the PLL.
- PLL_Value --> the values that are used to choose the PLL
Multiplication factor.
* There are three options for PLL_CLKSource:
- Half_HSI
- Half_HSE
- HSE
* There are multiple options for PLL_Value:
- PLL_input_clock_x2
- PLL_input_clock_x3
- PLL_input_clock_x4
- PLL_input_clock_x5
- PLL_input_clock_x6
- PLL_input_clock_x7
- PLL_input_clock_x8
- PLL_input_clock_x9
- PLL_input_clock_x10
- PLL_input_clock_x11
- PLL_input_clock_x12
- PLL_input_clock_x13
- PLL_input_clock_x14
- PLL_input_clock_x15
- PLL_input_clock_x16
* Parameters(Out) : None.
* */
void RCC_EnablePLL(uint8 PLL_CLKSource, uint8 PLL_Value);
/* void RCC_EnableLSI(void)
* Function Description: Configure RTC module to operate in
LSI(Low Speed Internal) mode.
* Processor operate by the internal RC oscillator of the uC.
* Internal oscillator Has a Frequency of 40KHz.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_EnableLSI(void);
/* void RCC_EnableLSE(void)
* Function Description: Configure RTC module to operate in
LSE(Low Speed External) mode.
* User has to connect 32.768KHz External oscillator.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_EnableLSE(void);
/* void RCC_Enable_RTC(void)
* Function Description: Enable RTC module of the uC.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_Enable_RTC(void);
/* void RCC_MCO_CLK(uint8 MCO_CLKSource)
* Function Description: Select specific clock to be generated
by MCO pin.
* Parameters(In) : - MCO_CLKSource --> The clock source to
the MCO.
* There are three options for MCO_CLKSource:
- MCO_No_clock
- MCO_System_clock_selected
- MCO_HSI_clock_selected
- MCO_HSE_clock_selected
- MCO_PLL_clock_divided_by_2_selected
* Parameters(Out) : None.
* */
void RCC_MCO_CLK(uint8 MCO_CLKSource);
/* void AHB_Prescaler(uint8 AHB_PrescalerValue)
* Function Description: Set the value of AHB Prescaler.
* Parameters(In) : AHB_PrescalerValue --> prescaler value.
* There are three options for AHB_PrescalerValue:
- AHB_SYSCLK_not_divided
- AHB_SYSCLK_divided_by_2
- AHB_SYSCLK_divided_by_4
- AHB_SYSCLK_divided_by_8
- AHB_SYSCLK_divided_by_16
- AHB_SYSCLK_divided_by_64
- AHB_SYSCLK_divided_by_128
- AHB_SYSCLK_divided_by_256
- AHB_SYSCLK_divided_by_512
* Parameters(Out) : None.
* */
void AHB_Prescaler(uint8 AHB_PrescalerValue);
/* void APB1_Prescaler(uint8 APB1_PrescalerValue)
* Function Description: Set the value of APB1 Prescaler.
* Parameters(In) : APB1_PrescalerValue --> prescaler value.
* There are three options for APB1_PrescalerValue:
- APB1_HCLK_not_divided
- APB1_HCLK_divided_by_2
- APB1_HCLK_divided_by_4
- APB1_HCLK_divided_by_8
- APB1_HCLK_divided_by_16
* Parameters(Out) : None.
* */
void APB1_Prescaler(uint8 APB1_PrescalerValue);
/* void APB2_Prescaler(uint8 APB2_PrescalerValue)
* Function Description: Set the value of APB2 Prescaler.
* Parameters(In) : APB2_PrescalerValue --> prescaler value.
* There are three options for APB2_PrescalerValue:
- APB2_HCLK_not_divided
- APB2_HCLK_divided_by_2
- APB2_HCLK_divided_by_4
- APB2_HCLK_divided_by_8
- APB2_HCLK_divided_by_16
* Parameters(Out) : None.
* */
void APB2_Prescaler(uint8 APB2_PrescalerValue);
/* void ADC_Prescaler(uint8 ADC_PrescalerValue)
* Function Description: Set the value of ADC prescaler.
* Parameters(In) : ADC_PrescalerValue --> prescaler value.
* There are three options for ADC_PrescalerValue:
- ADC_PCLK2_divided_by_2
- ADC_PCLK2_divided_by_4
- ADC_PCLK2_divided_by_6
- ADC_PCLK2_divided_by_8
* Parameters(Out) : None.
* */
void ADC_Prescaler(uint8 ADC_PrescalerValue);
/* void USB_Prescaler(uint8 USB_PrescalerValue)
* Function Description: Set the value of USB prescaler.
* Parameters(In) : USB_PrescalerValue --> prescaler value.
* There are three options for USB_PrescalerValue:
- USB_PLL_clock_is_divided_by_OneHalf
- USB_PLL_clock_is_not_divided
* Parameters(Out) : None.
* */
void USB_Prescaler(uint8 USB_PrescalerValue);
/* void Reset_Module(uint8 peripheralIdx)
* Function Description: Reset specific hardware module
in the uC.
* Parameters(In) : peripheralIdx --> hardware module.
* There are three options for Module:
- AFIORST
- IOPARST
- IOPBRST
- IOPCRST
- IOPDRST
- IOPERST
- IOPFRST
- IOPGRST
- ADC1RST
- ADC2RST
- TIM1RST
- SPI1RST
- TIM8RST
- USART1RST
- ADC3RST
- TIM9RST
- TIM10RST
- TIM11RST
- TIM2RST
- TIM3RST
- TIM4RST
- TIM5RST
- TIM6RST
- TIM7RST
- TIM12RST
- TIM13RST
- TIM14RST
- WWDGRST
- SPI2RST
- SPI3RST
- USART2RST
- USART3RST
- UART4RST
- UART5RST
- I2C1RST
- I2C2RST
- USBRST
- CANRST
- BKPRST
- PWRRST
- DACRST
* Parameters(Out) : None.
* */
void Reset_Module(uint8 peripheralIdx);
/* void Remove_ResetFlag(void)
* Function Description: Remove reset flag.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void Remove_ResetFlag(void);
/* void RCC_EnableCLK(uint8 peripheralIdx);
* Function Description: Enable specific hardware module
in the uC.
* Parameters(In) : peripheralIdx --> hardware module.
* There are Multiple options for peripheralIdx:
- DMA1EN
- DMA2EN
- SRAMEN
- FLIFTEN
- CRCEN
- FSMCEN
- SDIOEN
- AFIOEN
- IOPAEN
- IOPBEN
- IOPCEN
- IOPDEN
- IOPEEN
- IOPFEN
- IOPGEN
- ADC1EN
- ADC2EN
- TIM1REN
- SPI1EN
- TIM8EN
- USART1EN
- ADC3EN
- TIM9EN
- TIM10EN
- TIM11EN
- TIM2EN
- TIM3EN
- TIM4EN
- TIM5EN
- TIM6EN
- TIM7EN
- TIM12EN
- TIM13EN
- TIM14EN
- WWDGEN
- SPI2EN
- SPI3EN
- USART2EN
- USART3EN
- UART4EN
- UART5EN
- I2C1EN
- I2C2EN
- USBEN
- CANEN
- BKPEN
- PWREN
- DACEN
* Parameters(Out) : None.
* */
void RCC_EnableCLK(uint8 peripheralIdx);
/* void RCC_DisableCLK(uint8 peripheralIdx);
* Function Description: Disable specific hardware module
in the uC.
* Parameters(In) : peripheralIdx --> hardware module.
* There are Multiple options for peripheralIdx:
- DMA1EN
- DMA2EN
- SRAMEN
- FLIFTEN
- CRCEN
- FSMCEN
- SDIOEN
- AFIOEN
- IOPAEN
- IOPBEN
- IOPCEN
- IOPDEN
- IOPEEN
- IOPFEN
- IOPGEN
- ADC1EN
- ADC2EN
- TIM1REN
- SPI1EN
- TIM8EN
- USART1EN
- ADC3EN
- TIM9EN
- TIM10EN
- TIM11EN
- TIM2EN
- TIM3EN
- TIM4EN
- TIM5EN
- TIM6EN
- TIM7EN
- TIM12EN
- TIM13EN
- TIM14EN
- WWDGEN
- SPI2EN
- SPI3EN
- USART2EN
- USART3EN
- UART4EN
- UART5EN
- I2C1EN
- I2C2EN
- USBEN
- CANEN
- BKPEN
- PWREN
- DACEN
* Parameters(Out) : None.
* */
void RCC_DisableCLK(uint8 peripheralIdx);
/* void RCC_Config(void)
* Function Description: Configure RCC based on
the user configuration.
* Parameters(In) : None.
* Parameters(Out) : None.
* */
void RCC_Config(void);
#endif /* INTERFACE_H_ */