-
Notifications
You must be signed in to change notification settings - Fork 5
gpdma: add GPDMA driver #64
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f5cb2a7
gpdma: add GPDMA driver
astapleton c65d457
Fixes, simpler dma example
astapleton 69eab2a
more fixes
astapleton 5d9fc22
missed some defmt derives
astapleton 6f3aa81
use ReadBuffer, WriteBuffer to force immovable buffers; fix example
astapleton 95e3f78
fix example again
astapleton 793a9d5
doc clarification
astapleton 336a8c4
Use mutable reference to channels when creating transfers
astapleton 9bbaca7
fix data width check; remove incomplete documentation
astapleton 5c587f3
Hold onto source/destination; Remove UB from example
astapleton cd32400
mute type complexity clippy
astapleton 5b0d9be
rename fields
astapleton 100bf1b
Add free method, don't consume self in abort/wait_for_transfer_complete
astapleton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// #![deny(warnings)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
mod utilities; | ||
|
||
use cortex_m_rt::entry; | ||
use cortex_m_semihosting::debug; | ||
use stm32h5xx_hal::{ | ||
gpdma::{config::transform::*, DmaConfig, DmaTransfer}, | ||
pac, | ||
prelude::*, | ||
}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
utilities::logger::init(); | ||
|
||
let dp = pac::Peripherals::take().unwrap(); | ||
|
||
let pwr = dp.PWR.constrain(); | ||
let pwrcfg = pwr.vos0().freeze(); | ||
|
||
// Constrain and Freeze clock | ||
let rcc = dp.RCC.constrain(); | ||
let ccdr = rcc.sys_ck(250.MHz()).freeze(pwrcfg, &dp.SBS); | ||
|
||
let channels = dp.GPDMA1.channels(ccdr.peripheral.GPDMA1); | ||
|
||
// u8 to u8 | ||
log::info!("u8 to u8 transfer"); | ||
let src: [u8; 40] = core::array::from_fn(|i| i as u8); | ||
let dest = &mut [0u8; 40]; | ||
|
||
let channel = channels.0; | ||
let config = DmaConfig::new(); | ||
let transfer = DmaTransfer::memory_to_memory(config, &channel, &src, dest); | ||
transfer.start().unwrap(); | ||
transfer.wait_for_transfer_complete().unwrap(); | ||
assert_eq!(src, *dest, "u8 to u8 transfer failed"); | ||
|
||
// u32 to u32 with data transform | ||
log::info!("u32 to u32 with data transform"); | ||
let src = [0x12345678u32; 10]; | ||
let dest = &mut [0u32; 10]; | ||
let config = DmaConfig::new().with_data_transform( | ||
DataTransform::builder() | ||
.swap_destination_half_words() | ||
.swap_destination_half_word_byte_order(), | ||
); | ||
|
||
let transfer = DmaTransfer::memory_to_memory(config, &channel, &src, dest); | ||
|
||
transfer.start().unwrap(); | ||
transfer.wait_for_transfer_complete().unwrap(); | ||
assert_eq!( | ||
[0x78563412; 10], *dest, | ||
"u32 to u32 with data transform failed" | ||
); | ||
|
||
// u32 to u16 with truncate | ||
log::info!("u32 to u16 with truncate"); | ||
let src = [0x12345678u32; 10]; | ||
let dest = &mut [0u16; 20]; | ||
let config = DmaConfig::new().with_data_transform( | ||
DataTransform::builder().left_align_right_truncate(), | ||
); | ||
let transfer = DmaTransfer::memory_to_memory(config, &channel, &src, dest); | ||
|
||
transfer.start().unwrap(); | ||
transfer.wait_for_transfer_complete().unwrap(); | ||
assert_eq!( | ||
[0x1234; 10], | ||
(*dest)[0..10], | ||
"u32 to u16 with truncate failed" | ||
); | ||
assert_eq!([0; 10], (*dest)[10..20], "u32 to u16 with truncate failed"); | ||
|
||
// u32 to u8 with unpack | ||
log::info!("u32 to u8 with unpack"); | ||
let src = [0x12345678u32; 10]; | ||
let dest = &mut [0u8; 40]; | ||
let config = | ||
DmaConfig::new().with_data_transform(DataTransform::builder().unpack()); | ||
let transfer = DmaTransfer::memory_to_memory(config, &channel, &src, dest); | ||
|
||
transfer.start().unwrap(); | ||
transfer.wait_for_transfer_complete().unwrap(); | ||
let expected = [0x78, 0x56, 0x34, 0x12]; | ||
assert_eq!(expected, (*dest)[0..4], "u32 to u8 unpack failed"); | ||
assert_eq!(expected, (*dest)[36..40], "u32 to u8 unpack failed"); | ||
|
||
// u8 to u32 with pack | ||
log::info!("u8 to u32 with pack"); | ||
let mut src = [0u8; 40]; | ||
let dest = &mut [0u32; 10]; | ||
for chunk in src.chunks_mut(4) { | ||
chunk.copy_from_slice(&[0x78, 0x56, 0x34, 0x12]); | ||
} | ||
let config = | ||
DmaConfig::new().with_data_transform(DataTransform::builder().pack()); | ||
let transfer = DmaTransfer::memory_to_memory(config, &channel, &src, dest); | ||
|
||
transfer.start().unwrap(); | ||
transfer.wait_for_transfer_complete().unwrap(); | ||
assert_eq!([0x12345678; 10], (*dest), "u8 to u32 with pack failed"); | ||
|
||
log::info!("All tests passed!"); | ||
|
||
loop { | ||
debug::exit(debug::EXIT_SUCCESS) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.