diff options
Diffstat (limited to 'cortex-m-rt/examples')
-rw-r--r-- | cortex-m-rt/examples/alignment.rs | 14 | ||||
-rw-r--r-- | cortex-m-rt/examples/device.rs | 16 | ||||
-rw-r--r-- | cortex-m-rt/examples/main.rs | 15 | ||||
-rw-r--r-- | cortex-m-rt/examples/minimal.rs | 16 | ||||
-rw-r--r-- | cortex-m-rt/examples/override-exception.rs | 35 | ||||
-rw-r--r-- | cortex-m-rt/examples/state.rs | 14 |
6 files changed, 38 insertions, 72 deletions
diff --git a/cortex-m-rt/examples/alignment.rs b/cortex-m-rt/examples/alignment.rs index ef1beaa..5635851 100644 --- a/cortex-m-rt/examples/alignment.rs +++ b/cortex-m-rt/examples/alignment.rs @@ -4,14 +4,12 @@ #![no_main] #![no_std] -#[macro_use(entry, exception)] +#[macro_use(entry)] extern crate cortex_m_rt as rt; extern crate panic_abort; use core::ptr; -use rt::ExceptionFrame; - entry!(main); static mut BSS1: u16 = 0; @@ -33,13 +31,3 @@ fn main() -> ! { loop {} } - -exception!(HardFault, hard_fault); - -fn hard_fault(_ef: &ExceptionFrame) -> ! { - loop {} -} - -exception!(*, default_handler); - -fn default_handler(_irqn: i16) {} diff --git a/cortex-m-rt/examples/device.rs b/cortex-m-rt/examples/device.rs index cf91f21..4395db2 100644 --- a/cortex-m-rt/examples/device.rs +++ b/cortex-m-rt/examples/device.rs @@ -5,12 +5,10 @@ #![no_main] #![no_std] -#[macro_use(entry, exception)] +#[macro_use(entry)] extern crate cortex_m_rt as rt; extern crate panic_semihosting; -use rt::ExceptionFrame; - // the program entry point entry!(main); @@ -18,18 +16,6 @@ fn main() -> ! { loop {} } -// the hard fault handler -exception!(HardFault, hard_fault); - -fn hard_fault(_ef: &ExceptionFrame) -> ! { - loop {} -} - -// the default exception handler -exception!(*, default_handler); - -fn default_handler(_irqn: i16) {} - // interrupts portion of the vector table pub union Vector { handler: unsafe extern "C" fn(), diff --git a/cortex-m-rt/examples/main.rs b/cortex-m-rt/examples/main.rs index d319249..e5ce3d1 100644 --- a/cortex-m-rt/examples/main.rs +++ b/cortex-m-rt/examples/main.rs @@ -4,25 +4,10 @@ #![no_main] #![no_std] -#[macro_use(exception)] extern crate cortex_m_rt as rt; extern crate panic_semihosting; -use rt::ExceptionFrame; - #[no_mangle] pub unsafe extern "C" fn main() -> ! { loop {} } - -// the hard fault handler -exception!(HardFault, hard_fault); - -fn hard_fault(_ef: &ExceptionFrame) -> ! { - loop {} -} - -// the default exception handler -exception!(*, default_handler); - -fn default_handler(_irqn: i16) {} diff --git a/cortex-m-rt/examples/minimal.rs b/cortex-m-rt/examples/minimal.rs index c12d12d..a036046 100644 --- a/cortex-m-rt/examples/minimal.rs +++ b/cortex-m-rt/examples/minimal.rs @@ -5,27 +5,13 @@ #![no_main] #![no_std] -#[macro_use(entry, exception)] +#[macro_use(entry)] extern crate cortex_m_rt as rt; extern crate panic_semihosting; -use rt::ExceptionFrame; - // the program entry point entry!(main); fn main() -> ! { loop {} } - -// the hard fault handler -exception!(HardFault, hard_fault); - -fn hard_fault(_ef: &ExceptionFrame) -> ! { - loop {} -} - -// the default exception handler -exception!(*, default_handler); - -fn default_handler(_irqn: i16) {} diff --git a/cortex-m-rt/examples/override-exception.rs b/cortex-m-rt/examples/override-exception.rs new file mode 100644 index 0000000..2f100a2 --- /dev/null +++ b/cortex-m-rt/examples/override-exception.rs @@ -0,0 +1,35 @@ +//! How to override the hard fault exception handler and the default exception handler + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +extern crate cortex_m; +#[macro_use(entry, exception)] +extern crate cortex_m_rt as rt; +extern crate panic_semihosting; + +use cortex_m::asm; +use rt::ExceptionFrame; + +// the program entry point +entry!(main); + +fn main() -> ! { + loop {} +} + +exception!(*, default_handler); + +fn default_handler(_irqn: i16) { + asm::bkpt(); +} + +exception!(HardFault, hard_fault); + +fn hard_fault(_ef: &ExceptionFrame) -> ! { + asm::bkpt(); + + loop {} +} diff --git a/cortex-m-rt/examples/state.rs b/cortex-m-rt/examples/state.rs index 0b5eeeb..dbacdaf 100644 --- a/cortex-m-rt/examples/state.rs +++ b/cortex-m-rt/examples/state.rs @@ -9,8 +9,6 @@ extern crate cortex_m_rt as rt; extern crate panic_semihosting; -use rt::ExceptionFrame; - // the program entry point entry!(main); @@ -24,15 +22,3 @@ exception!(SysTick, sys_tick, state: u32 = 0); fn sys_tick(state: &mut u32) { *state += 1; } - -// the hard fault handler -exception!(HardFault, hard_fault); - -fn hard_fault(_ef: &ExceptionFrame) -> ! { - loop {} -} - -// the default exception handler -exception!(*, default_handler); - -fn default_handler(_irqn: i16) {} |