Skip to content
Snippets Groups Projects
Commit 222c5b4a authored by Carl Österberg's avatar Carl Österberg
Browse files

bare9_2

parent 9e68adc9
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use panic_rtt_target as _; use panic_rtt_target as _;
use stm32f4xx_hal::nb::block; use stm32f4xx_hal::nb::block;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
prelude::*, prelude::*,
serial::{config::Config, Event, Rx, Serial, Tx}, serial::{config::Config, Event, Rx, Serial, Tx},
...@@ -77,36 +78,43 @@ const APP: () = { ...@@ -77,36 +78,43 @@ const APP: () = {
} }
// capacity sets the size of the input buffer (# outstanding messages) // capacity sets the size of the input buffer (# outstanding messages)
#[task(resources = [TX], priority = 1, capacity = 128)] #[task(resources = [TX], priority = 2, capacity = 128)]
fn rx(cx: rx::Context, data: u8) { fn rx(cx: rx::Context, data: u8) {
let tx = cx.resources.TX; let tx = cx.resources.TX;
rprintln!("data {:b}", data); block!(tx.write(data)).unwrap();
match block!(tx.write(data)) { //rprintln!("data {:b}", data);
Ok(_val) => {
rprintln!("Ok {:b}", data);
}
Err(err) => {
rprintln!("Error {:?}", err);
}
}
} }
// Task bound to the USART2 interrupt. // Task bound to the USART2 interrupt.
#[task(binds = USART2, priority = 2, resources = [RX, ERR, RECV], spawn = [rx])] #[task(binds = USART2, priority = 3, resources = [RX], spawn = [rx,traceing])]
fn usart2(cx: usart2::Context) { fn usart2(cx: usart2::Context) {
let rx = cx.resources.RX; let rx = cx.resources.RX;
let received = cx.resources.RECV;
let errors = cx.resources.ERR;
match block!(rx.read()) { match block!(rx.read()) {
Ok(byte) => { Ok(byte) => {
*received += 1;
rprintln!("Ok {:b} Nmbr {:?}", byte, received);
cx.spawn.rx(byte).unwrap(); cx.spawn.rx(byte).unwrap();
let _res=cx.spawn.traceing(true);
}
Err(_err) => {
let _res=cx.spawn.traceing(false);
}
}
}
// Handles prints
#[task(priority = 1, resources = [ERR, RECV])]
fn traceing(cx: traceing::Context, state: bool) {
let received = cx.resources.RECV;
let errors = cx.resources.ERR;
match state {
true => {
*received += 1;
rprintln!("Ok:s {:?}", received);
} }
Err(err) => { false => {
*errors += 1; *errors += 1;
rprintln!("Error {:?} Nmbr {:?}", err, errors); rprintln!("Errors {:?}", errors);
} }
} }
...@@ -114,6 +122,7 @@ const APP: () = { ...@@ -114,6 +122,7 @@ const APP: () = {
extern "C" { extern "C" {
fn EXTI0(); fn EXTI0();
fn USART1();
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment