|
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 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. |
203 | 204 | //!
|
204 | 205 | //! - `HardFaultTrampoline`. This is the real hard fault handler. This function is simply a
|
205 | 206 | //! trampoline that jumps into the user defined hard fault handler named `HardFault`. The
|
206 | 207 | //! trampoline is required to set up the pointer to the stacked exception frame.
|
207 | 208 | //!
|
208 | 209 | //! - `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". |
210 | 211 | //!
|
211 | 212 | //! - `__STACK_START`. This is the first entry in the `.vector_table` section. This symbol contains
|
212 | 213 | //! 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;
|
407 | 408 | extern crate r0;
|
408 | 409 |
|
409 | 410 | use core::fmt;
|
410 |
| -use core::sync::atomic::{self, Ordering}; |
411 | 411 |
|
412 | 412 | /// Attribute to declare an interrupt (AKA device-specific exception) handler
|
413 | 413 | ///
|
@@ -950,21 +950,17 @@ pub unsafe extern "C" fn Reset() -> ! {
|
950 | 950 | #[link_section = ".HardFault.default"]
|
951 | 951 | #[no_mangle]
|
952 | 952 | 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"); |
958 | 954 | }
|
959 | 955 |
|
960 | 956 | #[doc(hidden)]
|
961 | 957 | #[no_mangle]
|
962 | 958 | 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); |
968 | 964 | }
|
969 | 965 |
|
970 | 966 | #[doc(hidden)]
|
|
0 commit comments