STM32 Blue Pill Drivers
Drivers that could be used to interface and interact with STM32F103C8T6 Microcontroller
Loading...
Searching...
No Matches
RCC_program.c File Reference

This file contains the implementation for the RCC module. More...

+ Include dependency graph for RCC_program.c:

Functions

static void RCC_vInitHSEClock (void)
 This function initializes the HSE clock. More...
 
static void RCC_vInitHSIClock (void)
 This function initializes the HSI clock. More...
 
static void RCC_vInitPLL (void)
 This function initializes the PLL clock. More...
 
static void RCC_vInitSystemClock (void)
 This function initializes the system clock. More...
 
static void RCC_vInitMCO (void)
 This function initializes the MCO. More...
 
static void RCC_vSetAPB2PeripheralClockStatus (t_RCC_APB2Peripherals enuPeripheral, t_bool bStatus)
 This function initializes a certain peripheral clock on APB2 bus. More...
 
static void RCC_vSetAPB1PeripheralClockStatus (t_RCC_APB1Peripherals enuPeripheral, t_bool bStatus)
 This function initializes a certain peripheral clock on APB1 bus. More...
 
static void RCC_vSetAHBPeripheralClockStatus (t_RCC_AHBPeripherals enuPeripheral, t_bool bStatus)
 This function initializes a certain peripheral clock on AHB bus. More...
 
static void RCC_vSetADCPreScaler (void)
 This function sets the ADC prescaler. More...
 
static void RCC_vSetUSBPrescaler (void)
 This function sets the USB prescaler. More...
 
static void RCC_vSetAHBPrescaler (void)
 This function sets the AHB prescaler. More...
 
static void RCC_vSetAPB1Prescaler (void)
 This function sets the APB1 prescaler. More...
 
static void RCC_vSetAPB2Prescaler (void)
 This function sets the APB2 prescaler. More...
 
void RCC_vInit (void)
 This function initializes the RCC peripheral. More...
 
void RCC_vEnablePeripheralABP2 (t_RCC_APB2Peripherals enuPeripheral)
 This function enables the clock of a peripheral connected to the APB2 bus. More...
 
void RCC_vDisablePeripheralABP2 (t_RCC_APB2Peripherals enuPeripheral)
 This function disables the clock of a peripheral connected to the APB2 bus. More...
 
void RCC_vEnablePeripheralABP1 (t_RCC_APB1Peripherals enuPeripheral)
 This function enables the clock of a peripheral connected to the APB1 bus. More...
 
void RCC_vDisablePeripheralABP1 (t_RCC_APB1Peripherals enuPeripheral)
 This function disables the clock of a peripheral connected to the APB1 bus. More...
 
void RCC_vEnablePeripheralAHB (t_RCC_AHBPeripherals enuPeripheral)
 This function enables the clock of a peripheral connected to the AHB bus. More...
 
void RCC_vDisablePeripheralAHB (t_RCC_AHBPeripherals enuPeripheral)
 This function disables the clock of a peripheral connected to the AHB bus. More...
 

Detailed Description

This file contains the implementation for the RCC module.

Author
Mohamed Alaa
Version
1.0.0

This file contains the implementation for the RCC module.

Date
2023-06-18

Function Documentation

◆ RCC_vInitHSEClock()

static void RCC_vInitHSEClock ( void  )
static

This function initializes the HSE clock.

This function initializes the HSE clock and waits until it is ready

23{
24 /* Enable HSE bypass */
25 RCC.CR.HSEBYP = TRUE;
26 /* Enable HSE */
27 RCC.CR.HSEON = TRUE;
28 /* Wait until HSE is ready */
29 while (RCC.CR.HSERDY == FALSE)
30 ;
31
32 if (RCC_ENABLE_CSS == TRUE)
33 {
34 /* Enable CSS */
35 RCC.CR.CSSON = TRUE;
36 }
37 else
38 {
39 /* Disable CSS */
40 RCC.CR.CSSON = FALSE;
41 }
42}
#define TRUE
Type definition for TRUE.
Definition: LSTD_VALUES.h:30
#define FALSE
Type definition for FALSE.
Definition: LSTD_VALUES.h:36
#define RCC_ENABLE_CSS
This macro defines the clock security system state.
Definition: RCC_config.h:122
#define RCC
RCC Register Map.
Definition: RCC_private.h:1001

References FALSE, RCC, RCC_ENABLE_CSS, and TRUE.

Referenced by RCC_vInit(), and RCC_vInitPLL().

+ Here is the caller graph for this function:

◆ RCC_vInitHSIClock()

static void RCC_vInitHSIClock ( void  )
static

This function initializes the HSI clock.

This function initializes the HSI clock and waits until it is ready

49{
50 /* Enable HSI */
51 RCC.CR.HSION = TRUE;
52 /* Wait until HSI is ready */
53 while (RCC.CR.HSIRDY == FALSE)
54 ;
55}

References FALSE, RCC, and TRUE.

Referenced by RCC_vInit(), and RCC_vInitPLL().

+ Here is the caller graph for this function:

◆ RCC_vInitPLL()

static void RCC_vInitPLL ( void  )
static

This function initializes the PLL clock.

This function initializes the PLL clock and waits until it is ready

62{
64 {
66 }
68 {
70 }
71 else
72 {
73 /* Do nothing */
74 }
75
76 /* Set PLL source to HSE */
77 RCC.CFGR.PLLSRC = RCC_PLL_SRC;
78 /* Set PLL multiplication factor */
79 RCC.CFGR.PLLMUL = RCC_PLL_MUL;
80 /* Set PLL entry HSE divider */
81 RCC.CFGR.PLLXTPRE = RCC_PLL_HSE_DIVIDE_BY_2;
82 /* Enable PLL */
83 RCC.CR.PLLON = TRUE;
84 /* Wait until PLL is ready */
85 while (RCC.CR.PLLRDY == FALSE)
86 ;
87}
static void RCC_vInitHSIClock(void)
This function initializes the HSI clock.
Definition: RCC_program.c:48
static void RCC_vInitHSEClock(void)
This function initializes the HSE clock.
Definition: RCC_program.c:22
#define RCC_PLL_MUL
This macro defines the PLL multiplication factor.
Definition: RCC_config.h:46
#define RCC_PLL_HSE_DIVIDE_BY_2
This macro defines the PLL entry HSE divider.
Definition: RCC_config.h:56
#define RCC_PLL_SRC
This macro defines the PLL source.
Definition: RCC_config.h:38
@ RCC_PLLSource_HSE
HSE clock selected as PLL clock.
Definition: RCC_interface.h:232
@ RCC_PLLSource_HSI_DividedBy2
HSI clock divided by 2 selected as PLL clock.
Definition: RCC_interface.h:228

References FALSE, RCC, RCC_PLL_HSE_DIVIDE_BY_2, RCC_PLL_MUL, RCC_PLL_SRC, RCC_PLLSource_HSE, RCC_PLLSource_HSI_DividedBy2, RCC_vInitHSEClock(), RCC_vInitHSIClock(), and TRUE.

Referenced by RCC_vInit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RCC_vInitSystemClock()

static void RCC_vInitSystemClock ( void  )
static

This function initializes the system clock.

This function initializes the system clock

94{
95 /* Set system clock source */
97 /* Wait until system clock source is set */
98 while (RCC.CFGR.SWS != RCC_SYSTEM_CLOCK_SOURCE)
99 ;
100}
#define RCC_SYSTEM_CLOCK_SOURCE
This macro defines the system clock source.
Definition: RCC_config.h:64

References RCC, and RCC_SYSTEM_CLOCK_SOURCE.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vInitMCO()

static void RCC_vInitMCO ( void  )
static

This function initializes the MCO.

This function initializes the MCO (Microcontroller Clock Output) and waits until it is ready

107{
108 /* Set MCO source */
109 RCC.CFGR.MCO = RCC_MCO_SOURCE;
110}
#define RCC_MCO_SOURCE
This macro defines the MCO source.
Definition: RCC_config.h:72

References RCC, and RCC_MCO_SOURCE.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vSetAPB2PeripheralClockStatus()

static void RCC_vSetAPB2PeripheralClockStatus ( t_RCC_APB2Peripherals  enuPeripheral,
t_bool  bStatus 
)
static

This function initializes a certain peripheral clock on APB2 bus.

This function initializes a certain peripheral clock on APB2 bus

Parameters
[in]enuPeripheralPeripheral to enable/disable its clock
[in]bStatusEnable/Disable peripheral clock
See also
RCC_APB2Peripherals
120{
121 switch (enuPeripheral)
122 {
124 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, AFIOEN, bStatus);
125 break;
127 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPAEN, bStatus);
128 break;
130 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPBEN, bStatus);
131 break;
133 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPCEN, bStatus);
134 break;
136 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPDEN, bStatus);
137 break;
139 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPEEN, bStatus);
140 break;
142 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPFEN, bStatus);
143 break;
145 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, IOPGEN, bStatus);
146 break;
148 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, ADC1EN, bStatus);
149 break;
151 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, ADC2EN, bStatus);
152 break;
154 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, TIM1EN, bStatus);
155 break;
157 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, SPI1EN, bStatus);
158 break;
160 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, USART1EN, bStatus);
161 break;
163 RCC_SET_REGISTER_BIT_STATUS(APB2ENR, ADC3EN, bStatus);
164 break;
165 default:
166 /* Do nothing */
167 break;
168 }
169}
@ RCC_APB2Peripherals_PORTF
I/O port F clock.
Definition: RCC_interface.h:315
@ RCC_APB2Peripherals_PORTA
I/O port A clock.
Definition: RCC_interface.h:295
@ RCC_APB2Peripherals_ADC2
ADC 2 interface clock.
Definition: RCC_interface.h:327
@ RCC_APB2Peripherals_TIM1
Timer 1 (TIM1) clock.
Definition: RCC_interface.h:331
@ RCC_APB2Peripherals_PORTB
I/O port B clock.
Definition: RCC_interface.h:299
@ RCC_APB2Peripherals_SPI1
SPI 1 clock.
Definition: RCC_interface.h:335
@ RCC_APB2Peripherals_ADC3
ADC 3 interface clock.
Definition: RCC_interface.h:343
@ RCC_APB2Peripherals_PORTG
I/O port G clock.
Definition: RCC_interface.h:319
@ RCC_APB2Peripherals_PORTD
I/O port D clock.
Definition: RCC_interface.h:307
@ RCC_APB2Peripherals_PORTC
I/O port C clock.
Definition: RCC_interface.h:303
@ RCC_APB2Peripherals_ADC1
ADC 1 interface clock.
Definition: RCC_interface.h:323
@ RCC_APB2Peripherals_PORTE
I/O port E clock.
Definition: RCC_interface.h:311
@ RCC_APB2Peripherals_AFIO
Alternate function I/O clock.
Definition: RCC_interface.h:291
@ RCC_APB2Peripherals_USART1
USART1 clock.
Definition: RCC_interface.h:339
#define RCC_SET_REGISTER_BIT_STATUS(REG, BIT, BSTATUS)
Set RCC register bit status (TRUE or FALSE)
Definition: RCC_private.h:1011

References RCC_APB2Peripherals_ADC1, RCC_APB2Peripherals_ADC2, RCC_APB2Peripherals_ADC3, RCC_APB2Peripherals_AFIO, RCC_APB2Peripherals_PORTA, RCC_APB2Peripherals_PORTB, RCC_APB2Peripherals_PORTC, RCC_APB2Peripherals_PORTD, RCC_APB2Peripherals_PORTE, RCC_APB2Peripherals_PORTF, RCC_APB2Peripherals_PORTG, RCC_APB2Peripherals_SPI1, RCC_APB2Peripherals_TIM1, RCC_APB2Peripherals_USART1, and RCC_SET_REGISTER_BIT_STATUS.

Referenced by RCC_vDisablePeripheralABP2(), and RCC_vEnablePeripheralABP2().

+ Here is the caller graph for this function:

◆ RCC_vSetAPB1PeripheralClockStatus()

static void RCC_vSetAPB1PeripheralClockStatus ( t_RCC_APB1Peripherals  enuPeripheral,
t_bool  bStatus 
)
static

This function initializes a certain peripheral clock on APB1 bus.

This function initializes a certain peripheral clock on APB1 bus

