embassy-rp

Crates

git

Versions

rp2040

Flavors

Module clocks

Source
Expand description

§Clock configuration for the RP2040 and RP235x microcontrollers.

§Clock Configuration API

This module provides both high-level convenience functions and low-level manual configuration options for the RP2040 clock system.

§High-Level Convenience Functions

For most users, these functions provide an easy way to configure clocks:

  • ClockConfig::system_freq(125_000_000) - Set system clock to a specific frequency with automatic voltage scaling
  • ClockConfig::crystal(12_000_000) - Default configuration with 12MHz crystal giving 125MHz system clock

§Manual Configuration

For advanced users who need precise control:

// Start with default configuration and customize it
let mut config = ClockConfig::default();

// Set custom PLL parameters
config.xosc = Some(XoscConfig {
    hz: 12_000_000,
    sys_pll: Some(PllConfig {
        refdiv: 1,
        fbdiv: 200,
        post_div1: 6,
        post_div2: 2,
    }),
    // ... other fields
});

// Set voltage for overclocking
config.core_voltage = CoreVoltage::V1_15;

§Examples

§Standard 125MHz (rp2040) or 150Mhz (rp235x) configuration

let config = ClockConfig::crystal(12_000_000);

Or using the default configuration:

let config = ClockConfig::default();

§Overclock to 200MHz

let config = ClockConfig::system_freq(200_000_000);

§Manual configuration for advanced scenarios

use embassy_rp::clocks::{ClockConfig, XoscConfig, PllConfig, CoreVoltage};

// Start with defaults and customize
let mut config = ClockConfig::default();
config.core_voltage = CoreVoltage::V1_15;
// Set other parameters as needed...

Structs§

AdcClkConfig
ADC clock config.
ClockConfig
CLock configuration.
Gpin
General purpose clock input driver.
Gpout
General purpose clock output driver.
PllConfig
PLL configuration.
RefClkConfig
Reference clock config.
RoscConfig
On-chip ring oscillator configuration.
RoscRng
Random number generator based on the ROSC RANDOMBIT register.
RtcClkConfig
RTC clock config.
SysClkConfig
SYS clock config.
UsbClkConfig
USB clock config.
XoscConfig
Crystal oscillator configuration.

Enums§

AdcClkSrc
ADC clock source.
ClockError
Clock error types.
CoreVoltage
Core voltage regulator settings.
GpoutSrc
Gpout clock source.
PeriClkSrc
Peripheral clock sources.
RefClkSrc
Reference clock source.
RoscRange
ROSC freq range.
RtcClkSrc
RTC clock source.
SysClkSrc
SYS clock source.
UsbClkSrc
USB clock source.

Traits§

GpinPin
General purpose input clock pin.
GpoutPin
General purpose clock output pin.

Functions§

clk_adc_freq
ADC clock frequency.
clk_peri_freq
Peripheral clock frequency.
clk_ref_freq
REF clock frequency.
clk_rtc_freq
RTC clock frequency.
clk_sys_freq
SYS clock frequency.
clk_usb_freq
USB clock frequency.
core_voltage
The core voltage of the chip.
dormant_sleep
Enter the DORMANT sleep state. This will stop all internal clocks and can only be exited through resets, dormant-wake GPIO interrupts, and RTC interrupts. If RTC is clocked from an internal clock source it will be stopped and not function as a wakeup source.
pll_sys_freq
PLL SYS clock frequency.
pll_usb_freq
PLL USB clock frequency.
rosc_freq
ROSC clock frequency.
xosc_freq
XOSC clock frequency.