From e72e17ded8f5f9f10eb68cc785101e5c7dab73ef Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Fri, 12 Sep 2025 20:03:00 +0900 Subject: Write data with the Ospi peripheral in chunks to respect the max DMA transfer size --- embassy-stm32/src/ospi/mod.rs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/embassy-stm32/src/ospi/mod.rs b/embassy-stm32/src/ospi/mod.rs index c291a311d..d93cecb69 100644 --- a/embassy-stm32/src/ospi/mod.rs +++ b/embassy-stm32/src/ospi/mod.rs @@ -1198,16 +1198,19 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { .cr() .modify(|v| v.set_fmode(vals::FunctionalMode::INDIRECT_WRITE)); - let transfer = unsafe { - self.dma - .as_mut() - .unwrap() - .write(buf, T::REGS.dr().as_ptr() as *mut W, Default::default()) - }; - - T::REGS.cr().modify(|w| w.set_dmaen(true)); - - transfer.blocking_wait(); + // TODO: implement this using a LinkedList DMA to offload the whole transfer off the CPU. + for chunk in buf.chunks(0xFFFF) { + let transfer = unsafe { + self.dma + .as_mut() + .unwrap() + .write(chunk, T::REGS.dr().as_ptr() as *mut W, Default::default()) + }; + + T::REGS.cr().modify(|w| w.set_dmaen(true)); + + transfer.blocking_wait(); + } finish_dma(T::REGS); @@ -1268,16 +1271,19 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { .cr() .modify(|v| v.set_fmode(vals::FunctionalMode::INDIRECT_WRITE)); - let transfer = unsafe { - self.dma - .as_mut() - .unwrap() - .write(buf, T::REGS.dr().as_ptr() as *mut W, Default::default()) - }; + // TODO: implement this using a LinkedList DMA to offload the whole transfer off the CPU. + for chunk in buf.chunks(0xFFFF) { + let transfer = unsafe { + self.dma + .as_mut() + .unwrap() + .write(chunk, T::REGS.dr().as_ptr() as *mut W, Default::default()) + }; - T::REGS.cr().modify(|w| w.set_dmaen(true)); + T::REGS.cr().modify(|w| w.set_dmaen(true)); - transfer.await; + transfer.await; + } finish_dma(T::REGS); -- cgit From 97462c07ce3d5797dfcefb15dd4b50383a850638 Mon Sep 17 00:00:00 2001 From: goodhoko Date: Tue, 16 Sep 2025 14:39:45 +0200 Subject: Aaaaaand the changelog of course --- embassy-stm32/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index e3f18ca0d..253b4796d 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - feat: Configurable gpio speed for QSPI - feat: derive Clone, Copy and defmt::Format for all *SPI-related configs - fix: handle address and data-length errors in OSPI +- feat: Allow OSPI DMA writes larger than 64kB using chunking ## 0.4.0 - 2025-08-26 -- cgit