libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
rcc.c File Reference
#include <stddef.h>
#include <libopencm3/cm3/assert.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/pwr.h>
#include <libopencm3/stm32/flash.h>
Include dependency graph for rcc.c:

Go to the source code of this file.

Macros

#define HZ_PER_MHZ   1000000UL
 
#define HZ_PER_KHZ   1000UL
 

Functions

static void rcc_configure_pll (uint32_t clkin, const struct pll_config *config, int pll_num)
 
static void rcc_set_and_enable_plls (const struct rcc_pll_config *config)
 
static uint16_t rcc_prediv_log_skip32_div (uint16_t clk_mhz, uint32_t div_val)
 
static uint16_t rcc_prediv_3bit_log_div (uint16_t clk_mhz, uint32_t div_val)
 
static void rcc_clock_setup_domain1 (const struct rcc_pll_config *config)
 
static void rcc_clock_setup_domain2 (const struct rcc_pll_config *config)
 
static void rcc_clock_setup_domain3 (const struct rcc_pll_config *config)
 
void rcc_clock_setup_pll (const struct rcc_pll_config *config)
 Setup the base PLLs and clock domains for the STM32H7. More...
 
uint32_t rcc_get_bus_clk_freq (enum rcc_clock_source source)
 Get the clock rate (in Hz) of the specified clock source. More...
 
uint32_t rcc_get_usart_clk_freq (uint32_t usart)
 Get the peripheral clock speed for the USART at base specified. More...
 
uint32_t rcc_get_timer_clk_freq (uint32_t timer)
 Get the peripheral clock speed for the Timer at base specified. More...
 
uint32_t rcc_get_i2c_clk_freq (uint32_t i2c)
 Get the peripheral clock speed for the I2C device at base specified. More...
 
uint32_t rcc_get_spi_clk_freq (uint32_t spi)
 Get the peripheral clock speed for the SPI device at base specified. More...
 
uint32_t rcc_get_fdcan_clk_freq (uint32_t fdcan)
 Get the peripheral clock speed for the FDCAN device at base specified. More...
 
void rcc_set_peripheral_clk_sel (uint32_t periph, uint32_t sel)
 Set the clksel value for the specified peripheral. More...
 
void rcc_set_fdcan_clksel (uint8_t clksel)
 Set the clock select for the FDCAN devices. More...
 
void rcc_set_rng_clksel (uint8_t clksel)
 Set the clock select for the RNG device. More...
 
void rcc_set_spi123_clksel (uint8_t clksel)
 Set the clock select for the SPI 1/2/3 devices. More...
 
void rcc_set_spi45_clksel (uint8_t clksel)
 Set the clock select for the SPI 4/5 devices. More...
 

Variables

struct {
   uint16_t   sysclk_mhz
 
   uint16_t   cpu_mhz
 
   uint16_t   hclk_mhz
 
   struct {
      uint16_t   pclk1_mhz
 
      uint16_t   pclk2_mhz
 
      uint16_t   pclk3_mhz
 
      uint16_t   pclk4_mhz
 
   }   per
 
   struct pll_clocks {
      uint16_t   p_mhz
 
      uint16_t   q_mhz
 
      uint16_t   r_mhz
 
   }   pll1
 
   struct pll_clocks {
      uint16_t   p_mhz
 
      uint16_t   q_mhz
 
      uint16_t   r_mhz
 
   }   pll2
 
   struct pll_clocks {
      uint16_t   p_mhz
 
      uint16_t   q_mhz
 
      uint16_t   r_mhz
 
   }   pll3
 
