diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 2f8f4f0a9..0e8fb7583 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -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] diff --git a/rp2040-hal/src/xosc.rs b/rp2040-hal/src/xosc.rs index 2285687b4..5ee008535 100644 --- a/rp2040-hal/src/xosc.rs +++ b/rp2040-hal/src/xosc.rs @@ -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, 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, Error> { + let initialized_xosc = + CrystalOscillator::new(xosc_dev).initialize(frequency, startup_delay_multiplier)?; let stable_xosc_token = nb::block!(initialized_xosc.await_stabilization()).unwrap();