From ae174fd0e0102ad77d18c33754dc5493e58dfdb5 Mon Sep 17 00:00:00 2001 From: Michael van Niekerk Date: Wed, 30 Aug 2023 21:42:27 +0200 Subject: [PATCH 1/5] RP2040: XOSC delay multiplier --- embassy-rp/src/clocks.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 7b25ecff..4637ae05 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -94,6 +94,7 @@ impl ClockConfig { post_div1: 6, post_div2: 5, }), + delay_multiplier: 1 }), ref_clk: RefClkConfig { src: RefClkSrc::Xosc, @@ -203,6 +204,7 @@ pub struct XoscConfig { pub hz: u32, pub sys_pll: Option, pub usb_pll: Option, + pub delay_multiplier: u32, } pub struct PllConfig { @@ -363,7 +365,7 @@ pub(crate) unsafe fn init(config: ClockConfig) { // start XOSC // datasheet mentions support for clock inputs into XIN, but doesn't go into // how this is achieved. pico-sdk doesn't support this at all. - start_xosc(config.hz); + start_xosc(config.hz, config.delay_multiplier); let pll_sys_freq = match config.sys_pll { Some(sys_pll_config) => configure_pll(pac::PLL_SYS, config.hz, sys_pll_config), @@ -624,12 +626,12 @@ pub fn clk_rtc_freq() -> u16 { CLOCKS.rtc.load(Ordering::Relaxed) } -fn start_xosc(crystal_hz: u32) { +fn start_xosc(crystal_hz: u32, delay_multiplier: u32) { pac::XOSC .ctrl() .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); - let startup_delay = ((crystal_hz / 1000) + 128) / 256; + let startup_delay = (((crystal_hz / 1000) + 128) * delay_multiplier) / 256; pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); pac::XOSC.ctrl().write(|w| { w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); From 891f1758bcd2621148ffba163d054da4420416aa Mon Sep 17 00:00:00 2001 From: Michael van Niekerk Date: Wed, 30 Aug 2023 21:43:57 +0200 Subject: [PATCH 2/5] RP2040: XOSC delay multiplier --- embassy-rp/src/clocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 4637ae05..55a18cf6 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -94,7 +94,7 @@ impl ClockConfig { post_div1: 6, post_div2: 5, }), - delay_multiplier: 1 + delay_multiplier: 1, }), ref_clk: RefClkConfig { src: RefClkSrc::Xosc, From f69e8459c9a2362165df9dd603adb0ec6531d383 Mon Sep 17 00:00:00 2001 From: Michael van Niekerk Date: Wed, 30 Aug 2023 21:52:03 +0200 Subject: [PATCH 3/5] RP2040: Fixes as per PR --- embassy-rp/src/clocks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 55a18cf6..c9b2190c 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -94,7 +94,7 @@ impl ClockConfig { post_div1: 6, post_div2: 5, }), - delay_multiplier: 1, + delay_multiplier: 128, }), ref_clk: RefClkConfig { src: RefClkSrc::Xosc, @@ -631,7 +631,7 @@ fn start_xosc(crystal_hz: u32, delay_multiplier: u32) { .ctrl() .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); - let startup_delay = (((crystal_hz / 1000) + 128) * delay_multiplier) / 256; + let startup_delay = ((crystal_hz / 1000 + delay_multiplier) + 128) / 256; pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); pac::XOSC.ctrl().write(|w| { w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); From a76ff53fb396be26dfc5153e72c3e77c004afdf6 Mon Sep 17 00:00:00 2001 From: Michael van Niekerk Date: Wed, 30 Aug 2023 21:58:36 +0200 Subject: [PATCH 4/5] RP2040: Fixes as per PR --- embassy-rp/src/clocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index c9b2190c..2c41befe 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -631,7 +631,7 @@ fn start_xosc(crystal_hz: u32, delay_multiplier: u32) { .ctrl() .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); - let startup_delay = ((crystal_hz / 1000 + delay_multiplier) + 128) / 256; + let startup_delay = (((crystal_hz / 1000) + 128) * delay_multiplier) / 256; pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); pac::XOSC.ctrl().write(|w| { w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); From 83a976cf4bd963f39bd0d3e4ea56f4b35bd82031 Mon Sep 17 00:00:00 2001 From: Michael van Niekerk Date: Wed, 30 Aug 2023 21:59:41 +0200 Subject: [PATCH 5/5] RP2040: Fixes as per PR --- embassy-rp/src/clocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 2c41befe..22066546 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -631,7 +631,7 @@ fn start_xosc(crystal_hz: u32, delay_multiplier: u32) { .ctrl() .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); - let startup_delay = (((crystal_hz / 1000) + 128) * delay_multiplier) / 256; + let startup_delay = (((crystal_hz / 1000) * delay_multiplier) + 128) / 256; pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); pac::XOSC.ctrl().write(|w| { w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ);