Skip to content

Commit 335856a

Browse files
committed
[WIP] provide defaults for DefaultHandler and HardFault
`exception!(HardFault, ..)` and `exception!(*, ..)` can now be omitted from programs to pick up the default behavior of an infinite loop. Existing programs that define these exception handlers will continue to work w/o any functional change. closes #72
1 parent 7865725 commit 335856a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

cortex-m-rt/link.x.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ PROVIDE(DebugMonitor = DefaultHandler);
4545
PROVIDE(PendSV = DefaultHandler);
4646
PROVIDE(SysTick = DefaultHandler);
4747

48+
PROVIDE(DefaultHandler = DefaultDefaultHandler);
49+
PROVIDE(UserHardFault = DefaultUserHardFault);
50+
4851
/* # Interrupt vectors */
4952
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
5053

cortex-m-rt/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390

391391
extern crate r0;
392392

393-
use core::fmt;
393+
use core::{fmt, ptr};
394394

395395
/// Registers stacked (pushed into the stack) during an exception
396396
#[derive(Clone, Copy)]
@@ -511,6 +511,26 @@ pub unsafe extern "C" fn Reset() -> ! {
511511
}
512512
}
513513

514+
#[doc(hidden)]
515+
#[no_mangle]
516+
pub unsafe extern "C" fn DefaultDefaultHandler() {
517+
loop {
518+
// add some side effect to prevent this from turning into a UDF instruction
519+
// see rust-lang/rust#28728
520+
ptr::read_volatile(&0u8);
521+
}
522+
}
523+
524+
#[doc(hidden)]
525+
#[no_mangle]
526+
pub unsafe extern "C" fn DefaultUserHardFault() {
527+
loop {
528+
// add some side effect to prevent this from turning into a UDF instruction
529+
// see rust-lang/rust#28728
530+
ptr::read_volatile(&0u8);
531+
}
532+
}
533+
514534
/// Macro to define the entry point of the program
515535
///
516536
/// **NOTE** This macro must be invoked once and must be invoked from an accessible module, ideally

0 commit comments

Comments
 (0)