15#define HZ_PER_MHZ 1000000UL
16#define HZ_PER_KHZ 1000UL
45static void rcc_configure_pll(uint32_t clkin,
const struct pll_config *config,
int pll_num) {
47 if (config->divm == 0 || pll_num < 1 || pll_num > 3) {
51 struct pll_clocks *pll_tree_ptr;
54 }
else if (pll_num == 2) {
65 uint8_t vco_addshift = 4 * (pll_num - 1);
68 uint32_t pll_clk_mhz = (clkin / config->divm) /
HZ_PER_MHZ;
69 if (pll_clk_mhz > 2 && pll_clk_mhz <= 4) {
71 }
else if (pll_clk_mhz > 4 && pll_clk_mhz <= 8) {
73 }
else if (pll_clk_mhz > 8) {
78 uint32_t pll_vco_clk_mhz = (pll_clk_mhz * config->divn);
79 if (pll_vco_clk_mhz <= 420) {
84 uint8_t diven_addshift = 3 * (pll_num - 1);
85 if (config->divp > 0) {
88 pll_tree_ptr->p_mhz = pll_vco_clk_mhz / config->divp;
90 if (config->divq > 0) {
93 pll_tree_ptr->q_mhz = pll_vco_clk_mhz / config->divq;
95 if (config->divr > 0) {
98 pll_tree_ptr->r_mhz = pll_vco_clk_mhz / config->divr;
102 uint8_t cr_addshift = 2 * (pll_num - 1);
130 return clk_mhz >> (div_val - 7);
132 return clk_mhz >> (div_val - 6);
142 return clk_mhz >> (div_val - 3);
270 uint32_t clksel, pclk;
371 volatile uint32_t *reg;
423 uint32_t regval = (*reg & mask) | val;
#define cm3_assert_not_reached()
Check if unreachable code is reached.
void flash_prefetch_enable(void)
This buffer is used for instruction fetches and may or may not be enabled by default,...
void flash_prefetch_disable(void)
Note carefully the clock restrictions under which the prefetch buffer may be set to disabled.
void flash_set_ws(uint32_t ws)
Set the Number of Wait States.
#define FLASH_ACR_LATENCY_0WS
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Set the voltage scaling/strength for the internal SMPS/LDO while running.
void pwr_set_mode(enum pwr_sys_mode mode, uint8_t smps_level)
Set power system based on "System Supply Configurations" table in reference manual.
#define RCC_CFGR_SWS_MASK
#define RCC_CFGR_SWS_PLL1
#define RCC_CFGR_SWS_SHIFT
#define RCC_CFGR_SW_SHIFT
#define RCC_D1CCIPR_CKPERSEL_HSE
#define RCC_D1CCIPR_CKPERSEL_HSI
#define RCC_D1CFGR_D1PPRE(ppre)
#define RCC_D1CFGR_D1CPRE_DIV16
#define RCC_D1CFGR_D1HPRE(hpre)
#define RCC_D1CFGR_D1CPRE(cpre)
#define RCC_D2CCIP1R_SPI123SEL_PLL3P
#define RCC_D2CCIP1R_SPI123SEL_PLL1Q
#define RCC_D2CCIP1R_FDCANSEL_PLL1Q
#define RCC_D2CCIP1R_SPI45SEL_PLL2Q
#define RCC_D2CCIP1R_SPI45SEL_PLL3Q
#define RCC_D2CCIP1R_SPI45SEL_HSE
#define RCC_D2CCIP1R_FDCANSEL_HSE
#define RCC_D2CCIP1R_FDCANSEL_PLL2Q
#define RCC_D2CCIP1R_SPI123SEL_PERCK
#define RCC_D2CCIP1R_SPI45SEL_APB4
#define RCC_D2CCIP1R_SPI45SEL_HSI
#define RCC_D2CCIP1R_SPI123SEL_PLL2P
#define RCC_D2CCIP2R_USARTSEL_PLL3Q
#define RCC_D2CCIP2R_USARTSEL_PLL2Q
#define RCC_D2CCIP2R_USARTSEL_LSE
#define RCC_D2CCIP2R_USARTSEL_HSI
#define RCC_D2CCIP2R_USARTSEL_PCLK
#define RCC_D2CCIP2R_USARTSEL_CSI
#define RCC_D2CFGR_D2PPRE1(ppre)
#define RCC_D2CFGR_D2PPRE2(ppre)
#define RCC_D3CFGR_D3PPRE(ppre)
#define RCC_D2CCIP2R_USARTSEL_MASK
#define RCC_D2CCIP1R_SPI123SEL_MASK
#define RCC_D2CCIP1R_FDCANSEL_MASK
#define RCC_D1CCIPR_CKPERSEL_SHIFT
#define RCC_HSI_BASE_FREQUENCY
#define RCC_D1CCIPR_CKPERSEL_MASK
#define RCC_D2CCIP2R_USART234578SEL_SHIFT
#define RCC_D2CCIP2R_RNGSEL_SHIFT
#define RCC_D2CCIP1R_SPI123SEL_SHIFT
#define RCC_D2CCIP2R_USART16SEL_SHIFT
#define RCC_D2CCIP2R_RNGSEL_MASK
rcc_clock_source
Enumerations for core system/bus clocks for user/driver/system access to base bus clocks not directly...
#define RCC_D2CCIP1R_SPI45SEL_MASK
#define RCC_D2CCIP1R_FDCANSEL_SHIFT
#define RCC_D2CCIP1R_SPI45SEL_SHIFT
uint32_t rcc_get_fdcan_clk_freq(uint32_t fdcan)
Get the peripheral clock speed for the FDCAN device at base specified.
void rcc_clock_setup_pll(const struct rcc_pll_config *config)
Setup the base PLLs and clock domains for the STM32H7.
uint32_t rcc_get_bus_clk_freq(enum rcc_clock_source source)
Get the clock rate (in Hz) of the specified clock source.
uint32_t rcc_get_spi_clk_freq(uint32_t spi)
Get the peripheral clock speed for the SPI device at base specified.
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
void rcc_set_rng_clksel(uint8_t clksel)
Set the clock select for the RNG device.
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
void rcc_set_fdcan_clksel(uint8_t clksel)
Set the clock select for the FDCAN devices.
void rcc_set_spi123_clksel(uint8_t clksel)
Set the clock select for the SPI 1/2/3 devices.
uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
Get the peripheral clock speed for the I2C device at base specified.
void rcc_set_peripheral_clk_sel(uint32_t periph, uint32_t sel)
Set the clksel value for the specified peripheral.
void rcc_set_spi45_clksel(uint8_t clksel)
Set the clock select for the SPI 4/5 devices.
#define RCC_PLLCFGR_PLLRGE_4_8MHZ
#define RCC_PLLCFGR_DIVR1EN
#define RCC_PLLCFGR_PLL1VCO_MED
#define RCC_PLLCFGR_DIVQ1EN
#define RCC_PLLCFGR_PLLRGE_2_4MHZ
#define RCC_PLLCFGR_PLLRGE_8_16MHZ
#define RCC_PLLCFGR_DIVP1EN
#define RCC_PLLCFGR_PLL1RGE_SHIFT
#define RCC_PLLCKSELR_PLLSRC_HSI
#define RCC_PLLCKSELR_DIVM3(n)
#define RCC_PLLCKSELR_DIVM1(n)
#define RCC_PLLCKSELR_DIVM2(n)
#define RCC_PLLNDIVR_DIVN(n)
#define RCC_PLLNDIVR_DIVR(n)
#define RCC_PLLNDIVR_DIVQ(n)
#define RCC_PLLNDIVR_DIVP(n)
static uint16_t rcc_prediv_3bit_log_div(uint16_t clk_mhz, uint32_t div_val)
struct @0::pll_clocks pll1
static struct @0 rcc_clock_tree
struct @0::pll_clocks pll2
static uint16_t rcc_prediv_log_skip32_div(uint16_t clk_mhz, uint32_t div_val)
static void rcc_clock_setup_domain2(const struct rcc_pll_config *config)
struct @0::pll_clocks pll3
static void rcc_clock_setup_domain3(const struct rcc_pll_config *config)
static void rcc_clock_setup_domain1(const struct rcc_pll_config *config)
static void rcc_set_and_enable_plls(const struct rcc_pll_config *config)
static void rcc_configure_pll(uint32_t clkin, const struct pll_config *config, int pll_num)
uint8_t divm
Pre-divider value for each PLL.
PLL Configuration structure.
uint8_t ppre3
APB3 Peripheral prescaler note: domain 1.
uint8_t core_pre
Core prescaler note: domain 1.
struct rcc_pll_config::pll_config pll1
uint8_t ppre1
APB1 Peripheral prescaler note: domain 2.
struct rcc_pll_config::pll_config pll2
uint8_t smps_level
If using SMPS, voltage level to set.
uint8_t ppre2
APB2 Peripheral prescaler note: domain 2.
uint8_t hpre
HCLK3 prescaler note: domain 1.
uint8_t ppre4
APB4 Peripheral prescaler note: domain 3.
enum rcc_osc sysclock_source
SYSCLK source input selection.
uint8_t flash_waitstates
Latency Value to set for flahs.
enum pwr_vos_scale voltage_scale
LDO/SMPS Voltage scale used for this frequency.
uint32_t hse_frequency
User specified HSE frequency, 0 if none.
struct rcc_pll_config::pll_config pll3
PLL1-PLL3 configurations.
uint8_t pll_source
RCC_PLLCKSELR_PLLSRC_xxx value.
enum pwr_sys_mode power_mode
LDO/SMPS configuration for device.