Commit 73157781 authored by Per's avatar Per

bare7 broken

parent e037976e
//! Serial interface loopback
#![deny(unsafe_code)]
#![deny(warnings)]
//#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern crate cortex_m_rtfm as rtfm;
extern crate f4;
extern crate heapless;
#[macro_use(block)]
extern crate nb;
#[macro_use]
extern crate cortex_m_debug;
use f4::prelude::*;
use f4::Serial;
use f4::serial::Event;
use f4::time::Hertz;
use heapless::Vec;
use rtfm::{app, Threshold};
// CONFIGURATION
const BAUD_RATE: Hertz = Hertz(115_200);
// TASKS & RESOURCES
// RTFM FRAMEWORK
app! {
device: f4::stm32f40x,
tasks: {
USART2: {
path: loopback,
resources: [USART2],
},
}
}
// static BUFFER: Vec<u8, [u8; 8]> = Vec::new();
// INITIALIZATION PHASE
// Init executes with interrupts disabled
// Hence its safe to access all peripherals (no race-conditions)
//
// In this case init will never return
// This is not the typical use-case as we will see later
fn init(p: init::Peripherals) {
ipln!("init");
let serial = Serial(p.USART2);
serial.init(BAUD_RATE.invert(), None, p.GPIOA, p.RCC);
serial.listen(Event::Rxne);
let mut buffer: Vec<u8, [u8; 4]> = Vec::new();
loop {
if let Ok(byte) = block!(serial.read()) {
buffer.push(byte);
ipln!("Ok {:?}", buffer);
block!(serial.write(byte)).ok();
} else {
ipln!("Error");
}
}
}
// IDLE LOOP
......@@ -44,15 +60,6 @@ fn idle() -> ! {
}
}
// TASKS
// Send back the received byte
fn loopback(_t: &mut Threshold, r: USART2::Resources) {
let serial = Serial(&**r.USART2);
let byte = serial.read().unwrap();
serial.write(byte).unwrap();
}
// 1. compile and run the project at 16MHz
// make sure its running (not paused)
// start a terminal program, e.g., `moserial`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment