|
199 | 199 | //! won't find it.
|
200 | 200 | //!
|
201 | 201 | //! - `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. |
204 | 203 | //!
|
205 | 204 | //! - `HardFaultTrampoline`. This is the real hard fault handler. This function is simply a
|
206 | 205 | //! trampoline that jumps into the user defined hard fault handler named `HardFault`. The
|
207 | 206 | //! trampoline is required to set up the pointer to the stacked exception frame.
|
208 | 207 | //!
|
209 | 208 | //! - `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. |
211 | 210 | //!
|
212 | 211 | //! - `__STACK_START`. This is the first entry in the `.vector_table` section. This symbol contains
|
213 | 212 | //! 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;
|
442 | 441 | extern crate r0;
|
443 | 442 |
|
444 | 443 | use core::fmt;
|
| 444 | +use core::sync::atomic::{self, Ordering}; |
445 | 445 |
|
446 | 446 | /// Attribute to declare an interrupt (AKA device-specific exception) handler
|
447 | 447 | ///
|
@@ -990,17 +990,21 @@ pub unsafe extern "C" fn Reset() -> ! {
|
990 | 990 | #[link_section = ".HardFault.default"]
|
991 | 991 | #[no_mangle]
|
992 | 992 | 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 | + } |
994 | 998 | }
|
995 | 999 |
|
996 | 1000 | #[doc(hidden)]
|
997 | 1001 | #[no_mangle]
|
998 | 1002 | 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 | + } |
1004 | 1008 | }
|
1005 | 1009 |
|
1006 | 1010 | #[doc(hidden)]
|
|
0 commit comments