diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index a743a036..764a967c 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -575,6 +575,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } pub fn blocking_write(&mut self, words: &[W]) -> Result<(), Error> { + unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) } flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter() { @@ -584,6 +585,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } pub fn blocking_read(&mut self, words: &mut [W]) -> Result<(), Error> { + unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) } flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter_mut() { @@ -593,6 +595,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } pub fn blocking_transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Error> { + unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) } flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter_mut() { @@ -602,6 +605,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } pub fn blocking_transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> { + unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) } flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); let len = read.len().max(write.len()); diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs index 3e9521ae..f4f1994c 100644 --- a/tests/stm32/src/bin/spi_dma.rs +++ b/tests/stm32/src/bin/spi_dma.rs @@ -68,6 +68,22 @@ async fn main(_spawner: Spawner, p: Peripherals) { spi.read::(&mut []).await.unwrap(); spi.write::(&[]).await.unwrap(); + // === Check mixing blocking with async. + spi.blocking_transfer(&mut buf, &data).unwrap(); + assert_eq!(buf, data); + spi.transfer(&mut buf, &data).await.unwrap(); + assert_eq!(buf, data); + spi.blocking_write(&buf).unwrap(); + spi.transfer(&mut buf, &data).await.unwrap(); + assert_eq!(buf, data); + spi.blocking_read(&mut buf).unwrap(); + spi.blocking_write(&buf).unwrap(); + spi.write(&buf).await.unwrap(); + spi.read(&mut buf).await.unwrap(); + spi.blocking_write(&buf).unwrap(); + spi.blocking_read(&mut buf).unwrap(); + spi.write(&buf).await.unwrap(); + info!("Test OK"); cortex_m::asm::bkpt(); }