diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 5420ba36..db8ce15f 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -288,6 +288,55 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { _ => 0b111, } } + + fn set_word_size(&mut self, word_size: WordSize) { + if self.current_word_size == word_size { + return; + } + + #[cfg(any(spi_v1, spi_f1))] + unsafe { + T::regs().cr1().modify(|reg| { + reg.set_spe(false); + reg.set_dff(word_size.dff()) + }); + T::regs().cr1().modify(|reg| { + reg.set_spe(true); + }); + } + #[cfg(spi_v2)] + unsafe { + T::regs().cr1().modify(|w| { + w.set_spe(false); + }); + T::regs().cr2().modify(|w| { + w.set_frxth(word_size.frxth()); + w.set_ds(word_size.ds()); + }); + T::regs().cr1().modify(|w| { + w.set_spe(true); + }); + } + #[cfg(spi_v3)] + unsafe { + T::regs().cr1().modify(|w| { + w.set_csusp(true); + }); + while T::regs().sr().read().eot() {} + T::regs().cr1().modify(|w| { + w.set_spe(false); + }); + T::regs().cfg1().modify(|w| { + w.set_dsize(word_size.dsize()); + }); + T::regs().cr1().modify(|w| { + w.set_csusp(false); + w.set_spe(true); + }); + } + + self.current_word_size = word_size; + } } trait RegsExt { diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index b98a7834..cd9383d1 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs @@ -13,22 +13,6 @@ use futures::future::join3; use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { - fn set_word_size(&mut self, word_size: WordSize) { - if self.current_word_size == word_size { - return; - } - unsafe { - T::regs().cr1().modify(|reg| { - reg.set_spe(false); - reg.set_dff(word_size.dff()) - }); - T::regs().cr1().modify(|reg| { - reg.set_spe(true); - }); - } - self.current_word_size = word_size; - } - #[allow(unused)] async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> where diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 5c62400e..9817311f 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -12,25 +12,6 @@ use futures::future::{join, join3}; use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { - fn set_word_size(&mut self, word_size: WordSize) { - if self.current_word_size == word_size { - return; - } - unsafe { - T::regs().cr1().modify(|w| { - w.set_spe(false); - }); - T::regs().cr2().modify(|w| { - w.set_frxth(word_size.frxth()); - w.set_ds(word_size.ds()); - }); - T::regs().cr1().modify(|w| { - w.set_spe(true); - }); - } - self.current_word_size = word_size; - } - #[allow(unused)] async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> where diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index a23a6dd0..af39d3a0 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs @@ -13,29 +13,6 @@ use futures::future::join3; use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { - fn set_word_size(&mut self, word_size: WordSize) { - if self.current_word_size == word_size { - return; - } - unsafe { - T::regs().cr1().modify(|w| { - w.set_csusp(true); - }); - while T::regs().sr().read().eot() {} - T::regs().cr1().modify(|w| { - w.set_spe(false); - }); - T::regs().cfg1().modify(|w| { - w.set_dsize(word_size.dsize()); - }); - T::regs().cr1().modify(|w| { - w.set_csusp(false); - w.set_spe(true); - }); - } - self.current_word_size = word_size; - } - #[allow(unused)] async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> where