From fb89815bb398e35fe6977627037ca339c802bd94 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Tue, 27 Aug 2024 15:11:36 +0200 Subject: [PATCH] Fix --- esp-hal/src/spi/master.rs | 54 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index d820f245791..027e43c2d13 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -1318,8 +1318,12 @@ pub mod dma { } let result = unsafe { - self.spi - .start_write_bytes_dma(buffer.first(), bytes_to_write, &mut self.channel.tx) + self.spi.start_write_bytes_dma( + buffer.first(), + bytes_to_write, + &mut self.channel.tx, + true, + ) }; if let Err(e) = result { return Err((e, self, buffer)); @@ -1346,8 +1350,12 @@ pub mod dma { } let result = unsafe { - self.spi - .start_read_bytes_dma(buffer.first(), bytes_to_read, &mut self.channel.rx) + self.spi.start_read_bytes_dma( + buffer.first(), + bytes_to_read, + &mut self.channel.rx, + true, + ) }; if let Err(e) = result { return Err((e, self, buffer)); @@ -1481,8 +1489,12 @@ pub mod dma { } let result = unsafe { - self.spi - .start_read_bytes_dma(buffer.first(), bytes_to_read, &mut self.channel.rx) + self.spi.start_read_bytes_dma( + buffer.first(), + bytes_to_read, + &mut self.channel.rx, + false, + ) }; if let Err(e) = result { return Err((e, self, buffer)); @@ -1559,8 +1571,12 @@ pub mod dma { } let result = unsafe { - self.spi - .start_write_bytes_dma(buffer.first(), bytes_to_write, &mut self.channel.tx) + self.spi.start_write_bytes_dma( + buffer.first(), + bytes_to_write, + &mut self.channel.tx, + false, + ) }; if let Err(e) = result { return Err((e, self, buffer)); @@ -2261,16 +2277,19 @@ pub trait InstanceDma: Instance { first_desc: *mut DmaDescriptor, len: usize, tx: &mut TX, + full_duplex: bool, ) -> Result<(), Error> { let reg_block = self.register_block(); self.configure_datalen(len as u32 * 8); tx.is_done(); - // disable MISO and re-enable MOSI - reg_block - .user() - .modify(|_, w| w.usr_miso().bit(false).usr_mosi().bit(true)); + // disable MISO and re-enable MOSI (DON'T do it for half-duplex) + if full_duplex { + reg_block + .user() + .modify(|_, w| w.usr_miso().bit(false).usr_mosi().bit(true)); + } self.enable_dma(); self.update(); @@ -2300,16 +2319,19 @@ pub trait InstanceDma: Instance { desc: *mut DmaDescriptor, data_length: usize, rx: &mut RX, + full_duplex: bool, ) -> Result<(), Error> { let reg_block = self.register_block(); self.configure_datalen(data_length as u32 * 8); rx.is_done(); - // re-enable MISO and disable MOSI - reg_block - .user() - .modify(|_, w| w.usr_miso().bit(true).usr_mosi().bit(false)); + // re-enable MISO and disable MOSI (DON'T do it for half-duplex) + if full_duplex { + reg_block + .user() + .modify(|_, w| w.usr_miso().bit(true).usr_mosi().bit(false)); + } self.enable_dma(); self.update();