diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 56fe461d62..b29766be74 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -1328,7 +1328,7 @@ pub trait Rx: crate::private::Sealed { fn start_transfer(&mut self) -> Result<(), DmaError>; - fn stop_transfer(&mut self); + fn reset_state_machine(&mut self); #[cfg(esp32s3)] fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize); @@ -1407,7 +1407,7 @@ where } } - fn stop_transfer(&mut self) { + fn reset_state_machine(&mut self) { R::reset_in(); } @@ -1505,8 +1505,8 @@ where self.rx_impl.start_transfer() } - fn stop_transfer(&mut self) { - self.rx_impl.stop_transfer(); + fn reset_state_machine(&mut self) { + self.rx_impl.reset_state_machine(); } #[cfg(esp32s3)] @@ -1582,7 +1582,7 @@ pub trait Tx: crate::private::Sealed { fn start_transfer(&mut self) -> Result<(), DmaError>; - fn stop_transfer(&mut self); + fn reset_state_machine(&mut self); #[cfg(esp32s3)] fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize); @@ -1639,7 +1639,7 @@ where } } - fn stop_transfer(&mut self) { + fn reset_state_machine(&mut self) { R::reset_out(); } @@ -1749,8 +1749,8 @@ where self.tx_impl.start_transfer() } - fn stop_transfer(&mut self) { - self.tx_impl.stop_transfer(); + fn reset_state_machine(&mut self) { + self.tx_impl.reset_state_machine(); } #[cfg(esp32s3)] diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index 62215d1fd8..4f14273ead 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -1512,6 +1512,8 @@ mod dma { } fn do_cancel(&mut self) { + // The SPI peripheral is controlling how much data we transfer, so let's + // update its counter. // 0 doesn't take effect on ESP32 and cuts the currently transmitted byte // immediately. // 1 seems to stop after transmitting the current byte which is somewhat less @@ -1519,12 +1521,14 @@ mod dma { self.spi_dma.spi_mut().configure_datalen(1, 1); self.spi_dma.spi_mut().update(); + // We need to reset the DMA state machines for the DMA to also pick up the + // change. if self.spi_dma.is_tx_in_progress() { - self.spi_dma.channel_mut().tx.stop_transfer(); + self.spi_dma.channel_mut().tx.reset_state_machine(); self.spi_dma.set_tx_in_progress(false); } if self.spi_dma.is_rx_in_progress() { - self.spi_dma.channel_mut().rx.stop_transfer(); + self.spi_dma.channel_mut().rx.reset_state_machine(); self.spi_dma.set_rx_in_progress(false); } }