From c21a402ebcf26fd40a2809fc771b71a3e9b31962 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 21 Nov 2025 14:56:00 -0800 Subject: Fix clkdiv configuration DIV should be modified while the clock is halted, not after it's already running. --- src/clocks/mod.rs | 16 ++++++---------- src/clocks/periph_helpers.rs | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/clocks/mod.rs b/src/clocks/mod.rs index a12e125c6..0b4535dc4 100644 --- a/src/clocks/mod.rs +++ b/src/clocks/mod.rs @@ -652,17 +652,15 @@ impl ClockOperator<'_> { }); } - // Halt and reset the div + // Halt and reset the div; then set our desired div. self.syscon.frohfdiv().write(|w| { w.halt().halt(); w.reset().asserted(); + unsafe { w.div().bits(d.into_bits()) }; w }); - // Then change the div, unhalt it, and reset it + // Then unhalt it, and reset it self.syscon.frohfdiv().write(|w| { - unsafe { - w.div().bits(d.into_bits()); - } w.halt().run(); w.reset().released(); w @@ -743,17 +741,15 @@ impl ClockOperator<'_> { }); } - // Halt and reset the div + // Halt and reset the div; then set our desired div. self.syscon.frolfdiv().write(|w| { w.halt().halt(); w.reset().asserted(); + unsafe { w.div().bits(d.into_bits()) }; w }); - // Then change the div, unhalt it, and reset it + // Then unhalt it, and reset it self.syscon.frolfdiv().write(|w| { - unsafe { - w.div().bits(d.into_bits()); - } w.halt().run(); w.reset().released(); w diff --git a/src/clocks/periph_helpers.rs b/src/clocks/periph_helpers.rs index e5b234c5b..8914f6833 100644 --- a/src/clocks/periph_helpers.rs +++ b/src/clocks/periph_helpers.rs @@ -240,12 +240,12 @@ impl SPConfHelper for LpuartConfig { clkdiv.modify(|_r, w| { w.halt().on(); w.reset().on(); + unsafe { w.div().bits(self.div.into_bits()) }; w }); clkdiv.modify(|_r, w| { w.halt().off(); w.reset().off(); - unsafe { w.div().bits(self.div.into_bits()) }; w }); @@ -377,12 +377,12 @@ impl SPConfHelper for AdcConfig { mrcc0.mrcc_adc_clkdiv().modify(|_r, w| { w.halt().on(); w.reset().on(); + unsafe { w.div().bits(self.div.into_bits()) }; w }); mrcc0.mrcc_adc_clkdiv().modify(|_r, w| { w.halt().off(); w.reset().off(); - unsafe { w.div().bits(self.div.into_bits()) }; w }); -- cgit