Skip to content
Snippets Groups Projects
Commit 7ea82ddd authored by Per's avatar Per
Browse files

println and gpio

parent 93ae125c
No related branches found
No related tags found
No related merge requests found
...@@ -25,16 +25,27 @@ ...@@ -25,16 +25,27 @@
"command": "xargo build --example gpio", "command": "xargo build --example gpio",
"problemMatcher": [ "problemMatcher": [
"$rustc" "$rustc"
] ],
"group": {
"kind": "build",
"isDefault": true
}
}, },
{ {
"taskName": "xargo build --example usart1", "taskName": "xargo build --example usart1",
"type": "shell", "type": "shell",
"command": "xargo build --example usart1", "command": "xargo build --example usart1",
"group": { "problemMatcher": [
"kind": "build", "$rustc"
"isDefault": true ]
}, },
{
"type": "shell",
"taskName": "cargo build",
"command": "cargo",
"args": [
"build"
],
"problemMatcher": [ "problemMatcher": [
"$rustc" "$rustc"
] ]
......
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
#![no_std] #![no_std]
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate cortex_m_semihosting as semihosting; #[macro_use]
extern crate nucleo_64; extern crate nucleo_64;
extern crate stm32f40x; extern crate stm32f40x;
use rtfm::app; use rtfm::app;
use semihosting::hio;
use core::fmt::Write;
use nucleo_64::gpio::PA5; use nucleo_64::gpio::PA5;
app! { app! {
...@@ -19,7 +17,7 @@ app! { ...@@ -19,7 +17,7 @@ app! {
} }
fn init(p: init::Peripherals) { fn init(p: init::Peripherals) {
writeln!(hio::hstdout().unwrap(), "Init!").unwrap(); println!("Init!");
// RM0368 6.3.9 // RM0368 6.3.9
// enable clock to GPIOA // enable clock to GPIOA
p.RCC.ahb1enr.modify(|_, w| w.gpioaen().enable()); p.RCC.ahb1enr.modify(|_, w| w.gpioaen().enable());
...@@ -33,12 +31,12 @@ fn init(p: init::Peripherals) { ...@@ -33,12 +31,12 @@ fn init(p: init::Peripherals) {
} }
fn idle() -> ! { fn idle() -> ! {
writeln!(hio::hstdout().unwrap(), "PA5 high!").unwrap(); loop {
println!("PA5 high!");
PA5.high(); PA5.high();
writeln!(hio::hstdout().unwrap(), "PA5 low!").unwrap(); rtfm::bkpt();
println!("PA5 low!");
PA5.low(); PA5.low();
// Sleep rtfm::bkpt();
loop {
rtfm::wfi();
} }
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_rtfm as rtfm;
extern crate cortex_m_semihosting as semihosting; extern crate cortex_m_semihosting as semihosting;
#[macro_use]
extern crate nb; extern crate nb;
extern crate nucleo_64; extern crate nucleo_64;
extern crate stm32f40x; extern crate stm32f40x;
...@@ -109,6 +110,15 @@ fn init(p: init::Peripherals) { ...@@ -109,6 +110,15 @@ fn init(p: init::Peripherals) {
// serial.init(BAUD_RATE.invert(), p.AFIO, None, p.GPIOA, p.RCC); // serial.init(BAUD_RATE.invert(), p.AFIO, None, p.GPIOA, p.RCC);
// echo incoming
loop {
let b = block!(read(p.USART2)).unwrap();
write(p.USART2, b).unwrap();
}
const BYTE: u8 = b'A'; const BYTE: u8 = b'A';
assert!(write(p.USART2, BYTE).is_ok()); assert!(write(p.USART2, BYTE).is_ok());
...@@ -140,6 +150,7 @@ pub enum Error { ...@@ -140,6 +150,7 @@ pub enum Error {
Overrun, Overrun,
#[doc(hidden)] _Extensible, #[doc(hidden)] _Extensible,
} }
fn write(usart2: &USART2, byte: u8) -> Result<()> { fn write(usart2: &USART2, byte: u8) -> Result<()> {
let sr = usart2.sr.read(); let sr = usart2.sr.read();
......
...@@ -139,3 +139,15 @@ pub mod apb1 { ...@@ -139,3 +139,15 @@ pub mod apb1 {
pub mod apb2 { pub mod apb2 {
frequency!(16_000_000); frequency!(16_000_000);
} }
/// println over semihosting
#[macro_export]
macro_rules! println {
($e:expr) => {
{
extern crate cortex_m_semihosting;
use core::fmt::Write;
writeln!(cortex_m_semihosting::hio::hstdout().unwrap(), $e).unwrap();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment