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

bare9_2

parent d3c039b1
Branches
No related tags found
No related merge requests found
...@@ -175,6 +175,7 @@ const APP: () = { ...@@ -175,6 +175,7 @@ const APP: () = {
// How did the added tracing/instrumentation affect the behavior? // How did the added tracing/instrumentation affect the behavior?
// //
// ** your answer here ** // ** your answer here **
// More error prone
// //
// Commit your answer (bare8_3) // Commit your answer (bare8_3)
// //
...@@ -187,6 +188,7 @@ const APP: () = { ...@@ -187,6 +188,7 @@ const APP: () = {
// Experiment a bit, what is the max length sequence you can receive without errors? // Experiment a bit, what is the max length sequence you can receive without errors?
// //
// ** your answer here ** // ** your answer here **
// we got 25
// //
// Commit your answer (bare8_4) // Commit your answer (bare8_4)
// //
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#![no_std] #![no_std]
use panic_rtt_target as _; use panic_rtt_target as _;
use stm32f4xx_hal::nb::block;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
prelude::*, prelude::*,
...@@ -24,6 +25,8 @@ const APP: () = { ...@@ -24,6 +25,8 @@ const APP: () = {
// Late resources // Late resources
TX: Tx<USART2>, TX: Tx<USART2>,
RX: Rx<USART2>, RX: Rx<USART2>,
RECV: i32,
ERR: i32,
} }
// init runs in an interrupt free section // init runs in an interrupt free section
...@@ -44,6 +47,9 @@ const APP: () = { ...@@ -44,6 +47,9 @@ const APP: () = {
let tx = gpioa.pa2.into_alternate_af7(); let tx = gpioa.pa2.into_alternate_af7();
let rx = gpioa.pa3.into_alternate_af7(); let rx = gpioa.pa3.into_alternate_af7();
let mut errors:i32 = 0;
let mut received:i32 = 0;
let mut serial = Serial::usart2( let mut serial = Serial::usart2(
device.USART2, device.USART2,
(tx, rx), (tx, rx),
...@@ -59,7 +65,7 @@ const APP: () = { ...@@ -59,7 +65,7 @@ const APP: () = {
let (tx, rx) = serial.split(); let (tx, rx) = serial.split();
// Late resources // Late resources
init::LateResources { TX: tx, RX: rx } init::LateResources { TX: tx, RX: rx, ERR:errors, RECV:received }
} }
// idle may be interrupted by other interrupts/tasks in the system // idle may be interrupted by other interrupts/tasks in the system
...@@ -74,16 +80,36 @@ const APP: () = { ...@@ -74,16 +80,36 @@ const APP: () = {
#[task(resources = [TX], priority = 1, capacity = 128)] #[task(resources = [TX], priority = 1, 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;
tx.write(data).unwrap(); rprintln!("data {:b}", data);
rprintln!("data {}", data); match block!(tx.write(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], spawn = [rx])] #[task(binds = USART2, priority = 2, resources = [RX, ERR, RECV], spawn = [rx])]
fn usart2(cx: usart2::Context) { fn usart2(cx: usart2::Context) {
let rx = cx.resources.RX; let rx = cx.resources.RX;
let data = rx.read().unwrap(); let received = cx.resources.RECV;
cx.spawn.rx(data).unwrap(); let errors = cx.resources.ERR;
match block!(rx.read()) {
Ok(byte) => {
*received += 1;
rprintln!("Ok {:b} Nmbr {:?}", byte, received);
cx.spawn.rx(byte).unwrap();
}
Err(err) => {
*errors += 1;
rprintln!("Error {:?} Nmbr {:?}", err, errors);
}
}
} }
extern "C" { extern "C" {
...@@ -149,6 +175,7 @@ const APP: () = { ...@@ -149,6 +175,7 @@ const APP: () = {
// Were you able to crash it? // Were you able to crash it?
// //
// ** your answer here ** // ** your answer here **
// yes, couldnt handle 123
// //
// Notice, the input tracing in `moserial` seems broken, and may loose data. // Notice, the input tracing in `moserial` seems broken, and may loose data.
// So don't be alarmed if data is missing, its a GUI tool after all. // So don't be alarmed if data is missing, its a GUI tool after all.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment