Compare commits
2 commits
23cf62e01f
...
4132b45631
| Author | SHA1 | Date | |
|---|---|---|---|
| 4132b45631 | |||
| 29e343b9c2 |
3 changed files with 19 additions and 20 deletions
1
bluepill-rs/Cargo.lock
generated
1
bluepill-rs/Cargo.lock
generated
|
|
@ -57,7 +57,6 @@ dependencies = [
|
|||
"nb 1.1.0",
|
||||
"panic-halt",
|
||||
"panic-semihosting",
|
||||
"stm32f1",
|
||||
"stm32f1xx-hal",
|
||||
"systick-monotonic",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
# main deps
|
||||
embedded-hal = "1.0.0"
|
||||
stm32f1 = { version = "0.15", features = ["stm32f103", "rt"] }
|
||||
stm32f1xx-hal = { version = "0.10.0", features = ["rt", "stm32f103", "medium"] }
|
||||
nb = "1"
|
||||
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod i2c_slave;
|
|||
// extern crate panic_halt;
|
||||
extern crate panic_semihosting;
|
||||
|
||||
#[rtic::app(device = stm32f1::stm32f103, peripherals = true)]
|
||||
#[rtic::app(device = stm32f1xx_hal::pac)]
|
||||
mod app {
|
||||
use cortex_m::singleton;
|
||||
use stm32f1xx_hal::{dma, gpio, pac, prelude::*, serial, timer};
|
||||
|
|
@ -20,12 +20,13 @@ mod app {
|
|||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
buffer: Option<&'static mut [u8; 512]>,
|
||||
buffer: &'static mut [u8; 512],
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
tx: Option<dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>>,
|
||||
txbuffer: Option<&'static mut [u8; 512]>,
|
||||
delay_us: timer::DelayUs<pac::TIM2>,
|
||||
led: gpio::gpioc::PC13<gpio::Output>,
|
||||
}
|
||||
|
|
@ -71,10 +72,11 @@ mod app {
|
|||
|
||||
(
|
||||
Shared {
|
||||
buffer: Some(singleton!(: [u8; 512] = [0b01010101; 512]).unwrap()),
|
||||
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
|
||||
},
|
||||
Local {
|
||||
tx: Some(serial.tx.with_dma(dma1.4)),
|
||||
txbuffer: Some(singleton!(: [u8; 512] = [0; 512]).unwrap()),
|
||||
|
||||
// Configure timer
|
||||
delay_us: cx.device.TIM2.delay_us(&clocks),
|
||||
|
|
@ -87,25 +89,24 @@ mod app {
|
|||
)
|
||||
}
|
||||
|
||||
#[idle(local = [tx, delay_us, led], shared = [buffer])]
|
||||
fn idle(mut cx: idle::Context) -> ! {
|
||||
let mut tx = cx.local.tx.take().unwrap();
|
||||
|
||||
#[idle(local = [tx, txbuffer, delay_us, led], shared = [&buffer])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
loop {
|
||||
tx = (cx.shared.buffer).lock(|buffer| {
|
||||
let buf = buffer.take().unwrap();
|
||||
let xfer = tx.write(buf);
|
||||
let mut tx = cx.local.tx.take().unwrap();
|
||||
let mut txbuffer = cx.local.txbuffer.take().unwrap();
|
||||
|
||||
cx.local.delay_us.delay(1.secs());
|
||||
cx.local.led.set_high();
|
||||
txbuffer.copy_from_slice(*cx.shared.buffer);
|
||||
let xfer = tx.write(txbuffer);
|
||||
|
||||
cx.local.delay_us.delay(1.secs());
|
||||
cx.local.led.set_low();
|
||||
cx.local.delay_us.delay(1.secs());
|
||||
cx.local.led.set_high();
|
||||
|
||||
let (buf, tx) = xfer.wait();
|
||||
buffer.replace(buf);
|
||||
tx
|
||||
});
|
||||
cx.local.delay_us.delay(1.secs());
|
||||
cx.local.led.set_low();
|
||||
|
||||
(txbuffer, tx) = xfer.wait();
|
||||
cx.local.tx.replace(tx);
|
||||
cx.local.txbuffer.replace(txbuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue