Skip to content

Commit faf7bd3

Browse files
committed
Add to docs
1 parent 5517d54 commit faf7bd3

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,15 @@
225225
//! - `DefaultHandler`. This is the default handler. If not overridden using `#[exception] fn
226226
//! DefaultHandler(..` this will be an infinite loop.
227227
//!
228-
//! - `HardFaultTrampoline`. This is the real hard fault handler. This function is simply a
229-
//! trampoline that jumps into the user defined hard fault handler named `HardFault`. The
230-
//! trampoline is required to set up the pointer to the stacked exception frame.
231-
//!
232-
//! - `HardFault`. This is the user defined hard fault handler. If not overridden using
233-
//! `#[exception] fn HardFault(..` it will default to an infinite loop.
228+
//! - `HardFault` and `_HardFault`. These function handle the hard fault handling and what they
229+
//! do depends on whether the hard fault is overridden and whether the trampoline is enabled (which it is by default).
230+
//! - No override: Both are the same function. The function is an infinite loop defined in the cortex-m-rt crate.
231+
//! - Trampoline enabled: `HardFault` is the real hard fault handler defined in assembly. This function is simply a
232+
//! trampoline that jumps into the rust defined `_HardFault` function. This second function jumps to the user-defined
233+
//! handler with the exception frame as parameter. This second jump is usually optimised away with inlining.
234+
//! - Trampoline disabled: `HardFault` is the user defined function. This means the user function is called directly
235+
//! from the vector table. `_HardFault` still exists, but is an empty function that is purely there for compiler
236+
//! diagnostics.
234237
//!
235238
//! - `__STACK_START`. This is the first entry in the `.vector_table` section. This symbol contains
236239
//! the initial value of the stack pointer; this is where the stack will be located -- the stack
@@ -724,16 +727,27 @@ pub use macros::entry;
724727
///
725728
/// # Usage
726729
///
727-
/// `#[exception] unsafe fn HardFault(..` sets the hard fault handler. The handler must have
728-
/// signature `unsafe fn(&ExceptionFrame) -> !`. This handler is not allowed to return as that can
729-
/// cause undefined behavior.
730+
/// ## HardFault handler
731+
///
732+
/// `#[exception(trampoline = true)] unsafe fn HardFault(..` sets the hard fault handler.
733+
/// If the trampoline parameter is set to true, the handler must have signature `unsafe fn(&ExceptionFrame) -> !`.
734+
/// If set to false, the handler must have signature `unsafe fn() -> !`.
735+
///
736+
/// This handler is not allowed to return as that can cause undefined behavior.
737+
///
738+
/// To maintain backwards compatibility the attribute can be used without trampoline parameter (`#[exception]`),
739+
/// which sets the trampoline to true.
740+
///
741+
/// ## Default handler
730742
///
731743
/// `#[exception] unsafe fn DefaultHandler(..` sets the *default* handler. All exceptions which have
732744
/// not been assigned a handler will be serviced by this handler. This handler must have signature
733745
/// `unsafe fn(irqn: i16) [-> !]`. `irqn` is the IRQ number (See CMSIS); `irqn` will be a negative
734746
/// number when the handler is servicing a core exception; `irqn` will be a positive number when the
735747
/// handler is servicing a device specific exception (interrupt).
736748
///
749+
/// ## Other handlers
750+
///
737751
/// `#[exception] fn Name(..` overrides the default handler for the exception with the given `Name`.
738752
/// These handlers must have signature `[unsafe] fn() [-> !]`. When overriding these other exception
739753
/// it's possible to add state to them by declaring `static mut` variables at the beginning of the

0 commit comments

Comments
 (0)