From e22fe7cbcfbbb68e4ad6ef7914bf8ed952fca8f4 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 2 Apr 2025 21:00:08 +0800 Subject: [PATCH] stm32: xspi wait for prescaler change This is documented as being required (and is done by stm32cube), hasn't been observed as a problem though. --- embassy-stm32/src/xspi/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/embassy-stm32/src/xspi/mod.rs b/embassy-stm32/src/xspi/mod.rs index c024b2ed6..c315e2320 100644 --- a/embassy-stm32/src/xspi/mod.rs +++ b/embassy-stm32/src/xspi/mod.rs @@ -335,8 +335,17 @@ impl<'d, T: Instance, M: PeriMode> Xspi<'d, T, M> { w.set_prescaler(config.clock_prescaler); }); + // Wait for busy flag to clear after changing prescaler, during calibration + while T::REGS.sr().read().busy() {} + T::REGS.cr().modify(|w| { w.set_dmm(dual_quad); + + // TODO: at the moment only ncs1 seems to get passed in? + // Only one must be selected + assert!(!(ncs1.is_some() && ncs2.is_some())); + assert!(!(ncs1.is_none() && ncs2.is_none())); + w.set_cssel(if ncs1.is_some() { Cssel::B_0X0 } else { Cssel::B_0X1 }); }); T::REGS.tcr().modify(|w| { @@ -344,14 +353,6 @@ impl<'d, T: Instance, M: PeriMode> Xspi<'d, T, M> { w.set_dhqc(config.delay_hold_quarter_cycle); }); - // TODO: at the moment only ncs1 seems to get passed in? - // Only one must be selected - assert!(!(ncs1.is_some() && ncs2.is_some())); - assert!(!(ncs1.is_none() && ncs2.is_none())); - T::REGS.cr().modify(|w| { - w.set_cssel(if ncs1.is_some() { Cssel::B_0X0 } else { Cssel::B_0X1 }); - }); - // Enable peripheral T::REGS.cr().modify(|w| { w.set_en(true);