Compare commits

..

No commits in common. "4132b45631b65d326b8f4ad85acfbc752b64c18a" and "23cf62e01fc292a87f4cb2a524fceb998bfac745" have entirely different histories.

3 changed files with 20 additions and 19 deletions

View file

@ -57,6 +57,7 @@ dependencies = [
"nb 1.1.0", "nb 1.1.0",
"panic-halt", "panic-halt",
"panic-semihosting", "panic-semihosting",
"stm32f1",
"stm32f1xx-hal", "stm32f1xx-hal",
"systick-monotonic", "systick-monotonic",
] ]

View file

@ -8,6 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
# main deps # main deps
embedded-hal = "1.0.0" embedded-hal = "1.0.0"
stm32f1 = { version = "0.15", features = ["stm32f103", "rt"] }
stm32f1xx-hal = { version = "0.10.0", features = ["rt", "stm32f103", "medium"] } stm32f1xx-hal = { version = "0.10.0", features = ["rt", "stm32f103", "medium"] }
nb = "1" nb = "1"
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }

View file

@ -8,7 +8,7 @@ mod i2c_slave;
// extern crate panic_halt; // extern crate panic_halt;
extern crate panic_semihosting; extern crate panic_semihosting;
#[rtic::app(device = stm32f1xx_hal::pac)] #[rtic::app(device = stm32f1::stm32f103, peripherals = true)]
mod app { mod app {
use cortex_m::singleton; use cortex_m::singleton;
use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer}; use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer};
@ -20,13 +20,12 @@ mod app {
#[shared] #[shared]
struct Shared { struct Shared {
buffer: &'static mut [u8; 512], buffer: Option<&'static mut [u8; 512]>,
} }
#[local] #[local]
struct Local { struct Local {
tx: Option<dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>>, tx: Option<dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>>,
txbuffer: Option<&'static mut [u8; 512]>,
delay_us: timer::DelayUs<pac::TIM2>, delay_us: timer::DelayUs<pac::TIM2>,
led: gpio::gpioc::PC13<gpio::Output>, led: gpio::gpioc::PC13<gpio::Output>,
} }
@ -72,11 +71,10 @@ mod app {
( (
Shared { Shared {
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(), buffer: Some(singleton!(: [u8; 512] = [0b01010101; 512]).unwrap()),
}, },
Local { Local {
tx: Some(serial.tx.with_dma(dma1.4)), tx: Some(serial.tx.with_dma(dma1.4)),
txbuffer: Some(singleton!(: [u8; 512] = [0; 512]).unwrap()),
// Configure timer // Configure timer
delay_us: cx.device.TIM2.delay_us(&clocks), delay_us: cx.device.TIM2.delay_us(&clocks),
@ -89,14 +87,14 @@ mod app {
) )
} }
#[idle(local = [tx, txbuffer, delay_us, led], shared = [&buffer])] #[idle(local = [tx, delay_us, led], shared = [buffer])]
fn idle(cx: idle::Context) -> ! { fn idle(mut cx: idle::Context) -> ! {
loop {
let mut tx = cx.local.tx.take().unwrap(); let mut tx = cx.local.tx.take().unwrap();
let mut txbuffer = cx.local.txbuffer.take().unwrap();
txbuffer.copy_from_slice(*cx.shared.buffer); loop {
let xfer = tx.write(txbuffer); tx = (cx.shared.buffer).lock(|buffer| {
let buf = buffer.take().unwrap();
let xfer = tx.write(buf);
cx.local.delay_us.delay(1.secs()); cx.local.delay_us.delay(1.secs());
cx.local.led.set_high(); cx.local.led.set_high();
@ -104,9 +102,10 @@ mod app {
cx.local.delay_us.delay(1.secs()); cx.local.delay_us.delay(1.secs());
cx.local.led.set_low(); cx.local.led.set_low();
(txbuffer, tx) = xfer.wait(); let (buf, tx) = xfer.wait();
cx.local.tx.replace(tx); buffer.replace(buf);
cx.local.txbuffer.replace(txbuffer); tx
});
} }
} }
} }