|
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
|
@@ -402,7 +403,6 @@ extern crate cortex_m_rt_macros as macros;
|
402 | 403 | extern crate r0;
|
403 | 404 |
|
404 | 405 | use core::fmt;
|
405 |
| -use core::sync::atomic::{self, Ordering}; |
406 | 406 |
|
407 | 407 | /// Attribute to declare an interrupt (AKA device-specific exception) handler
|
408 | 408 | ///
|
@@ -945,21 +945,17 @@ pub unsafe extern "C" fn Reset() -> ! {
|
945 | 945 | #[link_section = ".HardFault.default"]
|
946 | 946 | #[no_mangle]
|
947 | 947 | 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"); |
953 | 949 | }
|
954 | 950 |
|
955 | 951 | #[doc(hidden)]
|
956 | 952 | #[no_mangle]
|
957 | 953 | 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); |
963 | 959 | }
|
964 | 960 |
|
965 | 961 | #[doc(hidden)]
|
|
0 commit comments