diff --git a/examples/allocator.rs b/examples/allocator.rs index 5594e3c..e0a5ef4 100644 --- a/examples/allocator.rs +++ b/examples/allocator.rs @@ -17,13 +17,12 @@ extern crate panic_halt; use core::alloc::Layout; -use core::fmt::Write; use alloc::vec; use alloc_cortex_m::CortexMHeap; use cortex_m::asm; use cortex_m_rt::entry; -use cortex_m_semihosting::hio; +use cortex_m_semihosting::hprintln; // this is the allocator the application will use #[global_allocator] @@ -39,8 +38,7 @@ fn main() -> ! { // Growable array allocated on the heap let xs = vec![0, 1, 2]; - let mut stdout = hio::hstdout().unwrap(); - writeln!(stdout, "{:?}", xs).unwrap(); + hprintln!("{:?}", xs).unwrap(); loop {} } diff --git a/examples/device.rs b/examples/device.rs index 26e547a..6105aaa 100644 --- a/examples/device.rs +++ b/examples/device.rs @@ -27,11 +27,9 @@ #[allow(unused_extern_crates)] extern crate panic_halt; -use core::fmt::Write; - use cortex_m::peripheral::syst::SystClkSource; use cortex_m_rt::entry; -use cortex_m_semihosting::hio::{self, HStdout}; +use cortex_m_semihosting::hprint; use stm32f30x::{interrupt, Interrupt}; #[entry] @@ -58,14 +56,8 @@ fn main() -> ! { } // try commenting out this line: you'll end in `default_handler` instead of in `exti0` -interrupt!(EXTI0, exti0, state: Option = None); +interrupt!(EXTI0, exti0); -fn exti0(state: &mut Option) { - if state.is_none() { - *state = Some(hio::hstdout().unwrap()); - } - - if let Some(hstdout) = state.as_mut() { - hstdout.write_str(".").unwrap(); - } +fn exti0() { + hprint!(".").unwrap(); } diff --git a/examples/exception.rs b/examples/exception.rs index 6b9b103..756b85a 100644 --- a/examples/exception.rs +++ b/examples/exception.rs @@ -12,12 +12,10 @@ extern crate panic_halt; -use core::fmt::Write; - use cortex_m::peripheral::syst::SystClkSource; use cortex_m::Peripherals; use cortex_m_rt::{entry, exception}; -use cortex_m_semihosting::hio::{self, HStdout}; +use cortex_m_semihosting::hprint; #[entry] fn main() -> ! { @@ -35,13 +33,5 @@ fn main() -> ! { #[exception] fn SysTick() { - static mut STDOUT: Option = None; - - if STDOUT.is_none() { - *STDOUT = Some(hio::hstdout().unwrap()); - } - - if let Some(hstdout) = STDOUT.as_mut() { - hstdout.write_str(".").unwrap(); - } + hprint!(".").unwrap(); } diff --git a/examples/hello.rs b/examples/hello.rs index c7af29b..8e8586e 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -5,17 +5,15 @@ extern crate panic_halt; -use core::fmt::Write; - use cortex_m_rt::entry; -use cortex_m_semihosting::{debug, hio}; +use cortex_m_semihosting::{debug, hprintln}; #[entry] fn main() -> ! { - let mut stdout = hio::hstdout().unwrap(); - writeln!(stdout, "Hello, world!").unwrap(); + hprintln!("Hello, world!").unwrap(); - // exit QEMU or the debugger section + // exit QEMU + // NOTE do not run this on hardware; it can corrupt OpenOCD state debug::exit(debug::EXIT_SUCCESS); loop {}