53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use core::fmt::Write;
|
|
use core::panic::PanicInfo;
|
|
use hal::{
|
|
clock::GenericClockController,
|
|
gpio::{Pa10, Pa11, PfC},
|
|
pac::Peripherals,
|
|
prelude::*,
|
|
sercom::{PadPin, Sercom0Pad2, Sercom0Pad3, UART0},
|
|
time,
|
|
};
|
|
|
|
#[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 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 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();
|
|
}
|
|
}
|
|
}
|