   uint16_t   hse_khz
 
rcc_clock_tree
 

Macro Definition Documentation

◆ HZ_PER_KHZ

#define HZ_PER_KHZ   1000UL

Definition at line 16 of file rcc.c.

◆ HZ_PER_MHZ

#define HZ_PER_MHZ   1000000UL

Definition at line 15 of file rcc.c.

Function Documentation

◆ rcc_clock_setup_domain1()

static void rcc_clock_setup_domain1 ( const struct rcc_pll_config config)
static

Definition at line 146 of file rcc.c.

References rcc_pll_config::core_pre, rcc_pll_config::hpre, rcc_pll_config::ppre3, rcc_clock_tree, RCC_D1CFGR, RCC_D1CFGR_D1CPRE, RCC_D1CFGR_D1HPRE, RCC_D1CFGR_D1PPRE, rcc_prediv_3bit_log_div(), and rcc_prediv_log_skip32_div().

Referenced by rcc_clock_setup_pll().

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

◆ rcc_clock_setup_domain2()

static void rcc_clock_setup_domain2 ( const struct rcc_pll_config config)
static

Definition at line 160 of file rcc.c.

References rcc_pll_config::ppre1, rcc_pll_config::ppre2, rcc_clock_tree, RCC_D2CFGR, RCC_D2CFGR_D2PPRE1, RCC_D2CFGR_D2PPRE2, and rcc_prediv_3bit_log_div().

Referenced by rcc_clock_setup_pll().

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

◆ rcc_clock_setup_domain3()

static void rcc_clock_setup_domain3 ( const struct rcc_pll_config config)
static

Definition at line 172 of file rcc.c.

References rcc_pll_config::ppre4, rcc_clock_tree, RCC_D3CFGR, RCC_D3CFGR_D3PPRE, and rcc_prediv_3bit_log_div().

Referenced by rcc_clock_setup_pll().

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

◆ rcc_configure_pll()

static void rcc_configure_pll ( uint32_t  clkin,
const struct pll_config *  config,
int  pll_num 
)
static

◆ rcc_prediv_3bit_log_div()

static uint16_t rcc_prediv_3bit_log_div ( uint16_t  clk_mhz,
uint32_t  div_val 
)
static

Definition at line 138 of file rcc.c.

Referenced by rcc_clock_setup_domain1(), rcc_clock_setup_domain2(), and rcc_clock_setup_domain3().

Here is the caller graph for this function:

◆ rcc_prediv_log_skip32_div()

static uint16_t rcc_prediv_log_skip32_div ( uint16_t  clk_mhz,
uint32_t  div_val 
)
static

Definition at line 126 of file rcc.c.

References RCC_D1CFGR_D1CPRE_DIV16.

Referenced by rcc_clock_setup_domain1().

Here is the caller graph for this function:

◆ rcc_set_and_enable_plls()

static void rcc_set_and_enable_plls ( const struct rcc_pll_config config)
static

Variable Documentation

◆ cpu_mhz

uint16_t cpu_mhz

Definition at line 21 of file rcc.c.

◆ hclk_mhz

uint16_t hclk_mhz

Definition at line 22 of file rcc.c.

◆ hse_khz

uint16_t hse_khz

Definition at line 34 of file rcc.c.

◆ p_mhz

uint16_t p_mhz

Definition at line 30 of file rcc.c.

◆ pclk1_mhz

uint16_t pclk1_mhz

Definition at line 24 of file rcc.c.

◆ pclk2_mhz

uint16_t pclk2_mhz

Definition at line 25 of file rcc.c.

◆ pclk3_mhz

uint16_t pclk3_mhz

Definition at line 26 of file rcc.c.

◆ pclk4_mhz

uint16_t pclk4_mhz

Definition at line 27 of file rcc.c.

◆ 

struct { ... } per

◆ 

struct { ... } ::pll_clocks pll1

◆ 

struct { ... } ::pll_clocks pll2

◆ 

struct { ... } ::pll_clocks pll3

◆ q_mhz

uint16_t q_mhz

Definition at line 31 of file rcc.c.

◆ r_mhz

uint16_t r_mhz

Definition at line 32 of file rcc.c.

◆ 

◆ sysclk_mhz

uint16_t sysclk_mhz

Definition at line 20 of file rcc.c.