dma tx from shared variable
This commit is contained in:
parent
fe2425fca2
commit
6b7c18c8da
1 changed files with 16 additions and 12 deletions
|
@ -5,10 +5,10 @@
|
||||||
mod i2c_reg_slave;
|
mod i2c_reg_slave;
|
||||||
mod i2c_slave;
|
mod i2c_slave;
|
||||||
|
|
||||||
|
use panic_halt as _;
|
||||||
|
|
||||||
#[rtic::app(device = stm32f1::stm32f103, peripherals = true)]
|
#[rtic::app(device = stm32f1::stm32f103, peripherals = true)]
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m::singleton;
|
|
||||||
use panic_halt as _;
|
|
||||||
use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer};
|
use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer};
|
||||||
use systick_monotonic::Systick;
|
use systick_monotonic::Systick;
|
||||||
|
|
||||||
|
@ -17,7 +17,10 @@ mod app {
|
||||||
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {}
|
struct Shared {
|
||||||
|
#[lock_free]
|
||||||
|
buffer: [u8; 256],
|
||||||
|
}
|
||||||
|
|
||||||
#[local]
|
#[local]
|
||||||
struct Local {
|
struct Local {
|
||||||
|
@ -54,12 +57,12 @@ mod app {
|
||||||
let dma1 = cx.device.DMA1.split();
|
let dma1 = cx.device.DMA1.split();
|
||||||
|
|
||||||
// Serial config
|
// 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(
|
let serial = serial::Serial::new(
|
||||||
cx.device.USART1,
|
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,
|
&mut afio.mapr,
|
||||||
serial::Config {
|
serial::Config {
|
||||||
baudrate: 250_000.bps(),
|
baudrate: 250_000.bps(),
|
||||||
|
@ -69,7 +72,9 @@ mod app {
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
Shared {},
|
Shared {
|
||||||
|
buffer: [0b01010101; 256],
|
||||||
|
},
|
||||||
Local {
|
Local {
|
||||||
tx: Some(serial.tx.with_dma(dma1.4)),
|
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) -> ! {
|
fn idle(cx: idle::Context) -> ! {
|
||||||
let mut buf = singleton!(: [u8; 256] = [0b01010101; 256]).unwrap();
|
|
||||||
let mut tx = cx.local.tx.take().unwrap();
|
let mut tx = cx.local.tx.take().unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let xfer = tx.write(buf);
|
let xfer = tx.write(cx.shared.buffer);
|
||||||
|
|
||||||
cx.local.delay.delay(1.secs());
|
cx.local.delay.delay(1.secs());
|
||||||
cx.local.led.set_high();
|
cx.local.led.set_high();
|
||||||
|
@ -98,7 +102,7 @@ mod app {
|
||||||
cx.local.delay.delay(1.secs());
|
cx.local.delay.delay(1.secs());
|
||||||
cx.local.led.set_low();
|
cx.local.led.set_low();
|
||||||
|
|
||||||
(buf, tx) = xfer.wait();
|
(_, tx) = xfer.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue