ACDC Senior Project v1.0.0
Senior Project for Textron Aviation
Loading...
Searching...
No Matches
ACDC_CLOCK.h File Reference

Header file containing functions for configuring the system clock and clock-related peripherals. More...

#include "stm32f1xx.h"
#include "ACDC_stdbool.h"

Go to the source code of this file.

Enumerations

enum  SystemClockSpeed {
  SCS_1MHz = 1000000 , SCS_2MHz = 2000000 , SCS_3MHz = 3000000 , SCS_4MHz = 4000000 ,
  SCS_5MHz = 5000000 , SCS_6MHz = 6000000 , SCS_7MHz = 7000000 , SCS_8MHz = 8000000 ,
  SCS_9MHz = 9000000 , SCS_10MHz = 10000000 , SCS_11MHz = 11000000 , SCS_12MHz = 12000000 ,
  SCS_13MHz = 13000000 , SCS_14MHz = 14000000 , SCS_15MHz = 15000000 , SCS_16MHz = 16000000 ,
  SCS_18MHz = 18000000 , SCS_20MHz = 20000000 , SCS_22MHz = 22000000 , SCS_24MHz = 24000000 ,
  SCS_26MHz = 26000000 , SCS_28MHz = 28000000 , SCS_30MHz = 30000000 , SCS_32MHz = 32000000 ,
  SCS_36MHz = 36000000 , SCS_40MHz = 40000000 , SCS_44MHz = 44000000 , SCS_48MHz = 48000000 ,
  SCS_52MHz = 52000000 , SCS_56MHz = 56000000 , SCS_60MHz = 60000000 , SCS_64MHz = 64000000 ,
  SCS_72MHz = 72000000
}
 
enum  MicroClockOutput {
  MCO_NO_CLK = RCC_CFGR_MCO_NOCLOCK , MCO_SYSCLK = RCC_CFGR_MCO_SYSCLK , MCO_HSICLK = RCC_CFGR_MCO_HSI , MCO_HSECLK = RCC_CFGR_MCO_HSE ,
  MCO_PLLCLK = RCC_CFGR_MCO_PLLCLK_DIV2
}
 
enum  ADC_Prescaler { ADC_DIV_2 = RCC_CFGR_ADCPRE_DIV2 , ADC_DIV_4 = RCC_CFGR_ADCPRE_DIV4 , ADC_DIV_6 = RCC_CFGR_ADCPRE_DIV6 , ADC_DIV_8 = RCC_CFGR_ADCPRE_DIV8 }
 
enum  APB_Prescaler {
  APB_DIV_1 = 0b000 , APB_DIV_2 = 0b100 , APB_DIV_4 = 0b101 , APB_DIV_8 = 0b110 ,
  APB_DIV_16 = 0b111
}
 

Functions

void CLOCK_SetSystemClockSpeed (SystemClockSpeed SCS_x)
 Sets the SYSCLK speed, and sets the perepherals to their fastest speed available.
 
SystemClockSpeed CLOCK_GetSystemClockSpeed (void)
 Retrieves the current SYSCLK.
 
SystemClockSpeed CLOCK_GetAPB1ClockSpeed (void)
 Retrieves the clock speed of the APB1 Clock.
 
SystemClockSpeed CLOCK_GetAPB2ClockSpeed (void)
 Retrieves the clock speed of the APB2 Clock.
 
SystemClockSpeed CLOCK_GetAPB1TimerClockSpeed (void)
 Retrieves the clock speed of the APB2 Timer Clock.
 
void CLOCK_SetMcoOutput (MicroClockOutput MCO_x)
 Enables the MCO output on Pin PA8 using MCO_x as the clock source.
 
void CLOCK_SetADCPrescaler (ADC_Prescaler ADC_DIV_x)
 Sets the ADC's Prescaler to either 2, 4, 6, 8.
 
void CLOCK_SetAPB1Prescaler (APB_Prescaler APB_DIV_x)
 Sets the Advanced Peripheral Bus 1 Prescaler to either 1, 2, 4, 8, 16.
 
void CLOCK_SetAPB2Prescaler (APB_Prescaler APB_DIV_x)
 Sets the Advanced Peripheral Bus 2 Prescaler to either 1, 2, 4, 8, 16.
 

Detailed Description

Header file containing functions for configuring the system clock and clock-related peripherals.

Author
Devin Marx

This file defines enums and functions for configuring the system clock speed, enabling the MCO output, setting ADC and APB prescalers, and retrieving the current system clock speed.

Version
0.1
Date
2023-11-3

Enumeration Type Documentation

◆ ADC_Prescaler

Enumerator
ADC_DIV_2 

CLK divided by 2

ADC_DIV_4 

CLK divided by 4

ADC_DIV_6 

CLK divided by 6

ADC_DIV_8 

CLK divided by 8

◆ APB_Prescaler

Enumerator
APB_DIV_1 

CLK not divided

APB_DIV_2 

CLK divided by 2

