From 62407da29b5d1867f50f30c796cc1ecfc7dc77c1 Mon Sep 17 00:00:00 2001 From: Til Blechschmidt Date: Wed, 23 Feb 2022 23:38:18 +0100 Subject: [PATCH] Fix EasyDMA slice copying not actually copying data --- embassy-nrf/src/spim.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 5895558e6..3e793f393 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -8,6 +8,7 @@ use embassy::util::Unborrow; use embassy_hal_common::unborrow; use futures::future::poll_fn; +use crate::chip::FORCE_COPY_BUFFER_SIZE; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, AnyPin}; use crate::gpio::{Pin as GpioPin, PselBits}; @@ -273,8 +274,9 @@ impl<'d, T: Instance> Spim<'d, T> { Ok(_) => Ok(()), Err(Error::DMABufferNotInDataMemory) => { trace!("Copying SPIM tx buffer into RAM for DMA"); - let tx_copied = tx.clone(); - self.blocking_inner_from_ram(rx, tx_copied) + let mut tx_buf = [0u8; FORCE_COPY_BUFFER_SIZE]; + tx_buf[..tx.len()].copy_from_slice(tx); + self.blocking_inner_from_ram(rx, &tx_buf[..tx.len()]) } Err(error) => Err(error), } @@ -304,8 +306,9 @@ impl<'d, T: Instance> Spim<'d, T> { Ok(_) => Ok(()), Err(Error::DMABufferNotInDataMemory) => { trace!("Copying SPIM tx buffer into RAM for DMA"); - let tx_copied = tx.clone(); - self.async_inner_from_ram(rx, tx_copied).await + let mut tx_buf = [0u8; FORCE_COPY_BUFFER_SIZE]; + tx_buf[..tx.len()].copy_from_slice(tx); + self.async_inner_from_ram(rx, &tx_buf[..tx.len()]).await } Err(error) => Err(error), }