From 7d64ea99fdbb04f93f23abbc9d0470e77ce9e1b5 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 12 Aug 2019 12:13:21 -0400 Subject: Add HardFault handler. --- ble/src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'ble') diff --git a/ble/src/main.rs b/ble/src/main.rs index 6f167a5..0fed859 100644 --- a/ble/src/main.rs +++ b/ble/src/main.rs @@ -10,7 +10,7 @@ mod rtc; use clint::HandlerArray; use core::mem; use cortex_m::asm::wfi; -use cortex_m_rt::entry; +use cortex_m_rt::{entry, exception, ExceptionFrame}; use log::{info, trace, LevelFilter}; #[allow(unused_imports)] @@ -47,12 +47,12 @@ fn main() -> ! { let mut nvic = nrf52.NVIC; let mut rtc_handler = rtc::setup(Rtc::new(nrf52.RTC0), Clocks::new(nrf52.CLOCK)); - logln_now!("logln_now?"); HANDLERS.with_overrides(|hs| { hs.register(0, &mut rtc_handler); nvic.enable(Interrupt::RTC0); info!("Bootstrap complete."); + let mut last_tick = rtc::millis(); last_tick -= last_tick % 1024; loop { @@ -68,7 +68,17 @@ fn main() -> ! { unreachable!(); } -// TODO: RTC0/1/2 exist. See which is best, if it matters. +#[exception] +fn HardFault(ef: &ExceptionFrame) -> ! { + log::logger().flush(); + logln_now!("!!! Hard Fault - ef: {:?} !!!", ef); + logln_now!("flushing log"); + loop { + log::logger().flush(); + wfi() + } +} + #[interrupt] fn RTC0() { HANDLERS.call(0); -- cgit v1.2.3