Parameters
[in]enuPeripheralPeripheral to enable/disable its clock
[in]bStatusEnable/Disable peripheral clock
See also
t_RCC_APB1Peripherals
179{
180 switch (enuPeripheral)
181 {
183 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM2EN, bStatus);
184 break;
186 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM3EN, bStatus);
187 break;
189 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM4EN, bStatus);
190 break;
192 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM5EN, bStatus);
193 break;
195 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM6EN, bStatus);
196 break;
198 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, TIM7EN, bStatus);
199 break;
201 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, WWDGEN, bStatus);
202 break;
204 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, SPI2EN, bStatus);
205 break;
207 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, SPI3EN, bStatus);
208 break;
210 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, USART2EN, bStatus);
211 break;
213 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, USART3EN, bStatus);
214 break;
216 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, UART4EN, bStatus);
217 break;
219 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, UART5EN, bStatus);
220 break;
222 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, I2C1EN, bStatus);
223 break;
225 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, I2C2EN, bStatus);
226 break;
228 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, USBEN, bStatus);
229 break;
231 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, CANEN, bStatus);
232 break;
234 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, BKPEN, bStatus);
235 break;
237 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, PWREN, bStatus);
238 break;
240 RCC_SET_REGISTER_BIT_STATUS(APB1ENR, DACEN, bStatus);
241 break;
242 default:
243 /* Do nothing */
244 break;
245 }
246}
@ RCC_APB1Peripherals_TIM5
Timer 5 (TIM5) clock.
Definition: RCC_interface.h:368
@ RCC_APB1Peripherals_TIM6
Timer 6 (TIM6) clock.
Definition: RCC_interface.h:372
@ RCC_APB1Peripherals_USB
USB clock.
Definition: RCC_interface.h:416
@ RCC_APB1Peripherals_USART2
USART 2 clock.
Definition: RCC_interface.h:392
@ RCC_APB1Peripherals_CAN
CAN clock.
Definition: RCC_interface.h:420
@ RCC_APB1Peripherals_BKP
Backup interface clock.
Definition: RCC_interface.h:424
@ RCC_APB1Peripherals_WWDG
Window watchdog (WWDG) clock.
Definition: RCC_interface.h:380
@ RCC_APB1Peripherals_UART5
UART 5 clock.
Definition: RCC_interface.h:404
@ RCC_APB1Peripherals_TIM7
Timer 7 (TIM7) clock.
Definition: RCC_interface.h:376
@ RCC_APB1Peripherals_DAC
DAC interface clock.
Definition: RCC_interface.h:432
@ RCC_APB1Peripherals_TIM3
Timer 3 (TIM3) clock.
Definition: RCC_interface.h:360
@ RCC_APB1Peripherals_UART4
UART 4 clock.
Definition: RCC_interface.h:400
@ RCC_APB1Peripherals_SPI3
SPI 3 clock.
Definition: RCC_interface.h:388
@ RCC_APB1Peripherals_PWR
Power interface clock.
Definition: RCC_interface.h:428
@ RCC_APB1Peripherals_SPI2
SPI 2 clock.
Definition: RCC_interface.h:384
@ RCC_APB1Peripherals_TIM4
Timer 4 (TIM4) clock.
Definition: RCC_interface.h:364
@ RCC_APB1Peripherals_I2C2
I2C 2 clock.
Definition: RCC_interface.h:412
@ RCC_APB1Peripherals_TIM2
Timer 2 (TIM2) clock.
Definition: RCC_interface.h:356
@ RCC_APB1Peripherals_I2C1
I2C 1 clock.
Definition: RCC_interface.h:408
@ RCC_APB1Peripherals_USART3
USART 3 clock.
Definition: RCC_interface.h:396

References RCC_APB1Peripherals_BKP, RCC_APB1Peripherals_CAN, RCC_APB1Peripherals_DAC, RCC_APB1Peripherals_I2C1, RCC_APB1Peripherals_I2C2, RCC_APB1Peripherals_PWR, RCC_APB1Peripherals_SPI2, RCC_APB1Peripherals_SPI3, RCC_APB1Peripherals_TIM2, RCC_APB1Peripherals_TIM3, RCC_APB1Peripherals_TIM4, RCC_APB1Peripherals_TIM5, RCC_APB1Peripherals_TIM6, RCC_APB1Peripherals_TIM7, RCC_APB1Peripherals_UART4, RCC_APB1Peripherals_UART5, RCC_APB1Peripherals_USART2, RCC_APB1Peripherals_USART3, RCC_APB1Peripherals_USB, RCC_APB1Peripherals_WWDG, and RCC_SET_REGISTER_BIT_STATUS.

Referenced by RCC_vDisablePeripheralABP1(), and RCC_vEnablePeripheralABP1().

+ Here is the caller graph for this function:

