From cd9a1d547c3e377bd7c0f6743a27218b38b2f491 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 24 Nov 2021 14:59:18 +0100 Subject: [PATCH] Ensure SPI DMA write is completed Fix a bug where DMA writes were not fully completed and only a single byte out of two were written. --- embassy-stm32/src/spi/v2.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 9b8a74d7b..488e80ef8 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -17,7 +17,7 @@ use embassy::util::Unborrow; use embassy_hal_common::unborrow; use embassy_traits::spi as traits; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; -use futures::future::join3; +use futures::future::{join, join3}; impl WordSize { fn ds(&self) -> spi::vals::Ds { @@ -186,7 +186,16 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { }); } - f.await; + join(f, Self::wait_for_idle()).await; + + unsafe { + T::regs().cr2().modify(|reg| { + reg.set_txdmaen(false); + }); + T::regs().cr1().modify(|w| { + w.set_spe(false); + }); + } Ok(()) }