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

Support PSRAM in DmaTxBuf #2161

Merged
merged 25 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
306d118
support psram in DmaTxBuf
liebman Sep 15, 2024
008c8cd
add example that sometimes works :-(
liebman Sep 15, 2024
b231c8b
fmt
liebman Sep 15, 2024
07f780c
cleanups
liebman Sep 15, 2024
b1376b3
allow chunk_size upto (including) 4095
liebman Sep 16, 2024
179e926
this test is passing for me now
liebman Sep 16, 2024
1e37d4f
remove chunk_size and compute based on block_size
liebman Sep 16, 2024
5b2b4c9
return error in `prepare_transfer` if psram is found on non-esp32s3
liebman Sep 18, 2024
12acacd
missing parens
liebman Sep 18, 2024
9e2067d
changelog
liebman Sep 18, 2024
9fce2f4
default 4092 for esp32 & fmt
liebman Sep 18, 2024
b264ee2
no errors anymode
liebman Sep 19, 2024
1e62e91
use block_size is_some to flag invalid psram in prepare_transfer
liebman Sep 19, 2024
510b392
drop block_size from macro, the buffer allocation was not being align…
liebman Sep 19, 2024
af58a61
missed macro example
liebman Sep 19, 2024
70e98d7
use defmt::Format that decodes owner like Debug
liebman Sep 19, 2024
fa7cce0
fix typo
liebman Sep 19, 2024
6c9ff4c
DmaTxBuf: its an error if buffer is in psram and block_size is none
liebman Sep 20, 2024
d18fea7
DmaTxBuf: its an error if buffer is in psram and block_size is none
liebman Sep 20, 2024
37f7bff
update for PSRAM feature changes
liebman Sep 20, 2024
9162e63
Merge branch 'main' into dma-psram-tx-buf
JurajSadel Sep 24, 2024
51028c6
address alignment comments
liebman Sep 24, 2024
d452ef6
fmt
liebman Sep 24, 2024
b24f066
better alignment test
liebman Sep 24, 2024
65adcdf
revert alignment test
liebman Sep 24, 2024
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
14 changes: 12 additions & 2 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,11 @@ macro_rules! dma_tx_buffer {
($tx_size:expr) => {{
const TX_DESCRIPTOR_LEN: usize =
$crate::dma::DmaTxBuf::compute_descriptor_count($tx_size, None);
static mut TX_BUFFER: [u8; $tx_size] = [0u8; $tx_size];
$crate::declare_aligned_dma_buffer!(TX_BUFFER, $tx_size);
static mut TX_DESCRIPTORS: [$crate::dma::DmaDescriptor; TX_DESCRIPTOR_LEN] =
[$crate::dma::DmaDescriptor::EMPTY; TX_DESCRIPTOR_LEN];
let (tx_buffer, tx_descriptors) = unsafe { (&mut TX_BUFFER, &mut TX_DESCRIPTORS) };
let tx_buffer = $crate::as_mut_byte_array!(TX_BUFFER, $tx_size);
let tx_descriptors = unsafe { &mut TX_DESCRIPTORS };
$crate::dma::DmaTxBuf::new(tx_descriptors, tx_buffer)
liebman marked this conversation as resolved.
Show resolved Hide resolved
}};
}
Expand Down Expand Up @@ -1928,6 +1929,7 @@ pub trait DmaRxBuffer {

/// Error returned from Dma[Rx|Tx|RxTx]Buf operations.
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmaBufError {
/// More descriptors are needed for the buffer size
InsufficientDescriptors,
Expand Down Expand Up @@ -2034,6 +2036,14 @@ impl DmaTxBuf {
return Err(DmaBufError::InvalidAlignment);
}
} else {
#[cfg(any(esp32,esp32s2))]
if buffer.len() % 4 != 0 && buffer.as_ptr() as usize % 4 != 0 {
bugadani marked this conversation as resolved.
Show resolved Hide resolved
// ESP32 requires word alignment for DMA buffers.
// ESP32-S2 technically supports byte-aligned DMA buffers, but the
// transfer ends up writing out of bounds if the buffer's length
// is 2 or 3 (mod 4).
return Err(DmaBufError::InvalidAlignment);
}
// buffer can only be DRAM
if !is_slice_in_dram(buffer) {
return Err(DmaBufError::UnsupportedMemoryRegion);
Expand Down
23 changes: 23 additions & 0 deletions hil-test/tests/dma_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,27 @@ mod tests {
compute_circular_size(TX_SIZE, CHUNK_SIZE)
);
}

#[test]
fn test_dma_tx_buffer() {
use esp_hal::dma::DmaTxBuf;
use esp_hal::dma::DmaBufError;
const TX_SIZE: usize = DATA_SIZE;

fn check(result: Result<DmaTxBuf, DmaBufError>, size: usize) {
match result {
Ok(tx_buf) => {
assert_eq!(tx_buf.len(), size);
}
Err(_) => {
panic!("Failed to create DmaTxBuf");
}
}
}
check(esp_hal::dma_tx_buffer!(TX_SIZE), TX_SIZE);
check(esp_hal::dma_tx_buffer!(TX_SIZE+1), TX_SIZE+1);
check(esp_hal::dma_tx_buffer!(TX_SIZE+2), TX_SIZE+2);
check(esp_hal::dma_tx_buffer!(TX_SIZE+3), TX_SIZE+3);
}

}
Loading