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

Fix EasyDMA max size. #315

Merged
merged 1 commit into from
May 11, 2021
Merged
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
44 changes: 25 additions & 19 deletions nrf-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,35 @@ pub mod prelude {
}

/// Length of Nordic EasyDMA differs for MCUs
#[cfg(any(
feature = "52810",
feature = "52811",
feature = "52832",
feature = "51"
))]
pub mod target_constants {
// NRF52832 8 bits1..0xFF
pub const EASY_DMA_SIZE: usize = 255;
// Easy DMA can only read from data ram
pub const SRAM_LOWER: usize = 0x2000_0000;
pub const SRAM_UPPER: usize = 0x3000_0000;
pub const FORCE_COPY_BUFFER_SIZE: usize = 255;
const _CHECK_FORCE_COPY_BUFFER_SIZE: usize = EASY_DMA_SIZE - FORCE_COPY_BUFFER_SIZE;
// ERROR: FORCE_COPY_BUFFER_SIZE must be <= EASY_DMA_SIZE
}
#[cfg(any(feature = "52840", feature = "52833", feature = "9160"))]
pub mod target_constants {
// NRF52840 and NRF9160 16 bits 1..0xFFFF
pub const EASY_DMA_SIZE: usize = 65535;
#[cfg(feature = "51")]
pub const EASY_DMA_SIZE: usize = (1 << 8) - 1;
#[cfg(feature = "52805")]
pub const EASY_DMA_SIZE: usize = (1 << 14) - 1;
#[cfg(feature = "52810")]
pub const EASY_DMA_SIZE: usize = (1 << 10) - 1;
#[cfg(feature = "52811")]
pub const EASY_DMA_SIZE: usize = (1 << 14) - 1;
#[cfg(feature = "52820")]
pub const EASY_DMA_SIZE: usize = (1 << 15) - 1;
#[cfg(feature = "52832")]
pub const EASY_DMA_SIZE: usize = (1 << 8) - 1;
#[cfg(feature = "52833")]
pub const EASY_DMA_SIZE: usize = (1 << 16) - 1;
#[cfg(feature = "52840")]
pub const EASY_DMA_SIZE: usize = (1 << 16) - 1;
#[cfg(feature = "5340")]
pub const EASY_DMA_SIZE: usize = (1 << 16) - 1;
#[cfg(feature = "9160")]
pub const EASY_DMA_SIZE: usize = (1 << 12) - 1;

// Limits for Easy DMA - it can only read from data ram
pub const SRAM_LOWER: usize = 0x2000_0000;
pub const SRAM_UPPER: usize = 0x3000_0000;

#[cfg(any(feature = "51", feature = "52810", feature = "52832"))]
pub const FORCE_COPY_BUFFER_SIZE: usize = 255;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this constant if we already have EASY_DMA_SIZE?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's not necessarily bad to have a smaller force copy buffer size than the maximum allowed by DMA, because it gives less side effects with too big buffers overflowing memory unintentionally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, stack-allocating a 64kb copy buffer wouldn't be pretty

#[cfg(not(any(feature = "51", feature = "52810", feature = "52832")))]
pub const FORCE_COPY_BUFFER_SIZE: usize = 1024;
const _CHECK_FORCE_COPY_BUFFER_SIZE: usize = EASY_DMA_SIZE - FORCE_COPY_BUFFER_SIZE;
// ERROR: FORCE_COPY_BUFFER_SIZE must be <= EASY_DMA_SIZE
Expand Down