embassy-rp

Crates

git

Versions

rp2040

Flavors

Struct ClockConfig

Source
#[non_exhaustive]
pub struct ClockConfig { pub rosc: Option<RoscConfig>, pub xosc: Option<XoscConfig>, pub ref_clk: RefClkConfig, pub sys_clk: SysClkConfig, pub peri_clk_src: Option<PeriClkSrc>, pub usb_clk: Option<UsbClkConfig>, pub adc_clk: Option<AdcClkConfig>, pub rtc_clk: Option<RtcClkConfig>, pub core_voltage: CoreVoltage, pub voltage_stabilization_delay_us: Option<u32>, }
Expand description

CLock configuration.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§rosc: Option<RoscConfig>

Ring oscillator configuration.

§xosc: Option<XoscConfig>

External oscillator configuration.

§ref_clk: RefClkConfig

Reference clock configuration.

§sys_clk: SysClkConfig

System clock configuration.

§peri_clk_src: Option<PeriClkSrc>

Peripheral clock source configuration.

§usb_clk: Option<UsbClkConfig>

USB clock configuration.

§adc_clk: Option<AdcClkConfig>

ADC clock configuration.

§rtc_clk: Option<RtcClkConfig>

RTC clock configuration.

§core_voltage: CoreVoltage

Core voltage scaling. Defaults to 1.10V.

§voltage_stabilization_delay_us: Option<u32>

Voltage stabilization delay in microseconds. If not set, defaults will be used based on voltage level.

Implementations§

Source§

impl ClockConfig

Source

pub fn crystal(crystal_hz: u32) -> Self

Clock configuration derived from external crystal.

This uses default settings for most parameters, suitable for typical use cases. For manual control of PLL parameters, use new_manual() or modify the struct fields directly.

Source

pub fn rosc() -> Self

Clock configuration from internal oscillator.

Source

pub fn system_freq(hz: u32) -> Result<Self, ClockError>

Configure clocks derived from an external crystal with specific system frequency.

This function calculates optimal PLL parameters to achieve the requested system frequency. This only works for the usual 12MHz crystal. In case a different crystal is used, You will have to set the PLL parameters manually.

§Arguments
  • sys_freq_hz - The desired system clock frequency in Hz
§Returns

A ClockConfig configured to achieve the requested system frequency using the the usual 12Mhz crystal, or an error if no valid parameters can be found.

§Note on core voltage:

For RP2040: To date the only officially documented core voltages (see Datasheet section 2.15.3.1. Instances) are:

  • Up to 133MHz: V1_10 (default)
  • Above 133MHz: V1_15, but in the context of the datasheet covering reaching up to 200Mhz That way all other frequencies below 133MHz or above 200MHz are not explicitly documented and not covered here. In case You want to go below 133MHz or above 200MHz and want a different voltage, You will have to set that manually and with caution.

For RP235x: At this point in time there is no official manufacturer endorsement for running the chip on other core voltages and/or other clock speeds than the defaults. Using this function is experimental and may not work as expected or even damage the chip.

§Returns

A Result containing either the configured ClockConfig or a ClockError.

Source

pub fn manual_pll( xosc_hz: u32, pll_config: PllConfig, core_voltage: CoreVoltage, ) -> Self

Configure with manual PLL settings for full control over system clock

This method provides a simple way to configure the system with custom PLL parameters without needing to understand the full nested configuration structure.

§Arguments
  • xosc_hz - The frequency of the external crystal in Hz
  • pll_config - The PLL configuration parameters to achieve desired frequency
  • core_voltage - Voltage scaling for overclocking (required for >133MHz)
§Returns

A ClockConfig configured with the specified PLL parameters

§Example
// Configure for 200MHz operation
let config = Config::default();
config.clocks = ClockConfig::manual_pll(
    12_000_000,
    PllConfig {
        refdiv: 1,    // Reference divider (12 MHz / 1 = 12 MHz)
        fbdiv: 100,   // Feedback divider (12 MHz * 100 = 1200 MHz VCO)
        post_div1: 3, // First post divider (1200 MHz / 3 = 400 MHz)
        post_div2: 2, // Second post divider (400 MHz / 2 = 200 MHz)
    },
    CoreVoltage::V1_15
);

Trait Implementations§

Source§

impl Default for ClockConfig

Source§

fn default() -> Self

Creates a minimal default configuration with safe values.

This configuration uses the ring oscillator (ROSC) as the clock source and sets minimal defaults that guarantee a working system. It’s intended as a starting point for manual configuration.

Most users should use one of the more specific configuration functions:

  • ClockConfig::crystal() - Standard configuration with external crystal
  • ClockConfig::rosc() - Configuration using only the internal oscillator
  • ClockConfig::system_freq() - Configuration for a specific system frequency

Auto Trait Implementations§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.