v0.2.0
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
//! Overriding an exception
|
||||
//! Overriding an exception handler
|
||||
//!
|
||||
//! **NOTE** You have to disable the `cortex-m-rt` crate's "exceptions" feature
|
||||
//! to make this work.
|
||||
//! You can override an exception handler using the [`exception!`][1] macro.
|
||||
//!
|
||||
//! [1]: https://docs.rs/cortex-m-rt/0.3.2/cortex_m_rt/macro.exception.html
|
||||
//!
|
||||
//! The default exception handler can be overridden using the
|
||||
//! [`default_handler!`][2] macro
|
||||
//!
|
||||
//! [2]: https://docs.rs/cortex-m-rt/0.3.2/cortex_m_rt/macro.default_handler.html
|
||||
//!
|
||||
//! ---
|
||||
|
||||
#![feature(used)]
|
||||
#![no_std]
|
||||
|
||||
extern crate cortex_m;
|
||||
#[macro_use(exception)]
|
||||
extern crate cortex_m_rt;
|
||||
|
||||
use core::ptr;
|
||||
|
||||
use cortex_m::{asm, exception};
|
||||
use cortex_m::asm;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
@@ -20,25 +29,17 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn hard_fault(_: exception::HardFault) {
|
||||
exception!(HARD_FAULT, handler);
|
||||
|
||||
fn handler() {
|
||||
// You'll hit this breakpoint rather than the one in cortex-m-rt
|
||||
asm::bkpt()
|
||||
}
|
||||
|
||||
// When the "exceptions" feature is disabled, you'll have to provide this symbol
|
||||
#[allow(dead_code)]
|
||||
#[used]
|
||||
#[link_section = ".rodata.exceptions"]
|
||||
static EXCEPTIONS: exception::Handlers = exception::Handlers {
|
||||
// This is the exception handler override
|
||||
hard_fault: hard_fault,
|
||||
..exception::DEFAULT_HANDLERS
|
||||
};
|
||||
|
||||
// As we are not using interrupts, we just register a dummy catch all handler
|
||||
#[allow(dead_code)]
|
||||
#[used]
|
||||
#[link_section = ".rodata.interrupts"]
|
||||
#[link_section = ".vector_table.interrupts"]
|
||||
static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240];
|
||||
|
||||
extern "C" fn default_handler() {
|
||||
|
||||
Reference in New Issue
Block a user