From 9cf1d5b29cae76b39b709a65afbef00906bfdd8e Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 25 Jun 2021 06:23:20 +0200 Subject: [PATCH] rp/clocks: fix wrong PLL setup --- embassy-rp/src/clocks.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 71e738c4..c3ca4cf6 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -155,15 +155,16 @@ unsafe fn configure_pll( }); p.fbdiv_int().write(|w| w.set_fbdiv_int(0)); - let ref_mhz = XOSC_MHZ / refdiv; - p.cs().write(|w| w.set_refdiv(ref_mhz as _)); + let ref_freq = XOSC_MHZ * 1_000_000 / refdiv; - let fbdiv = vco_freq / (ref_mhz * 1_000_000); - assert!(fbdiv >= 16 && fbdiv <= 520); - assert!((post_div1 >= 1 && post_div1 <= 7) && (post_div2 >= 1 && post_div2 <= 7)); + let fbdiv = vco_freq / ref_freq; + assert!(fbdiv >= 16 && fbdiv <= 320); + assert!(post_div1 >= 1 && post_div1 <= 7); + assert!(post_div2 >= 1 && post_div2 <= 7); assert!(post_div2 <= post_div1); - assert!(ref_mhz <= (vco_freq / 16)); + assert!(ref_freq <= (vco_freq / 16)); + p.cs().write(|w| w.set_refdiv(refdiv as _)); p.fbdiv_int().write(|w| w.set_fbdiv_int(fbdiv as _)); p.pwr().modify(|w| {