diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index d8ffabb1..a743a036 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> { + flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter() { let _ = transfer_word(T::REGS, *word)?; @@ -583,6 +584,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } pub fn blocking_read(&mut self, words: &mut [W]) -> Result<(), Error> { + flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter_mut() { *word = transfer_word(T::REGS, W::default())?; @@ -591,6 +593,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> { + flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); for word in words.iter_mut() { *word = transfer_word(T::REGS, *word)?; @@ -599,6 +602,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> { + flush_rx_fifo(T::REGS); self.set_word_size(W::WORDSIZE); let len = read.len().max(write.len()); for i in 0..len { @@ -727,7 +731,6 @@ fn spin_until_rx_ready(regs: Regs) -> Result<(), Error> { } } -#[cfg(not(spi_v3))] fn flush_rx_fifo(regs: Regs) { unsafe { #[cfg(not(spi_v3))]