Skip to content

Commit d72d3bd

Browse files
bors[bot]korken89
andauthored
Merge #257
257: Changed Hardfault's and DefaultHander's default implementations to panic r=adamgreig a=korken89 From the discussions in #253 I started a PR with the proposed change. Co-authored-by: Emil Fresk <[email protected]>
2 parents 70c8edf + 853a47f commit d72d3bd

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,15 @@
199199
//! won't find it.
200200
//!
201201
//! - `DefaultHandler`. This is the default handler. If not overridden using `#[exception] fn
202-
//! DefaultHandler(..` this will be an infinite loop.
202+
//! DefaultHandler(..` this will cause a panic with the message "DefaultHandler #`i`", where `i` is
203+
//! the number of the interrupt handler.
203204
//!
204205
//! - `HardFaultTrampoline`. This is the real hard fault handler. This function is simply a
205206
//! trampoline that jumps into the user defined hard fault handler named `HardFault`. The
206207
//! trampoline is required to set up the pointer to the stacked exception frame.
207208
//!
208209
//! - `HardFault`. This is the user defined hard fault handler. If not overridden using
209-
//! `#[exception] fn HardFault(..` it will default to an infinite loop.
210+
//! `#[exception] fn HardFault(..` it will default to a panic with message "HardFault".
210211
//!
211212
//! - `__STACK_START`. This is the first entry in the `.vector_table` section. This symbol contains
212213
//! the initial value of the stack pointer; this is where the stack will be located -- the stack
@@ -407,7 +408,6 @@ extern crate cortex_m_rt_macros as macros;
407408
extern crate r0;
408409

409410
use core::fmt;
410-
use core::sync::atomic::{self, Ordering};
411411

412412
/// Attribute to declare an interrupt (AKA device-specific exception) handler
413413
///
@@ -950,21 +950,17 @@ pub unsafe extern "C" fn Reset() -> ! {
950950
#[link_section = ".HardFault.default"]
951951
#[no_mangle]
952952
pub unsafe extern "C" fn HardFault_(ef: &ExceptionFrame) -> ! {
953-
loop {
954-
// add some side effect to prevent this from turning into a UDF instruction
955-
// see rust-lang/rust#28728 for details
956-
atomic::compiler_fence(Ordering::SeqCst);
957-
}
953+
panic!("HardFault");
958954
}
959955

960956
#[doc(hidden)]
961957
#[no_mangle]
962958
pub unsafe extern "C" fn DefaultHandler_() -> ! {
963-
loop {
964-
// add some side effect to prevent this from turning into a UDF instruction
965-
// see rust-lang/rust#28728 for details
966-
atomic::compiler_fence(Ordering::SeqCst);
967-
}
959+
const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
960+
961+
let irqn = core::ptr::read(SCB_ICSR) as u8 as i16 - 16;
962+
963+
panic!("DefaultHandler #{}", irqn);
968964
}
969965

970966
#[doc(hidden)]

0 commit comments

Comments
 (0)