From 6a5d2ccc97abf5780a4d40efa5a981c4609f3f08 Mon Sep 17 00:00:00 2001 From: liebman Date: Wed, 31 Jul 2024 12:24:58 -0700 Subject: [PATCH 1/4] dma: allow choices of CHUNK_SIZE --- esp-hal/Cargo.toml | 6 ++++++ esp-hal/src/dma/mod.rs | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 71ae2729127..ea36c17616a 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -180,6 +180,12 @@ opsram-8m = [] ## Use externally connected Octal RAM (16MB). opsram-16m = [] +#! ### DMA Feature Flags +## Use a DMA chunk size that is a multiple of 32 bytes. +dma4064 = [] +## Use a DMA chunk size that is a multiple of 64 bytes. +dma4032 = [] + # This feature is intended for testing; you probably don't want to enable it: ci = ["async", "embedded-hal-02", "embedded-io", "ufmt", "defmt", "bluetooth", "place-spi-driver-in-ram"] diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 535c3533589..04a4ded5be4 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -281,8 +281,18 @@ pub enum DmaInterrupt { RxDone, } -/// The default CHUNK_SIZE used for DMA transfers -pub const CHUNK_SIZE: usize = 4092; +cfg_if::cfg_if! { + if #[cfg(feature = "dma4064")] { + /// The default CHUNK_SIZE used for DMA transfers + pub const CHUNK_SIZE: usize = 4064; + } else if #[cfg(feature = "dma4032")] { + /// The default CHUNK_SIZE used for DMA transfers + pub const CHUNK_SIZE: usize = 4032; + } else { + /// The default CHUNK_SIZE used for DMA transfers + pub const CHUNK_SIZE: usize = 4092; + } +} /// Convenience macro to create DMA buffers and descriptors /// From 6ed3258cc5b3538a460c6f70d769677cf59001e1 Mon Sep 17 00:00:00 2001 From: liebman Date: Wed, 31 Jul 2024 12:39:29 -0700 Subject: [PATCH 2/4] changelog --- esp-hal/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 65fd89f3abe..6324e617cc7 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use the peripheral ref pattern for `OneShotTimer` and `PeriodicTimer` (#1855) - Allow DMA to/from psram for esp32s3 (#1827) +- Allow DMA default chunk size choices. This allows DMA to peripherals to/from psram as drivers don't allow specifying chunk size with DMA descriptors (#1889) - DMA buffers now don't require a static lifetime. Make sure to never `mem::forget` an in-progress DMA transfer (consider using `#[deny(clippy::mem_forget)]`) (#1837) ### Fixed From ce2d1b67aaabf0211b7bf0f934d7cb73e5affc2d Mon Sep 17 00:00:00 2001 From: liebman Date: Wed, 31 Jul 2024 12:57:20 -0700 Subject: [PATCH 3/4] insure only one dma chunk size feature is enabled at build time --- esp-hal/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 53d29277066..9ab006e648b 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -26,6 +26,9 @@ fn main() -> Result<(), Box> { "esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3" ); + // Ensure at most one dma chunk size feature is specified. + assert_unique_used_features!("dma4032", "dma4064"); + #[cfg(all( feature = "flip-link", not(any(feature = "esp32c6", feature = "esp32h2")) From b566f5aa20c5a7b73e9d238ea0f3fbb4b37999ed Mon Sep 17 00:00:00 2001 From: liebman Date: Wed, 31 Jul 2024 13:36:04 -0700 Subject: [PATCH 4/4] use correct unique features macro --- esp-hal/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 9ab006e648b..6a3d8f74652 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -7,7 +7,7 @@ use std::{ str::FromStr, }; -use esp_build::assert_unique_used_features; +use esp_build::{assert_unique_features, assert_unique_used_features}; use esp_metadata::{Chip, Config}; #[cfg(debug_assertions)] @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { ); // Ensure at most one dma chunk size feature is specified. - assert_unique_used_features!("dma4032", "dma4064"); + assert_unique_features!("dma4032", "dma4064"); #[cfg(all( feature = "flip-link",