From 6b7c18c8da0af5e104f880febf40574f12f7bf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 11 Mar 2024 19:09:21 +0000 Subject: [PATCH] dma tx from shared variable --- bluepill-rs/src/main.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bluepill-rs/src/main.rs b/bluepill-rs/src/main.rs index b13fbb8..c9c0166 100644 --- a/bluepill-rs/src/main.rs +++ b/bluepill-rs/src/main.rs @@ -5,10 +5,10 @@ mod i2c_reg_slave; mod i2c_slave; +use panic_halt as _; + #[rtic::app(device = stm32f1::stm32f103, peripherals = true)] mod app { - use cortex_m::singleton; - use panic_halt as _; use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer}; use systick_monotonic::Systick; @@ -17,7 +17,10 @@ mod app { type MyMono = Systick<100>; // 100 Hz / 10 ms granularity #[shared] - struct Shared {} + struct Shared { + #[lock_free] + buffer: [u8; 256], + } #[local] struct Local { @@ -54,12 +57,12 @@ mod app { let dma1 = cx.device.DMA1.split(); // Serial config - let tx = gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh); - let rx = gpioa.pa10; //.into_pull_up_input(&mut gpioa.crh); - let serial = serial::Serial::new( cx.device.USART1, - (tx, rx), + ( + gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh), + gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh), + ), &mut afio.mapr, serial::Config { baudrate: 250_000.bps(), @@ -69,7 +72,9 @@ mod app { ); ( - Shared {}, + Shared { + buffer: [0b01010101; 256], + }, Local { tx: Some(serial.tx.with_dma(dma1.4)), @@ -84,13 +89,12 @@ mod app { ) } - #[idle(local = [tx, delay, led])] + #[idle(local = [tx, delay, led], shared = [&buffer])] fn idle(cx: idle::Context) -> ! { - let mut buf = singleton!(: [u8; 256] = [0b01010101; 256]).unwrap(); let mut tx = cx.local.tx.take().unwrap(); loop { - let xfer = tx.write(buf); + let xfer = tx.write(cx.shared.buffer); cx.local.delay.delay(1.secs()); cx.local.led.set_high(); @@ -98,7 +102,7 @@ mod app { cx.local.delay.delay(1.secs()); cx.local.led.set_low(); - (buf, tx) = xfer.wait(); + (_, tx) = xfer.wait(); } } }