Skip to content

Commit 4c935d0

Browse files
author
Henrik Alsér
committed
Revert copy to RAM in embedded hal spim transfer. The mut slice must already be in RAM, so no check neccessary
1 parent aad5fb9 commit 4c935d0

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

nrf-hal-common/,

Whitespace-only changes.

nrf-hal-common/src/spim.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,13 @@ where
4141
type Error = Error;
4242

4343
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Error> {
44-
if slice_in_ram(words) {
45-
words.chunks(EASY_DMA_SIZE).try_for_each(|chunk| {
46-
self.do_spi_dma_transfer(DmaSlice::from_slice(chunk), DmaSlice::from_slice(chunk))
47-
})?;
48-
} else {
49-
words
50-
.chunks_mut(FORCE_COPY_BUFFER_SIZE)
51-
.try_for_each(|chunk| {
52-
let mut buf = [0u8; FORCE_COPY_BUFFER_SIZE];
53-
buf[..chunk.len()].copy_from_slice(chunk);
54-
self.do_spi_dma_transfer(
55-
DmaSlice::from_slice(&buf[..chunk.len()]),
56-
DmaSlice::from_slice(&buf[..chunk.len()]),
57-
)?;
58-
chunk.copy_from_slice(&buf[..chunk.len()]);
59-
Ok(())
60-
})?;
61-
}
44+
// If the slice isn't in RAM, we can't write back to it at all
45+
slice_in_ram_or(words, Error::DMABufferNotInDataMemory)?;
46+
47+
words.chunks(EASY_DMA_SIZE).try_for_each(|chunk| {
48+
self.do_spi_dma_transfer(DmaSlice::from_slice(chunk), DmaSlice::from_slice(chunk))
49+
})?;
50+
6251
Ok(words)
6352
}
6453
}

0 commit comments

Comments
 (0)