Skip to content

Commit ffffb7b

Browse files
committed
Changed Hardfault's and DefaultHander's default implementations to panic
1 parent aa68192 commit ffffb7b

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
@@ -402,7 +403,6 @@ extern crate cortex_m_rt_macros as macros;
402403
extern crate r0;
403404

404405
use core::fmt;
405-
use core::sync::atomic::{self, Ordering};
406406

407407
/// Attribute to declare an interrupt (AKA device-specific exception) handler
408408
///
@@ -945,21 +945,17 @@ pub unsafe extern "C" fn Reset() -> ! {
945945
#[link_section = ".HardFault.default"]
946946
#[no_mangle]
947947
pub unsafe extern "C" fn HardFault_(ef: &ExceptionFrame) -> ! {
948-
loop {
949-
// add some side effect to prevent this from turning into a UDF instruction
950-
// see rust-lang/rust#28728 for details
951-
atomic::compiler_fence(Ordering::SeqCst);
952-
}
948+
panic!("Hardfault");
953949
}
954950

955951
#[doc(hidden)]
956952
#[no_mangle]
957953
pub unsafe extern "C" fn DefaultHandler_() -> ! {
958-
loop {
959-
// add some side effect to prevent this from turning into a UDF instruction
960-
// see rust-lang/rust#28728 for details
961-
atomic::compiler_fence(Ordering::SeqCst);
962-
}
954+
const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
955+
956+
let irqn = core::ptr::read(SCB_ICSR) as u8 as i16 - 16;
957+
958+
panic!("DefaultHandler #{}", irqn);
963959
}
964960

965961
#[doc(hidden)]

0 commit comments

Comments
 (0)