APB_DIV_4 

CLK divided by 4

APB_DIV_8 

CLK divided by 8

APB_DIV_16 

CLK divided by 16

◆ MicroClockOutput

Enumerator
MCO_NO_CLK 

No Clock Output

MCO_SYSCLK 

System Clock output

MCO_HSICLK 

HSI Clock output

MCO_HSECLK 

HSE Clock output

MCO_PLLCLK 

PLL Clock Divided by 2

◆ SystemClockSpeed

Enumerator
SCS_1MHz 

System Clock Speed 1MHz

SCS_2MHz 

System Clock Speed 2MHz

SCS_3MHz 

System Clock Speed 3MHz

SCS_4MHz 

System Clock Speed 4MHz

SCS_5MHz 

System Clock Speed 5MHz

SCS_6MHz 

System Clock Speed 6MHz

SCS_7MHz 

System Clock Speed 7MHz

SCS_8MHz 

System Clock Speed 8MHz

SCS_9MHz 

System Clock Speed 9MHz

SCS_10MHz 

System Clock Speed 10MHz

SCS_11MHz 

System Clock Speed 11MHz

SCS_12MHz 

System Clock Speed 12MHz

SCS_13MHz 

System Clock Speed 13MHz

SCS_14MHz 

System Clock Speed 14MHz

SCS_15MHz 

System Clock Speed 15MHz

SCS_16MHz 

System Clock Speed 16MHz

SCS_18MHz 

System Clock Speed 18MHz

SCS_20MHz 

System Clock Speed 20MHz

SCS_22MHz 

System Clock Speed 22MHz

SCS_24MHz 

System Clock Speed 24MHz

SCS_26MHz 

System Clock Speed 26MHz

SCS_28MHz 

System Clock Speed 28MHz

SCS_30MHz 

System Clock Speed 30MHz

SCS_32MHz 

System Clock Speed 32MHz

SCS_36MHz 

System Clock Speed 36MHz

SCS_40MHz 

System Clock Speed 40MHz

SCS_44MHz 

System Clock Speed 44MHz

SCS_48MHz 

System Clock Speed 48MHz

SCS_52MHz 

System Clock Speed 52MHz

SCS_56MHz 

System Clock Speed 56MHz

SCS_60MHz 

System Clock Speed 60MHz

SCS_64MHz 

System Clock Speed 64MHz

SCS_72MHz 

System Clock Speed 72MHz

Function Documentation

◆ CLOCK_GetAPB1ClockSpeed()

SystemClockSpeed CLOCK_GetAPB1ClockSpeed ( void )

Retrieves the clock speed of the APB1 Clock.

Returns
System Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)

◆ CLOCK_GetAPB1TimerClockSpeed()

SystemClockSpeed CLOCK_GetAPB1TimerClockSpeed ( void )

Retrieves the clock speed of the APB2 Timer Clock.

Returns
System Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)

◆ CLOCK_GetAPB2ClockSpeed()

SystemClockSpeed CLOCK_GetAPB2ClockSpeed ( void )

Retrieves the clock speed of the APB2 Clock.

Returns
System Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)

◆ CLOCK_GetSystemClockSpeed()

SystemClockSpeed CLOCK_GetSystemClockSpeed ( void )

Retrieves the current SYSCLK.

Returns
System Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)

◆ CLOCK_SetADCPrescaler()

void CLOCK_SetADCPrescaler ( ADC_Prescaler ADC_DIV_x)

Sets the ADC's Prescaler to either 2, 4, 6, 8.

Parameters
PRE_DIV_xADC Prescaler (Ex. ADC_DIV_2, ADC_DIV_4, ...)

◆ CLOCK_SetAPB1Prescaler()

void CLOCK_SetAPB1Prescaler ( APB_Prescaler APB_DIV_x)

Sets the Advanced Peripheral Bus 1 Prescaler to either 1, 2, 4, 8, 16.

Parameters
APB_DIV_xAPB1 Prescaler Divider (Ex. APB_DIV_1, APB_DIV_2, ...)

◆ CLOCK_SetAPB2Prescaler()

void CLOCK_SetAPB2Prescaler ( APB_Prescaler APB_DIV_x)

Sets the Advanced Peripheral Bus 2 Prescaler to either 1, 2, 4, 8, 16.

Parameters
APB_DIV_xAPB2 Prescaler Divider (Ex. APB_DIV_1, APB_DIV_2, ...)

◆ CLOCK_SetMcoOutput()

void CLOCK_SetMcoOutput ( MicroClockOutput MCO_x)

Enables the MCO output on Pin PA8 using MCO_x as the clock source.

Parameters
MCO_xClock output source (Ex. MCO_NO_CLK, MCO_SYSCLK, ...)

◆ CLOCK_SetSystemClockSpeed()

void CLOCK_SetSystemClockSpeed ( SystemClockSpeed SCS_x)

Sets the SYSCLK speed, and sets the perepherals to their fastest speed available.

Parameters
SCS_xSystem Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)