From 4d8b9ef2db4fcdf0730e1ab7f6cda9c67798f8d7 Mon Sep 17 00:00:00 2001 From: Dominic Fischer Date: Sat, 4 Jan 2025 22:56:41 +0000 Subject: [PATCH] Properly reset descriptors in `DmaRxStreamBuf::prepare` --- esp-hal/CHANGELOG.md | 1 + esp-hal/src/dma/buffers.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index ab9f122d98..22abde76b7 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `spi::master::Spi::{into_async, into_blocking}` are now correctly available on the typed driver, to. (#2674) - It is no longer possible to safely conjure `GpioPin` instances (#2688) - UART: Public API follows `C-WORD_ORDER` Rust API standard (`VerbObject` order) (#2851) +- `DmaRxStreamBuf` now correctly resets the descriptors the next time it's used (#2890) ### Removed diff --git a/esp-hal/src/dma/buffers.rs b/esp-hal/src/dma/buffers.rs index 78a6a68bf9..2bf12111d6 100644 --- a/esp-hal/src/dma/buffers.rs +++ b/esp-hal/src/dma/buffers.rs @@ -1137,13 +1137,6 @@ impl DmaRxStreamBuf { return Err(DmaBufError::InsufficientDescriptors); } - // Link up all the descriptors (but not in a circle). - let mut next = null_mut(); - for desc in descriptors.iter_mut().rev() { - desc.next = next; - next = desc; - } - let mut chunks = buffer.chunks_exact_mut(chunk_size); for (desc, chunk) in descriptors.iter_mut().zip(chunks.by_ref()) { desc.buffer = chunk.as_mut_ptr(); @@ -1176,7 +1169,12 @@ unsafe impl DmaRxBuffer for DmaRxStreamBuf { type View = DmaRxStreamBufView; fn prepare(&mut self) -> Preparation { - for desc in self.descriptors.iter_mut() { + // Link up all the descriptors (but not in a circle). + let mut next = null_mut(); + for desc in self.descriptors.iter_mut().rev() { + desc.next = next; + next = desc; + desc.reset_for_rx(); } Preparation {