Skip to content
Snippets Groups Projects
Commit 2246228d authored by Per Lindgren's avatar Per Lindgren
Browse files

bare6 84hmz

parent 6deb811a
Branches
No related tags found
No related merge requests found
//! Serial interface loopback
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern crate cortex_m_rtfm as rtfm;
extern crate f4;
use f4::prelude::*;
use f4::Serial;
use f4::serial::Event;
use f4::time::Hertz;
use rtfm::{app, Threshold};
// CONFIGURATION
const BAUD_RATE: Hertz = Hertz(115_200);
// TASKS & RESOURCES
app! {
device: f4::stm32f40x,
tasks: {
USART2: {
path: loopback,
resources: [USART2],
},
}
}
// INITIALIZATION PHASE
fn init(p: init::Peripherals) {
let serial = Serial(p.USART2);
serial.init(BAUD_RATE.invert(), None, p.GPIOA, p.RCC);
serial.listen(Event::Rxne);
}
// IDLE LOOP
fn idle() -> ! {
// Sleep
loop {
rtfm::wfi();
}
}
// 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`
// connect to the port
//
// Device /dev/ttyACM0
// Baude Rate 115200
// Data Bits 8
// Stop Bits 1
// Parity None
// Handshake None
//
// (this is also known in short as 15200 8N1)
//
// you should now be able to send data and recive an echo from the MCU
//
// try sending: "abcd"
//
// what did you receive
// ** your answer here **
//
// try changing to baud rate 57600, both in the program and terminal settings,
// recompile and run
//
// try sending: "abcd"
// what did you receive
// ** your answer here **
//
// commit your answers as (bare7_1)
//
// 2. now you should make a buffer
// static BUFFER [u8;8]
// to store the incoming data
//
// this can be done in a resource
// app
//
// when the buffer is full you should write the complete buffer
//
//
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment