Initial commit
This commit is contained in:
53
src/panic.rs
Normal file
53
src/panic.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use core::fmt::Write;
|
||||
use core::panic::PanicInfo;
|
||||
use hal::{
|
||||
clock::GenericClockController,
|
||||
gpio::{Pa10, Pa11, PfC},
|
||||
prelude::*,
|
||||
sercom::{PadPin, Sercom0Pad2, Sercom0Pad3, UART0},
|
||||
time, CorePeripherals, Peripherals,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
let mut peripherals = unsafe { Peripherals::steal() };
|
||||
let mut pins = hal::Pins::new(peripherals.PORT);
|
||||
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
|
||||
red_led.set_high().ok();
|
||||
|
||||
let mut core = unsafe { CorePeripherals::steal() };
|
||||
let mut clocks = GenericClockController::with_internal_32kosc(
|
||||
peripherals.GCLK,
|
||||
&mut peripherals.PM,
|
||||
&mut peripherals.SYSCTRL,
|
||||
&mut peripherals.NVMCTRL,
|
||||
);
|
||||
let glck0 = clocks.gclk0();
|
||||
|
||||
let mut uart: UART0<Sercom0Pad3<Pa11<PfC>>, Sercom0Pad2<Pa10<PfC>>, (), ()> = UART0::new(
|
||||
&clocks.sercom0_core(&glck0).unwrap(),
|
||||
time::Hertz(115200),
|
||||
peripherals.SERCOM0,
|
||||
&mut core.NVIC,
|
||||
&mut peripherals.PM,
|
||||
(
|
||||
pins.d0.into_pad(&mut pins.port),
|
||||
pins.d1.into_pad(&mut pins.port),
|
||||
),
|
||||
);
|
||||
|
||||
loop {
|
||||
uart.write_str("## PANIC ##\r\n").ok();
|
||||
if let Some(location) = info.location() {
|
||||
writeln!(
|
||||
uart,
|
||||
"Panic occured in file {}\r\nAt location {}\r\n",
|
||||
location.file(),
|
||||
location.line(),
|
||||
)
|
||||
.ok();
|
||||
} else {
|
||||
uart.write_str("No location info available...\r\n").ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user