Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 9c6b290

Browse files
committed
use hprint macros
1 parent 7e2bec6 commit 9c6b290

File tree

4 files changed

+12
-34
lines changed

4 files changed

+12
-34
lines changed

examples/allocator.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
extern crate panic_halt;
1818

1919
use core::alloc::Layout;
20-
use core::fmt::Write;
2120

2221
use alloc::vec;
2322
use alloc_cortex_m::CortexMHeap;
2423
use cortex_m::asm;
2524
use cortex_m_rt::entry;
26-
use cortex_m_semihosting::hio;
25+
use cortex_m_semihosting::hprintln;
2726

2827
// this is the allocator the application will use
2928
#[global_allocator]
@@ -39,8 +38,7 @@ fn main() -> ! {
3938
// Growable array allocated on the heap
4039
let xs = vec![0, 1, 2];
4140

42-
let mut stdout = hio::hstdout().unwrap();
43-
writeln!(stdout, "{:?}", xs).unwrap();
41+
hprintln!("{:?}", xs).unwrap();
4442

4543
loop {}
4644
}

examples/device.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
#[allow(unused_extern_crates)]
2828
extern crate panic_halt;
2929

30-
use core::fmt::Write;
31-
3230
use cortex_m::peripheral::syst::SystClkSource;
3331
use cortex_m_rt::entry;
34-
use cortex_m_semihosting::hio::{self, HStdout};
32+
use cortex_m_semihosting::hprint;
3533
use stm32f30x::{interrupt, Interrupt};
3634

3735
#[entry]
@@ -58,14 +56,8 @@ fn main() -> ! {
5856
}
5957

6058
// try commenting out this line: you'll end in `default_handler` instead of in `exti0`
61-
interrupt!(EXTI0, exti0, state: Option<HStdout> = None);
62-
63-
fn exti0(state: &mut Option<HStdout>) {
64-
if state.is_none() {
65-
*state = Some(hio::hstdout().unwrap());
66-
}
59+
interrupt!(EXTI0, exti0);
6760

68-
if let Some(hstdout) = state.as_mut() {
69-
hstdout.write_str(".").unwrap();
70-
}
61+
fn exti0() {
62+
hprint!(".").unwrap();
7163
}

examples/exception.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313
extern crate panic_halt;
1414

15-
use core::fmt::Write;
16-
1715
use cortex_m::peripheral::syst::SystClkSource;
1816
use cortex_m::Peripherals;
1917
use cortex_m_rt::{entry, exception};
20-
use cortex_m_semihosting::hio::{self, HStdout};
18+
use cortex_m_semihosting::hprint;
2119

2220
#[entry]
2321
fn main() -> ! {
@@ -35,13 +33,5 @@ fn main() -> ! {
3533

3634
#[exception]
3735
fn SysTick() {
38-
static mut STDOUT: Option<HStdout> = None;
39-
40-
if STDOUT.is_none() {
41-
*STDOUT = Some(hio::hstdout().unwrap());
42-
}
43-
44-
if let Some(hstdout) = STDOUT.as_mut() {
45-
hstdout.write_str(".").unwrap();
46-
}
36+
hprint!(".").unwrap();
4737
}

examples/hello.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
extern crate panic_halt;
77

8-
use core::fmt::Write;
9-
108
use cortex_m_rt::entry;
11-
use cortex_m_semihosting::{debug, hio};
9+
use cortex_m_semihosting::{debug, hprintln};
1210

1311
#[entry]
1412
fn main() -> ! {
15-
let mut stdout = hio::hstdout().unwrap();
16-
writeln!(stdout, "Hello, world!").unwrap();
13+
hprintln!("Hello, world!").unwrap();
1714

18-
// exit QEMU or the debugger section
15+
// exit QEMU
16+
// NOTE do not run this on hardware; it can corrupt OpenOCD state
1917
debug::exit(debug::EXIT_SUCCESS);
2018

2119
loop {}

0 commit comments

Comments
 (0)