Struct CFGR

Source
pub struct CFGR { /* private fields */ }
Expand description

Clock configuration

An instance of this struct is acquired from the RCC struct.

let dp = pac::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
use_cfgr(&mut rcc.cfgr)

Implementations§

Source§

impl CFGR

Source

pub fn use_hse(self, freq: Megahertz) -> Self

Uses HSE (external oscillator) instead of HSI (internal RC oscillator) as the clock source.

Will result in a hang if an external oscillator is not connected or it fails to start, unless css is enabled.

§Panics

Panics if conversion from Megahertz to Hertz produces a value greater then u32::MAX.

Source

pub fn use_pll(self) -> Self

Set this to disallow bypass the PLLCLK for the systemclock generation.

Source

pub fn bypass_hse(self) -> Self

Enable HSE bypass.

Uses user provided clock signal instead of an external oscillator. OSC_OUT pin is free and can be used as GPIO.

No effect if HSE is not enabled.

Source

pub fn enable_css(self) -> Self

Enable CSS (Clock Security System).

System clock is automatically switched to HSI and an interrupt (CSSI) is generated when HSE clock failure is detected.

No effect if HSE is not enabled.

Source

pub fn hclk(self, freq: Megahertz) -> Self

Sets a frequency for the AHB bus.

§Panics

Panics if conversion from Megahertz to Hertz produces a value greater then u32::MAX.

Source

pub fn pclk1(self, freq: Megahertz) -> Self

Sets a frequency for the APB1 bus

  • Maximal supported frequency: 36 Mhz

If not manually set, it will be set to CFGR::sysclk frequency or CFGR::sysclk frequency / 2, if CFGR::sysclk > 36 Mhz

§Panics

Panics if conversion from Megahertz to Hertz produces a value greater then u32::MAX.

Source

pub fn pclk2(self, freq: Megahertz) -> Self

Sets a frequency for the APB2 bus

§Resolution and Limits
  • Maximal supported frequency with HSE: 72 Mhz
  • Maximal supported frequency without HSE: 64 Mhz

This is true for devices except the following devices, as these allow finer resolutions even when using the internal oscillator:

[stm32f302xd,stm32f302xe,stm32f303xd,stm32f303xe,stm32f398]
§Panics

Panics if conversion from Megahertz to Hertz produces a value greater then u32::MAX.

Source

pub fn sysclk(self, freq: Megahertz) -> Self

Sets the system (core) frequency

§Resolution and Limits
  • Maximal supported frequency with HSE: 72 Mhz
  • Maximal supported frequency without HSE: 64 Mhz

If CFGR::use_hse is not set, HSI / 2 will be used. Only multiples of (HSI / 2) (4 Mhz) are allowed.

This is true for devices except the following devices, as these allow finer resolutions even when using the internal oscillator:

[stm32f302xd,stm32f302xe,stm32f303xd,stm32f303xe,stm32f398]
§Panics

Panics if conversion from Megahertz to Hertz produces a value greater then u32::MAX.

Source

pub fn freeze(self, acr: &mut ACR) -> Clocks

Freezes the clock configuration, making it effective

This function internally calculates the specific. divisors for the different clock peripheries.

§Panics

If any of the set frequencies via sysclk, hclk, pclk1 or pclk2 are invalid or can not be reached because of e.g. to low frequencies of the former, as sysclk depends on the configuration of hclk this function will panic.

Trait Implementations§

Source§

impl Default for CFGR

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for CFGR

§

impl RefUnwindSafe for CFGR

§

impl Send for CFGR

§

impl Sync for CFGR

§

impl Unpin for CFGR

§

impl UnwindSafe for CFGR

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.