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 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/build.rs b/esp-hal/build.rs index 53d29277066..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)] @@ -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_features!("dma4032", "dma4064"); + #[cfg(all( feature = "flip-link", not(any(feature = "esp32c6", feature = "esp32h2")) 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 ///