aboutsummaryrefslogtreecommitdiff
path: root/examples/src/bin/dma_ping_pong_transfer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/src/bin/dma_ping_pong_transfer.rs')
-rw-r--r--examples/src/bin/dma_ping_pong_transfer.rs52
1 files changed, 29 insertions, 23 deletions
diff --git a/examples/src/bin/dma_ping_pong_transfer.rs b/examples/src/bin/dma_ping_pong_transfer.rs
index d765ea575..692515441 100644
--- a/examples/src/bin/dma_ping_pong_transfer.rs
+++ b/examples/src/bin/dma_ping_pong_transfer.rs
@@ -24,12 +24,12 @@
24#![no_main] 24#![no_main]
25 25
26use core::sync::atomic::{AtomicBool, Ordering}; 26use core::sync::atomic::{AtomicBool, Ordering};
27
27use embassy_executor::Spawner; 28use embassy_executor::Spawner;
28use embassy_mcxa::clocks::config::Div8; 29use embassy_mcxa::clocks::config::Div8;
29use embassy_mcxa::dma::{self, DmaChannel, DmaCh1InterruptHandler, Tcd, TransferOptions}; 30use embassy_mcxa::dma::{self, DmaCh1InterruptHandler, DmaChannel, Tcd, TransferOptions};
30use embassy_mcxa::bind_interrupts;
31use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; 31use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx};
32use embassy_mcxa::pac; 32use embassy_mcxa::{bind_interrupts, pac};
33use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 33use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
34 34
35// Source and destination buffers for Approach 1 (scatter/gather) 35// Source and destination buffers for Approach 1 (scatter/gather)
@@ -44,19 +44,21 @@ static mut DST2: [u32; 8] = [0; 8];
44#[repr(C, align(32))] 44#[repr(C, align(32))]
45struct TcdPool([Tcd; 2]); 45struct TcdPool([Tcd; 2]);
46 46
47static mut TCD_POOL: TcdPool = TcdPool([Tcd { 47static mut TCD_POOL: TcdPool = TcdPool(
48 saddr: 0, 48 [Tcd {
49 soff: 0, 49 saddr: 0,
50 attr: 0, 50 soff: 0,
51 nbytes: 0, 51 attr: 0,
52 slast: 0, 52 nbytes: 0,
53 daddr: 0, 53 slast: 0,
54 doff: 0, 54 daddr: 0,
55 citer: 0, 55 doff: 0,
56 dlast_sga: 0, 56 citer: 0,
57 csr: 0, 57 dlast_sga: 0,
58 biter: 0, 58 csr: 0,
59}; 2]); 59 biter: 0,
60 }; 2],
61);
60 62
61// AtomicBool to track scatter/gather completion 63// AtomicBool to track scatter/gather completion
62// Note: With ESG=1, DONE bit is cleared by hardware when next TCD loads, 64// Note: With ESG=1, DONE bit is cleared by hardware when next TCD loads,
@@ -289,7 +291,8 @@ async fn main(_spawner: Spawner) {
289 // - True async/await support 291 // - True async/await support
290 // - Good for streaming data processing 292 // - Good for streaming data processing
291 293
292 tx.blocking_write(b"--- Approach 2: wait_half() demo ---\r\n\r\n").unwrap(); 294 tx.blocking_write(b"--- Approach 2: wait_half() demo ---\r\n\r\n")
295 .unwrap();
293 296
294 // Enable DMA CH1 interrupt 297 // Enable DMA CH1 interrupt
295 unsafe { 298 unsafe {
@@ -310,10 +313,11 @@ async fn main(_spawner: Spawner) {
310 313
311 // Configure transfer with half-transfer interrupt enabled 314 // Configure transfer with half-transfer interrupt enabled
312 let mut options = TransferOptions::default(); 315 let mut options = TransferOptions::default();
313 options.half_transfer_interrupt = true; // Enable half-transfer interrupt 316 options.half_transfer_interrupt = true; // Enable half-transfer interrupt
314 options.complete_transfer_interrupt = true; 317 options.complete_transfer_interrupt = true;
315 318
316 tx.blocking_write(b"Starting transfer with half_transfer_interrupt...\r\n").unwrap(); 319 tx.blocking_write(b"Starting transfer with half_transfer_interrupt...\r\n")
320 .unwrap();
317 321
318 unsafe { 322 unsafe {
319 let src = &*core::ptr::addr_of!(SRC2); 323 let src = &*core::ptr::addr_of!(SRC2);
@@ -327,10 +331,12 @@ async fn main(_spawner: Spawner) {
327 let half_ok = transfer.wait_half().await; 331 let half_ok = transfer.wait_half().await;
328 332
329 if half_ok { 333 if half_ok {
330 tx.blocking_write(b"Half-transfer complete! First half of DST2: ").unwrap(); 334 tx.blocking_write(b"Half-transfer complete! First half of DST2: ")
335 .unwrap();
331 print_buffer(&mut tx, core::ptr::addr_of!(DST2) as *const u32, 4); 336 print_buffer(&mut tx, core::ptr::addr_of!(DST2) as *const u32, 4);
332 tx.blocking_write(b"\r\n").unwrap(); 337 tx.blocking_write(b"\r\n").unwrap();
333 tx.blocking_write(b"(Processing first half while second half transfers...)\r\n").unwrap(); 338 tx.blocking_write(b"(Processing first half while second half transfers...)\r\n")
339 .unwrap();
334 } 340 }
335 341
336 // Wait for complete transfer 342 // Wait for complete transfer
@@ -363,10 +369,10 @@ async fn main(_spawner: Spawner) {
363 defmt::info!("PASS: Approach 2 verified."); 369 defmt::info!("PASS: Approach 2 verified.");
364 } 370 }
365 371
366 tx.blocking_write(b"\r\n=== All ping-pong demos complete ===\r\n").unwrap(); 372 tx.blocking_write(b"\r\n=== All ping-pong demos complete ===\r\n")
373 .unwrap();
367 374
368 loop { 375 loop {
369 cortex_m::asm::wfe(); 376 cortex_m::asm::wfe();
370 } 377 }
371} 378}
372