diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d4e35cba6dfb8546f2370736b85a9236e4246a10..2e40660a8b30819144ad6f79069a6c04a6dd0381 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 54b931cdcb7184d7b84eec0b96705e2542997926..e68e9021adcd535185bd0a68509e115e2f4dcb8b 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 9b9ea4bd350b609a038ec0a396484665b2994e43..5ba1d25a93ceb58a9e15e63ffb4544ce0d04512a 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 0f57797788ead322b0adf5fff07ed04e7ea1708b..443556075f92517808ac1b381952df9b1609dca1 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(); + } + } +}