Skip to content

Commit

Permalink
Set startup_delay_multiplier of XOSC to 64
Browse files Browse the repository at this point in the history
  • Loading branch information
jannic committed Jan 1, 2024
1 parent 38f5963 commit f4340cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- bump MSRV to 1.65
- Set startup\_delay\_multiplier of XOSC to 64, and make it configurable.
This should increase compatibility with boards where the oscillator starts up
more slowly than on the Raspberry Pico.

## [0.9.1]

Expand Down
27 changes: 26 additions & 1 deletion rp2040-hal/src/xosc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,36 @@ pub enum Error {
}

/// Blocking helper method to setup the XOSC without going through all the steps.
///
/// This uses a startup_delay_multiplier of 64, which is a rather conservative value
/// that should work even if the XOSC starts up slowly. In case you need a fast boot
/// sequence, and your XOSC starts up quickly enough, use [`setup_xosc_blocking_custom_delay`].
pub fn setup_xosc_blocking(
xosc_dev: XOSC,
frequency: HertzU32,
) -> Result<CrystalOscillator<Stable>, Error> {
let initialized_xosc = CrystalOscillator::new(xosc_dev).initialize(frequency, 1)?;
let initialized_xosc = CrystalOscillator::new(xosc_dev).initialize(frequency, 64)?;

let stable_xosc_token = nb::block!(initialized_xosc.await_stabilization()).unwrap();

Ok(initialized_xosc.get_stable(stable_xosc_token))
}

/// Blocking helper method to setup the XOSC without going through all the steps.
///
/// This function allows setting a startup_delay_multiplier to tune the amount of time
/// the chips waits for the XOSC to stabilize.
/// The default value in the C SDK is 1, which should work on the Raspberry Pico, and many
/// third-party boards.
/// [`setup_xosc_blocking`], uses a conservative value of 64, which is the value commonly
/// used on slower-starting oscillators.
pub fn setup_xosc_blocking_custom_delay(
xosc_dev: XOSC,
frequency: HertzU32,
startup_delay_multiplier: u32,
) -> Result<CrystalOscillator<Stable>, Error> {
let initialized_xosc =
CrystalOscillator::new(xosc_dev).initialize(frequency, startup_delay_multiplier)?;

let stable_xosc_token = nb::block!(initialized_xosc.await_stabilization()).unwrap();

Expand Down

0 comments on commit f4340cd

Please sign in to comment.