diff --git a/.gitignore b/.gitignore index a136337..faa5f85 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pdf +dma_example/ diff --git a/dma_gpio2/src/bin/main.rs b/dma_gpio2/src/bin/main.rs index 24ba11e..d2867c7 100644 --- a/dma_gpio2/src/bin/main.rs +++ b/dma_gpio2/src/bin/main.rs @@ -29,9 +29,10 @@ unsafe fn start_dma<'a>( } pub const TIM6_UP_REQ: Request = 4; +const DMA_BUF_WORDS: usize = 256; -static BUF_A: StaticCell<[u32; 8]> = StaticCell::new(); -static BUF_B: StaticCell<[u32; 8]> = StaticCell::new(); +static BUF_A: StaticCell<[u32; DMA_BUF_WORDS]> = StaticCell::new(); +static BUF_B: StaticCell<[u32; DMA_BUF_WORDS]> = StaticCell::new(); #[embassy_executor::main] async fn main(_spawner: Spawner) { @@ -41,8 +42,16 @@ async fn main(_spawner: Spawner) { init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE); dump_tim6_regs(); - let buf_a = BUF_A.init([0u32; 8]); - let buf_b = BUF_B.init([0u32; 8]); + let buf_a = BUF_A.init([0u32; DMA_BUF_WORDS]); + let buf_b = BUF_B.init([0u32; DMA_BUF_WORDS]); + // Pre-fill with idle high level (stop bit level) + let idle = 1u32 << TX_PIN_BIT; + for w in buf_a.iter_mut() { + *w = idle; + } + for w in buf_b.iter_mut() { + *w = idle; + } let mut opts = TransferOptions::default(); opts.priority = Priority::VeryHigh; @@ -58,10 +67,25 @@ async fn main(_spawner: Spawner) { (&*buf_b, &mut *buf_a) }; + // Start from idle pattern + let idle = 1u32 << TX_PIN_BIT; + for w in cpu_buf.iter_mut() { + *w = idle; + } + let used = encode_uart_frames(TX_PIN_BIT, b"Hello marshmallow\r\n", cpu_buf).await; + let len = if used == 0 { 1 } else { used }; + // At least one word so DMA is always valid. + let transfer = unsafe { - start_dma(ch0.reborrow(), TIM6_UP_REQ, odr_ptr, &dma_buf[..used], opts) + start_dma( + ch0.reborrow(), + TIM6_UP_REQ, + odr_ptr, + &dma_buf[..len], + opts, + ) }; transfer.await; using_a = !using_a;