Skip to content

Commit ac74bff

Browse files
Revert "Changed Hardfault's and DefaultHander's default implementations to panic"
This reverts commit ffffb7b.
1 parent 679d422 commit ac74bff

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

cortex-m-rt/src/lib.rs

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

444443
use core::fmt;
444+
use core::sync::atomic::{self, Ordering};
445445

446446
/// Attribute to declare an interrupt (AKA device-specific exception) handler
447447
///
@@ -990,17 +990,21 @@ pub unsafe extern "C" fn Reset() -> ! {
990990
#[link_section = ".HardFault.default"]
991991
#[no_mangle]
992992
pub unsafe extern "C" fn HardFault_(ef: &ExceptionFrame) -> ! {
993-
panic!("HardFault");
993+
loop {
994+
// add some side effect to prevent this from turning into a UDF instruction
995+
// see rust-lang/rust#28728 for details
996+
atomic::compiler_fence(Ordering::SeqCst);
997+
}
994998
}
995999

9961000
#[doc(hidden)]
9971001
#[no_mangle]
9981002
pub unsafe extern "C" fn DefaultHandler_() -> ! {
999-
const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
1000-
1001-
let irqn = core::ptr::read(SCB_ICSR) as u8 as i16 - 16;
1002-
1003-
panic!("DefaultHandler #{}", irqn);
1003+
loop {
1004+
// add some side effect to prevent this from turning into a UDF instruction
1005+
// see rust-lang/rust#28728 for details
1006+
atomic::compiler_fence(Ordering::SeqCst);
1007+
}
10041008
}
10051009

10061010
#[doc(hidden)]

0 commit comments

Comments
 (0)