Struct Clocks

Source
pub struct Clocks {
    pub input_src: InputSrc,
    pub pll: PllCfg,
    pub hclk_prescaler: HclkPrescaler,
    pub apb1_prescaler: ApbPrescaler,
    pub apb2_prescaler: ApbPrescaler,
    pub clk48_src: Clk48Src,
    pub lpuart_src: LpUartSrc,
    pub hse_bypass: bool,
    pub security_system: bool,
    pub hsi48_on: bool,
    pub boost_mode: bool,
    pub can_src: CanSrc,
}
Expand description

Settings used to configure clocks. Create this struct by using its Default::default() implementation, then modify as required, referencing your RM’s clock tree, or Stm32Cube IDE’s interactive clock manager. Apply settings by running .setup().

Fields§

§input_src: InputSrc

The input source for the system and peripheral clocks. Eg HSE, HSI, PLL etc

§pll: PllCfg

Enable and speed status for the main PLL

§hclk_prescaler: HclkPrescaler

The value to divide SYSCLK by, to get systick and peripheral clocks. Also known as AHB divider

§apb1_prescaler: ApbPrescaler

The divider of HCLK to get the APB1 peripheral clock

§apb2_prescaler: ApbPrescaler

The divider of HCLK to get the APB2 peripheral clock

§clk48_src: Clk48Src

The input source for the 48Mhz clock used by USB.

§lpuart_src: LpUartSrc§hse_bypass: bool

Bypass the HSE output, for use with oscillators that don’t need it. Saves power, and frees up the pin for use as GPIO.

§security_system: bool§hsi48_on: bool

Enable the HSI48. For L4, this is only applicable for some devices.

§boost_mode: bool

Range 1 boost mode: Used to increase regulator voltage to 1.28v, for when system clock frequency is up to 170Mhz. Defaults to true.

§can_src: CanSrc

FDCAN kernel clock selection. Defaults to APB1.

Implementations§

Source§

impl Clocks

Source

pub fn setup(&self) -> Result<(), RccError>

Setup common and return Ok if the config is valid. Abort the setup if speeds are invalid. Use the STM32CubeIDE Clock Configuration tab to help identify valid configs. Use the default() implementation as a safe baseline.

Source

pub fn reselect_input(&self) -> Result<(), RccError>

Re-select input source; used after Stop and Standby modes, where the system reverts to MSI or HSI after wake.

Source

pub fn sysclk(&self) -> u32

Get the sysclock frequency, in hz.

Source

pub fn pll_is_enabled(&self) -> bool

Check if the PLL is enabled. This is useful if checking whether to re-enable the PLL after exiting Stop or Standby modes, eg so you don’t re-enable if it was already re-enabled in a different context. eg:

if !clock_cfg.pll_is_enabled() {
    clock_cfg.reselect_input();
}
Source

pub fn hclk(&self) -> u32

Get the HCLK frequency, in hz

Source

pub fn systick(&self) -> u32

Get the systick frequency, in hz

Source

pub fn usb(&self) -> u32

Source

pub fn apb1(&self) -> u32

Get the APB1 peripheral clock frequency frequency, in hz

Source

pub fn apb1_timer(&self) -> u32

Get the frequency used by APB1 timers, in hz

Source

pub fn apb2(&self) -> u32

Get the APB2 peipheral clock frequency, in hz.

Source

pub fn apb2_timer(&self) -> u32

Source

pub fn validate_speeds(&self) -> Result<(), RccError>

Trait Implementations§

Source§

impl Default for Clocks

Source§

fn default() -> Self

This default configures clocks with a HSI, with system and peripheral clocks at full rated speed. All peripheral. Speeds -> L4: 80Mhz. L5: 110Mhz. G0: 64Mhz. G4: 170Mhz. WB: 64Mhz.

Auto Trait Implementations§

§

impl Freeze for Clocks

§

impl RefUnwindSafe for Clocks

§

impl Send for Clocks

§

impl Sync for Clocks

§

impl Unpin for Clocks

§

impl UnwindSafe for Clocks

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.