Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dma: allow choices of CHUNK_SIZE #1889

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
5 changes: 4 additions & 1 deletion esp-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -26,6 +26,9 @@ fn main() -> Result<(), Box<dyn Error>> {
"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"))
Expand Down
14 changes: 12 additions & 2 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down