microHAL
An abstraction layer for your future F4xx projects
|
Function prototypes for the RCC driver. More...
Go to the source code of this file.
Data Structures | |
struct | RCCRegs |
Contains RCC registers. More... | |
struct | RCCPLLConfig |
Contains PLL configuration values. More... | |
Macros | |
#define | RCC_PTR (struct RCCRegs *)RCC_BASE |
Typedefs | |
typedef enum rcc_osc | rcc_osc_t |
Available RCC oscillators. | |
typedef enum rcc_clk_periph | rcc_clk_periph_t |
Available AHB/APB peripheral clocks. | |
typedef enum rcc_apb_prescaler | rcc_apb_prescaler_t |
Available RCC APBx prescaler dividers. | |
typedef enum rcc_ahb_prescaler | rcc_ahb_prescaler_t |
Available RCC AHB prescaler dividers. | |
typedef enum rcc_pll_target | rcc_pll_target_t |
Available PLL targets. | |
typedef enum rcc_systemclock_src | rcc_systemclock_src_t |
Available RCC system clock sources. | |
typedef enum rcc_mco1_src | rcc_mco1_src_t |
Available MCO1 clock sources. | |
typedef enum rcc_mco2_src | rcc_mco2_src_t |
Available MCO2 clock sources. | |
typedef enum rcc_mco_prescaler | rcc_mco_prescaler_t |
Available MCO prescaler dividers. | |
typedef enum rcc_rtc_src | rcc_rtc_src_t |
Enumerations | |
enum | rcc_osc { RCC_OSC_HSI = 0x0 , RCC_OSC_HSE = 0x1 , RCC_OSC_LSI = 0x2 , RCC_OSC_LSE = 0x3 , RCC_OSC_PLL = 0x4 , RCC_OSC_PLLSAI = 0x5 , RCC_OSC_PLLI2S = 0x6 } |
Available RCC oscillators. | |
enum | rcc_clk_periph { RCC_CLK_GPIOA = 0U , RCC_CLK_GPIOB , RCC_CLK_GPIOD , RCC_CLK_GPIOC , RCC_CLK_GPIOE , RCC_CLK_GPIOF , RCC_CLK_GPIOG , RCC_CLK_GPIOH , RCC_CLK_GPIOI , RCC_CLK_GPIOJ , RCC_CLK_GPIOK , RCC_CLK_CRC = 12U , RCC_CLK_LP_FLITF = 15U , RCC_CLK_LP_SRAM1 , RCC_CLK_LP_SRAM2 , RCC_CLK_BKPSRAM , RCC_CLK_CCMDATARAM = 20U , RCC_CLK_DMA1 , RCC_CLK_DMA2 , RCC_CLK_DMA2D , RCC_CLK_ETHMAC = 25U , RCC_CLK_ETHMACTX , RCC_CLK_ETHMACRX , RCC_CLK_ETHMACPTP , RCC_CLK_OTGHS , RCC_CLK_OTGHSULPI , RCC_CLK_DCMI = 32U , RCC_CLK_CRYP = 32U + 4U , RCC_CLK_HASH , RCC_CLK_RNG , RCC_CLK_OTGFS , RCC_CLK_FMC = 64U , RCC_CLK_QSPI , RCC_CLK_TIM2 = 96U , RCC_CLK_TIM3 , RCC_CLK_TIM4 , RCC_CLK_TIM5 , RCC_CLK_TIM6 , RCC_CLK_TIM7 , RCC_CLK_TIM12 , RCC_CLK_TIM13 , RCC_CLK_TIM14 , RCC_CLK_WWDG = 96U + 11U , RCC_CLK_SPI2 = 96U + 14U , RCC_CLK_SPI3 , RCC_CLK_SPDIFRX , RCC_CLK_USART2 , RCC_CLK_USART3 , RCC_CLK_UART4 , RCC_CLK_UART5 , RCC_CLK_I2C1 , RCC_CLK_I2C2 , RCC_CLK_I2C3 , RCC_CLK_FMPI2C1 , RCC_CLK_CAN1 , RCC_CLK_CAN2 , RCC_CLK_CEC , RCC_CLK_PWR , RCC_CLK_DAC , RCC_CLK_UART7 , RCC_CLK_UART8 , RCC_CLK_TIM1 = 128U , RCC_CLK_TIM8 , RCC_CLK_USART1 = 128U + 4U , RCC_CLK_USART6 , RCC_CLK_ADC1 = 128U + 8U , RCC_CLK_ADC2 , RCC_CLK_ADC3 , RCC_CLK_SDIO , RCC_CLK_SPI1 , RCC_CLK_SPI4 , RCC_CLK_SYSCFG , RCC_CLK_TIM9 = 128U + 16U , RCC_CLK_TIM10 , RCC_CLK_TIM11 , RCC_CLK_SPI5 = 128U + 20U , RCC_CLK_SPI6 , RCC_CLK_SAI1 , RCC_CLK_SAI2 , RCC_CLK_LTDC = 128U + 26U , RCC_CLK_DSI } |
Available AHB/APB peripheral clocks. More... | |
enum | rcc_apb_prescaler { RCC_APB_PRESCALER_DIV1 = 0x0 , RCC_APB_PRESCALER_DIV2 = 0x4 , RCC_APB_PRESCALER_DIV4 = 0x5 , RCC_APB_PRESCALER_DIV8 = 0x6 , RCC_APB_PRESCALER_DIV16 = 0x7 } |
Available RCC APBx prescaler dividers. | |
enum | rcc_ahb_prescaler { RCC_AHB_PRESCALER_DIV1 = 0x0 , RCC_AHB_PRESCALER_DIV2 = 0x8 , RCC_AHB_PRESCALER_DIV4 = 0x9 , RCC_AHB_PRESCALER_DIV8 = 0xA , RCC_AHB_PRESCALER_DIV16 = 0xB , RCC_AHB_PRESCALER_DIV64 = 0xC , RCC_AHB_PRESCALER_DIV128 = 0xD , RCC_AHB_PRESCALER_DIV256 = 0xE , RCC_AHB_PRESCALER_DIV512 = 0xF } |
Available RCC AHB prescaler dividers. | |
enum | rcc_pll_target { RCC_PLL_TARGET_PLL = 0x0 , RCC_PLL_TARGET_I2S = 0x1 , RCC_PLL_TARGET_SAI = 0x2 } |
Available PLL targets. | |
enum | rcc_systemclock_src { RCC_SYSTEMCLOCK_SRC_HSI = 0x0 , RCC_SYSTEMCLOCK_SRC_HSE = 0x1 , RCC_SYSTEMCLOCK_SRC_PLL = 0x2 , RCC_SYSTEMCLOCK_SRC_PLR = 0x3 } |
Available RCC system clock sources. More... | |
enum | rcc_mco1_src { RCC_MCO1_SRC_HSI = 0x0 , RCC_MCO1_SRC_LSE = 0x1 , RCC_MCO1_SRC_HSE = 0x2 , RCC_MCO1_SRC_PLL = 0x3 } |
Available MCO1 clock sources. | |
enum | rcc_mco2_src { RCC_MCO2_SRC_SYS = 0x0 , RCC_MCO2_SRC_I2S = 0x1 , RCC_MCO2_SRC_HSE = 0x2 , RCC_MCO2_SRC_PLL = 0x3 } |
Available MCO2 clock sources. | |
enum | rcc_mco_prescaler { RCC_MCO_PRESCALER_DIV1 = 0x0 , RCC_MCO_PRESCALER_DIV2 = 0x4 , RCC_MCO_PRESCALER_DIV3 = 0x5 , RCC_MCO_PRESCALER_DIV4 = 0x6 , RCC_MCO_PRESCALER_DIV5 = 0x7 } |
Available MCO prescaler dividers. | |
enum | rcc_rtc_src { RCC_RTC_SRC_NON = 0x0 , RCC_RTC_SRC_LSE = 0x1 , RCC_RTC_SRC_LSI = 0x2 , RCC_RTC_SRC_HSE = 0x3 } |
Functions | |
void | rcc_configure_ahb_prescaler (const rcc_ahb_prescaler_t value) |
Set AHB prescaler to the desired value. | |
void | rcc_configure_apb_prescaler (const uint8_t apb, const rcc_apb_prescaler_t value) |
Set APBx prescaler to the desired value. | |
void | rcc_configure_pll_clk (const struct RCCPLLConfig config, const rcc_pll_target_t target) |
Sets the PLL clocks according to config. | |
void | rcc_enable_osc (const rcc_osc_t osc) |
Enable the specified oscillator. | |
void | rcc_disable_osc (const rcc_osc_t osc) |
Disable the specified oscillator. | |
void | rcc_set_systemclock_src (const rcc_systemclock_src_t source) |
Sets the system clock to the specified source. | |
void | rcc_enable_peripheral_clk (const rcc_clk_periph_t peripheral) |
Enables the specified peripheral clock. | |
void | rcc_disable_peripheral_clk (const rcc_clk_periph_t peripheral) |
Disables the specified peripheral clock. | |
void | rcc_enable_lp_peripheral_clk (const rcc_clk_periph_t peripheral) |
Enables the peripheral in low power mode. | |
void | rcc_set_mco1_src (const rcc_mco1_src_t source) |
Set MCO1 to the specified clock source. | |
void | rcc_set_mco2_src (const rcc_mco2_src_t source) |
Set MCO2 to the specified clock source. | |
void | rcc_configure_mco_prescaler (const uint8_t mco, const rcc_mco_prescaler_t value) |
Set MCOx prescaler to the desired value. | |
void | rcc_enable_rtc (const rcc_rtc_src_t source) |
Enables the RTC with specified source. | |
void | rcc_disable_rtc (void) |
Disables the RTC. | |
void | rcc_configure_rtc_prescaler (const uint8_t value) |
Set RTC HSE prescaler to the desired value. | |
Function prototypes for the RCC driver.
This file contains all of the enums, macros, and function prototypes required for a functional RCC driver.
enum rcc_clk_periph |
enum rcc_systemclock_src |
void rcc_configure_ahb_prescaler | ( | const rcc_ahb_prescaler_t | value | ) |
Set AHB prescaler to the desired value.
The available prescale dividers are available in the rcc_ahb_prescaler_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
value | The prescaler divide value |
void rcc_configure_apb_prescaler | ( | const uint8_t | apb, |
const rcc_apb_prescaler_t | value ) |
Set APBx prescaler to the desired value.
The available prescale dividers are available in the rcc_apb_prescaler_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
apb | The selected APB (1..2) |
value | The prescaler divide value |
void rcc_configure_mco_prescaler | ( | const uint8_t | mco, |
const rcc_mco_prescaler_t | value ) |
Set MCOx prescaler to the desired value.
The available prescale dividers are available in the rcc_mco_prescaler_t enum. Any other value will be ignored.
mco | The selected MCO (1..2) |
value | The prescaler divide value |
void rcc_configure_pll_clk | ( | const struct RCCPLLConfig | config, |
const rcc_pll_target_t | target ) |
Sets the PLL clocks according to config.
The configuration values can be found in the RCCPLLConfig struct. Extra care must be taken with PLL values as their bits are not the same and wrapping may happen. Also a target (PLL, I2S, SAI) must be specified. A DSB instruction is inserted after each RCC register write as per errata.
peripheral | The peripheral clock |
target | The target PLL |
void rcc_configure_rtc_prescaler | ( | const uint8_t | value | ) |
Set RTC HSE prescaler to the desired value.
value | The prescaler divide value (0..31) |
void rcc_disable_osc | ( | const rcc_osc_t | osc | ) |
Disable the specified oscillator.
The available oscilattors are available in the rcc_osc_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
osc | The selected oscillator |
void rcc_disable_peripheral_clk | ( | const rcc_clk_periph_t | peripheral | ) |
Disables the specified peripheral clock.
The available peripherals can be found in the rcc_clk_periph_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
peripheral | The peripheral clock |
void rcc_enable_lp_peripheral_clk | ( | const rcc_clk_periph_t | peripheral | ) |
Enables the peripheral in low power mode.
The available peripherals can be found in the rcc_clk_periph_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
DISCLAIMER: Only enable peripherals that actually exist on hardware!
peripheral | The peripheral clock |
void rcc_enable_osc | ( | const rcc_osc_t | osc | ) |
Enable the specified oscillator.
The available oscilattors are available in the rcc_osc_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
osc | The selected oscillator |
void rcc_enable_peripheral_clk | ( | const rcc_clk_periph_t | peripheral | ) |
Enables the specified peripheral clock.
The available peripherals can be found in the rcc_clk_periph_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
DISCLAIMER: Only enable peripherals that actually exist on hardware!
peripheral | The peripheral clock |
void rcc_enable_rtc | ( | const rcc_rtc_src_t | source | ) |
Enables the RTC with specified source.
The available RTC sources can be found in the rcc_rtc_src_t enum. Any other value will be ignored.
source | The RTC clock source |
void rcc_set_mco1_src | ( | const rcc_mco1_src_t | source | ) |
Set MCO1 to the specified clock source.
The available source clocks are available in the rcc_mco1_src_t enum. Any other value will be ignored.
source | The specified clock source |
void rcc_set_mco2_src | ( | const rcc_mco2_src_t | source | ) |
Set MCO2 to the specified clock source.
The available source clocks are available in the rcc_mco2_src_t enum. Any other value will be ignored.
source | The specified clock source |
void rcc_set_systemclock_src | ( | const rcc_systemclock_src_t | source | ) |
Sets the system clock to the specified source.
The available systemclock sources are located in the rcc_systemclock_src_t enum. Any other value will be ignored. A DSB instruction is inserted after each RCC register write as per errata.
source | The selected clock source |