◆ RCC_vSetAHBPeripheralClockStatus()

static void RCC_vSetAHBPeripheralClockStatus ( t_RCC_AHBPeripherals  enuPeripheral,
t_bool  bStatus 
)
static

This function initializes a certain peripheral clock on AHB bus.

This function initializes a certain peripheral clock on AHB bus

Parameters
[in]enuPeripheralPeripheral to enable/disable its clock
[in]bStatusEnable/Disable peripheral clock
See also
t_RCC_AHBPeripherals
256{
257 switch (enuPeripheral)
258 {
260 RCC_SET_REGISTER_BIT_STATUS(AHBENR, DMA1EN, bStatus);
261 break;
263 RCC_SET_REGISTER_BIT_STATUS(AHBENR, DMA2EN, bStatus);
264 break;
266 RCC_SET_REGISTER_BIT_STATUS(AHBENR, CRCEN, bStatus);
267 break;
268 default:
269 /* Do nothing */
270 break;
271 }
272}
@ RCC_AHBPeripherals_DMA1
DMA 1 clock.
Definition: RCC_interface.h:445
@ RCC_AHBPeripherals_DMA2
DMA 2 clock.
Definition: RCC_interface.h:449
@ RCC_AHBPeripherals_CRC
CRC clock.
Definition: RCC_interface.h:453

References RCC_AHBPeripherals_CRC, RCC_AHBPeripherals_DMA1, RCC_AHBPeripherals_DMA2, and RCC_SET_REGISTER_BIT_STATUS.

Referenced by RCC_vDisablePeripheralAHB(), and RCC_vEnablePeripheralAHB().

+ Here is the caller graph for this function:

◆ RCC_vSetADCPreScaler()

static void RCC_vSetADCPreScaler ( void  )
static

This function sets the ADC prescaler.

This function sets the ADC prescaler to be used by ADC

279{
280 /* Set ADC prescaler */
281 RCC.CFGR.ADCPRE = RCC_ADC_PRESCALER;
282}
#define RCC_ADC_PRESCALER
This macro defines the ADC clock prescaler.
Definition: RCC_config.h:80

References RCC, and RCC_ADC_PRESCALER.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vSetUSBPrescaler()

static void RCC_vSetUSBPrescaler ( void  )
static

This function sets the USB prescaler.

This function sets the USB prescaler to be used by USB

289{
290 /* Set USB prescaler */
291 RCC.CFGR.USBPRE = RCC_USB_PRESCALER;
292}
#define RCC_USB_PRESCALER
This macro defines the USB clock prescaler.
Definition: RCC_config.h:112

References RCC, and RCC_USB_PRESCALER.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vSetAHBPrescaler()

static void RCC_vSetAHBPrescaler ( void  )
static

This function sets the AHB prescaler.

This function sets the AHB prescaler to be used by AHB bus

299{
300 /* Set AHB prescaler */
301 RCC.CFGR.HPRE = RCC_AHB_PRESCALER;
302}
#define RCC_AHB_PRESCALER
This macro defines the AHB clock prescaler.
Definition: RCC_config.h:88

References RCC, and RCC_AHB_PRESCALER.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vSetAPB1Prescaler()

static void RCC_vSetAPB1Prescaler ( void  )
static

This function sets the APB1 prescaler.

This function sets the APB1 prescaler to be used by APB1 bus

309{
310 /* Set APB1 prescaler */
311 RCC.CFGR.PPRE1 = RCC_APB1_PRESCALER;
312}
#define RCC_APB1_PRESCALER
This macro defines the APB1 clock prescaler.
Definition: RCC_config.h:96

References RCC, and RCC_APB1_PRESCALER.

Referenced by RCC_vInit().

+ Here is the caller graph for this function:

◆ RCC_vSetAPB2Prescaler()

static void RCC_vSetAPB2Prescaler ( void  )
static

This function sets the APB2 prescaler.

This function sets the APB2 prescaler to be used by APB2 bus

319{
320 /* Set APB2 prescaler */
321 RCC.CFGR.PPRE2 = RCC_APB2_PRESCALER;
322}
#define RCC_APB2_PRESCALER
This macro defines the APB2 clock prescaler.
Definition: RCC_config.h:104

References RCC, and RCC_APB2_PRESCALER.

Referenced by RCC_vInit().

+ Here is the caller graph for this function: