From 63c353faacfc7020c120fa3edc7546f10ab8c30f Mon Sep 17 00:00:00 2001 From: Priec Date: Sat, 1 Nov 2025 14:08:27 +0100 Subject: [PATCH] adjusted comments --- dma_gpio/src/bin/main.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dma_gpio/src/bin/main.rs b/dma_gpio/src/bin/main.rs index 3f376b8..9331f45 100644 --- a/dma_gpio/src/bin/main.rs +++ b/dma_gpio/src/bin/main.rs @@ -119,29 +119,29 @@ async fn main(spawner: Spawner) { #[embassy_executor::task] async fn rx_dma_task(ch: Peri<'static, GPDMA1_CH1>) { - - // SAFETY: this task owns the ring buffer exclusively (Rust 2024: avoid &mut static directly). + // SAFETY Own the static RX buffer exclusively. let ring_ptr = core::ptr::addr_of_mut!(RX_RING); let ring = unsafe { &mut *ring_ptr }; - // Sample the low byte of GPIOA.IDR (PA0..PA7). PA3 is bit 3, so that's within this byte. - let idr_low_byte = embassy_stm32::pac::GPIOA.idr().as_ptr() as *mut u8; + // DMA will read samples from GPIOA input register. + // Each sample is one byte (PA0..PA7). PA3 lives in bit 3. + let gpioa_idr = embassy_stm32::pac::GPIOA.idr().as_ptr() as *mut u8; let mut opts = TransferOptions::default(); - // Enable HT/TC IRQ so read_exact can await naturally. - opts.half_transfer_ir = true; - opts.complete_transfer_ir = true; + opts.half_transfer_ir = true; // wake at half buffer + opts.complete_transfer_ir = true; // wake at full buffer // Start hardware-linked circular DMA into ring. - let mut rx = unsafe { DmaRingRx::new(ch, TIM7_UP_REQ, idr_low_byte, ring, opts) }; + let mut rx = unsafe { DmaRingRx::new(ch, TIM7_UP_REQ, gpioa_idr, ring, opts) }; rx.start(); - // Drain in fixed chunks when CPU has time; DMA keeps running regardless. + // Drain in fixed chunks when CPU has time let mut chunk = [0u8; 256]; loop { - // Wait for a full chunk; wakes on half/full buffer events + // Wait for a full chunk + // Wakes on half/full buffer events let _ = rx.read_exact(&mut chunk).await; - // Forward raw samples to PIPE_RX (decode later if desired) + // Forward raw samples to PIPE_RX (decode later) PIPE_RX.write(&chunk).await; } }