Skip to content

Commit

Permalink
Merge pull request rust-embedded#125 from 30Wedge/fix-crash-example
Browse files Browse the repository at this point in the history
Add a user-defined HardFault handler to print ExceptionFrame in crash…
  • Loading branch information
newAM authored Jul 13, 2024
2 parents cf52e9e + 6929b56 commit a34dd4f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/crash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
use panic_halt as _;

use core::ptr;
use core::fmt::Write;

use cortex_m_rt::entry;
use cortex_m_rt::{entry, exception, ExceptionFrame};
use cortex_m_semihosting::hio;

#[entry]
fn main() -> ! {
Expand All @@ -94,3 +96,12 @@ fn main() -> ! {

loop {}
}

#[exception]
fn HardFault(ef: &ExceptionFrame) -> ! {
if let Ok(mut hstdout) = hio::hstdout() {
writeln!(hstdout, "{:#?}", ef).ok();
}

loop {}
}

0 comments on commit a34dd4f

Please sign in to comment.