From 9c6b290e12f9aaf5fee14cabe6e4b2a57cee9de6 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 9 Nov 2018 23:51:11 +0100 Subject: [PATCH 1/4] use hprint macros --- examples/allocator.rs | 6 ++---- examples/device.rs | 16 ++++------------ examples/exception.rs | 14 ++------------ examples/hello.rs | 10 ++++------ 4 files changed, 12 insertions(+), 34 deletions(-) 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 {} From f7a943f480dbf2268363783891c47613db6b74b7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 10 Nov 2018 00:01:25 +0100 Subject: [PATCH 2/4] fix the allocator example importing alloc is a bit weird --- examples/allocator.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/allocator.rs b/examples/allocator.rs index e0a5ef4..0399ebb 100644 --- a/examples/allocator.rs +++ b/examples/allocator.rs @@ -14,11 +14,12 @@ #![no_main] #![no_std] +extern crate alloc; extern crate panic_halt; +use self::alloc::vec; use core::alloc::Layout; -use alloc::vec; use alloc_cortex_m::CortexMHeap; use cortex_m::asm; use cortex_m_rt::entry; @@ -40,6 +41,10 @@ fn main() -> ! { hprintln!("{:?}", xs).unwrap(); + // exit QEMU + // NOTE do not run this on hardware; it can corrupt OpenOCD state + debug::exit(debug::EXIT_SUCCESS); + loop {} } From e64e69051212c5b0b5d4bd382ab2ae8aa4b19dd8 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 10 Nov 2018 00:02:00 +0100 Subject: [PATCH 3/4] use NVIC::pend instead of the deprecated NVIC.set_pending --- examples/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/device.rs b/examples/device.rs index 6105aaa..8205237 100644 --- a/examples/device.rs +++ b/examples/device.rs @@ -51,7 +51,7 @@ fn main() -> ! { while !syst.has_wrapped() {} // trigger the `EXTI0` interrupt - nvic.set_pending(Interrupt::EXTI0); + NVIC::pend(Interrupt::EXTI0); } } From 55e61c3291ddca5eda4397904ab88960eaff5f7f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 10 Nov 2018 00:04:28 +0100 Subject: [PATCH 4/4] bump dependencies --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 853c94a..a637c20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,9 @@ name = "{{project-name}}" version = "0.1.0" [dependencies] -cortex-m = "0.5.7" -cortex-m-rt = "0.6.3" -cortex-m-semihosting = "0.3.1" +cortex-m = "0.5.8" +cortex-m-rt = "0.6.5" +cortex-m-semihosting = "0.3.2" panic-halt = "0.2.0" # Uncomment for the panic example.