Skip to content
Snippets Groups Projects
Commit 95e6b2aa authored by Per's avatar Per
Browse files

bare 7

parent 6268c73d
Branches
No related tags found
No related merge requests found
//! Serial interface loopback //! Serial interface loopback
#![deny(unsafe_code)] #![deny(unsafe_code)]
//#![deny(warnings)] #![deny(warnings)]
#![feature(proc_macro)] #![feature(proc_macro)]
#![no_std] #![no_std]
...@@ -18,7 +18,7 @@ use f4::prelude::*; ...@@ -18,7 +18,7 @@ use f4::prelude::*;
use f4::Serial; use f4::Serial;
use f4::time::Hertz; use f4::time::Hertz;
use heapless::Vec; use heapless::Vec;
use rtfm::{app, Threshold}; use rtfm::app;
// CONFIGURATION // CONFIGURATION
const BAUD_RATE: Hertz = Hertz(115_200); const BAUD_RATE: Hertz = Hertz(115_200);
...@@ -42,17 +42,21 @@ fn init(p: init::Peripherals) { ...@@ -42,17 +42,21 @@ fn init(p: init::Peripherals) {
let mut buffer: Vec<u8, [u8; 4]> = Vec::new(); let mut buffer: Vec<u8, [u8; 4]> = Vec::new();
loop { loop {
if let Ok(byte) = block!(serial.read()) { match block!(serial.read()) {
buffer.push(byte); Ok(byte) => {
let _ = buffer.push(byte);
ipln!("Ok {:?}", buffer); ipln!("Ok {:?}", buffer);
block!(serial.write(byte)).ok(); block!(serial.write(byte)).ok();
} else { }
ipln!("Error"); Err(err) => {
ipln!("Error {:?}", err);
p.USART2.dr.read(); // clear the error by reading the data register
}
} }
} }
} }
// IDLE LOOP // We will never reach `idle` since we burn the CPU arduino style :)
fn idle() -> ! { fn idle() -> ! {
// Sleep // Sleep
loop { loop {
...@@ -76,27 +80,41 @@ fn idle() -> ! { ...@@ -76,27 +80,41 @@ fn idle() -> ! {
// //
// you should now be able to send data and recive an echo from the MCU // you should now be able to send data and recive an echo from the MCU
// //
// try sending: "abcd" // try sending: "abcd" as a single sequence (set the option No end in moserial)
// (don't send the quation marks, just abcd)
// //
// what did you receive // what did you receive, and what was the output of the ITM trace
// ** your answer here ** // ** your answer here **
// //
// try changing to baud rate 57600, both in the program and terminal settings, // now try sending 'a', 'b', 'c', 'd' character by character
// recompile and run // (just send the characters not the single quotes and commas)
// what did you receive, and what was the output of the ITM trace
// ** your answer here **
// //
// try sending: "abcd" // why did the transmission fail? (hint, think about timing...)
// what did you receive
// ** your answer here ** // ** your answer here **
// //
// commit your answers as (bare7_1) // commit your answers (bare7_1)
//
// 2. now stress the buffer lengt sending a sequence
// 'a', 'b', 'c', 'd', 'e' character by character
// what did you receive, and what was the output of the ITM trace
// ** your answer here **
// //
// 2. now you should make a buffer // if done correctly you see an evedince of Rust's memory safety
// static BUFFER [u8;8] // the buffer will be saturated (all elements occupied)
// to store the incoming data // but no buffer owerwrite will occur (outside the buffer)
// //
// this can be done in a resource // your job now is to check the API of `heapless`
// app // https://docs.rs/heapless/0.2.1/heapless/
// //
// when the buffer is full you should write the complete buffer // and catch the case we are trying to write to a full buffer
// and write a suiteble error message
// //
// commit your answers (bare7_2)
// //
// !!!!! NOTICE !!!!!
// here we are not solving the underlying problem
// we are just mitigating the effects
// in bare8 we will se how to use interrupts for reliable
// high-speed communictation
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment