...
 
Commits (3)
......@@ -425,6 +425,62 @@
]
},
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "c bare6 84Mhz",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare6",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
"monitor reset init"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 84000000,
"swoFrequency": 2000000, // you may try 1000000 if not working
"source": "probe",
"decoders": [
{
"type": "console",
"label": "Name",
"port": 0
}
]
},
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "c bare7 16Mhz",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare7",
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
"continue"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000, // you may try 1000000 if not working
"source": "probe",
"decoders": [
{
"type": "console",
"label": "Name",
"port": 0
}
]
},
"cwd": "${workspaceRoot}"
}
]
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ cortex-m-rtfm = "0.2.2"
cortex-m = "0.3.1"
rtfm-core = "0.1.0"
cortex-m-semihosting = "0.2.0"
heapless = "0.2.0"
[dependencies.cortex-m-debug]
version = "0.1.0"
......@@ -34,9 +35,12 @@ version = "0.2.0"
git = "https://github.com/jsjolund/f4"
version = "0.1.0"
[features]
wcet_bkpt = []
wcet_nop = []
#[dev-dependencies.nb]
#features = ["unstable"]
#version = "0.1.1"
[dependencies.nb]
git = "https://github.com/japaric/nb"
[profile.release]
lto = true
......
//! 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`
......