From 6afea5e58e47b345adaa0f556184f75599503521 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 8 Aug 2022 14:48:55 -0400 Subject: log in panics if possible. --- src/main.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7fd2ba3..707feed 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,10 @@ use gd32vf103xx_hal::{ time::Hertz, timer::Timer, }; -use riscv::asm::wfi; +use riscv::{ + asm::wfi, + interrupt, +}; use riscv_rt::entry; use led::LED; @@ -71,28 +74,34 @@ fn main(_hartid: usize) -> ! { #[export_name="ExceptionHandler"] fn exception_handler(_frame: &riscv_rt::TrapFrame) -> ! { - loop { unsafe { wfi() } }; + spin(); } #[export_name="DefaultHandler"] fn default_handler() -> ! { - loop { unsafe { wfi() } }; + spin(); } #[export_name="MachineTimer"] fn machine_timer() { - loop { unsafe { wfi() } }; + spin(); } #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { - if let Some(loc) = info.location() { - let _file = loc.file(); - let _line = loc.line(); - if let Some(_msg) = info.payload().downcast_ref::<&str>() { - loop {} + interrupt::free(|_cs| { + log!("!!! panic "); + if let Some(loc) = info.location() { + log!("in {}:{} ", loc.file(), loc.line()); } - loop {} - } - loop {} + if let Some(msg) = info.payload().downcast_ref::<&str>() { + log!("⇒ {} ", msg); + } + logln!("!!!"); + }); + spin(); +} + +fn spin() -> ! { + loop { unsafe { wfi() } }; } -- cgit v1.2.3