Skip to content

Commit a34dd4f

Browse files
authored
Merge pull request rust-embedded#125 from 30Wedge/fix-crash-example
Add a user-defined HardFault handler to print ExceptionFrame in crash…
2 parents cf52e9e + 6929b56 commit a34dd4f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/crash.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
use panic_halt as _;
8383

8484
use core::ptr;
85+
use core::fmt::Write;
8586

86-
use cortex_m_rt::entry;
87+
use cortex_m_rt::{entry, exception, ExceptionFrame};
88+
use cortex_m_semihosting::hio;
8789

8890
#[entry]
8991
fn main() -> ! {
@@ -94,3 +96,12 @@ fn main() -> ! {
9496

9597
loop {}
9698
}
99+
100+
#[exception]
101+
fn HardFault(ef: &ExceptionFrame) -> ! {
102+
if let Ok(mut hstdout) = hio::hstdout() {
103+
writeln!(hstdout, "{:#?}", ef).ok();
104+
}
105+
106+
loop {}
107+
}

0 commit comments

Comments
 (0)