From 7ea82ddd63b07d37f5a277da832baf86ac0c10ee Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Fri, 20 Oct 2017 01:02:26 +0200 Subject: [PATCH] println and gpio --- .vscode/tasks.json | 21 ++++++++++++++++----- examples/gpio.rs | 18 ++++++++---------- examples/usart1.rs | 11 +++++++++++ src/lib.rs | 12 ++++++++++++ 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d4e35cb..2e40660 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -25,16 +25,27 @@ "command": "xargo build --example gpio", "problemMatcher": [ "$rustc" - ] + ], + "group": { + "kind": "build", + "isDefault": true + } }, { "taskName": "xargo build --example usart1", "type": "shell", "command": "xargo build --example usart1", - "group": { - "kind": "build", - "isDefault": true - }, + "problemMatcher": [ + "$rustc" + ] + }, + { + "type": "shell", + "taskName": "cargo build", + "command": "cargo", + "args": [ + "build" + ], "problemMatcher": [ "$rustc" ] diff --git a/examples/gpio.rs b/examples/gpio.rs index 54b931c..e68e902 100644 --- a/examples/gpio.rs +++ b/examples/gpio.rs @@ -5,13 +5,11 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; -extern crate cortex_m_semihosting as semihosting; +#[macro_use] extern crate nucleo_64; extern crate stm32f40x; use rtfm::app; -use semihosting::hio; -use core::fmt::Write; use nucleo_64::gpio::PA5; app! { @@ -19,7 +17,7 @@ app! { } fn init(p: init::Peripherals) { - writeln!(hio::hstdout().unwrap(), "Init!").unwrap(); + println!("Init!"); // RM0368 6.3.9 // enable clock to GPIOA p.RCC.ahb1enr.modify(|_, w| w.gpioaen().enable()); @@ -33,12 +31,12 @@ fn init(p: init::Peripherals) { } fn idle() -> ! { - writeln!(hio::hstdout().unwrap(), "PA5 high!").unwrap(); - PA5.high(); - writeln!(hio::hstdout().unwrap(), "PA5 low!").unwrap(); - PA5.low(); - // Sleep loop { - rtfm::wfi(); + println!("PA5 high!"); + PA5.high(); + rtfm::bkpt(); + println!("PA5 low!"); + PA5.low(); + rtfm::bkpt(); } } diff --git a/examples/usart1.rs b/examples/usart1.rs index 9b9ea4b..5ba1d25 100644 --- a/examples/usart1.rs +++ b/examples/usart1.rs @@ -11,6 +11,7 @@ extern crate cortex_m_rtfm as rtfm; extern crate cortex_m_semihosting as semihosting; +#[macro_use] extern crate nb; extern crate nucleo_64; extern crate stm32f40x; @@ -109,6 +110,15 @@ fn init(p: init::Peripherals) { // 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'; assert!(write(p.USART2, BYTE).is_ok()); @@ -140,6 +150,7 @@ pub enum Error { Overrun, #[doc(hidden)] _Extensible, } + fn write(usart2: &USART2, byte: u8) -> Result<()> { let sr = usart2.sr.read(); diff --git a/src/lib.rs b/src/lib.rs index 0f57797..4435560 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,3 +139,15 @@ pub mod apb1 { pub mod apb2 { 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(); + } + } +} -- GitLab