Initial commit

This commit is contained in:
2019-08-17 21:31:59 +02:00
commit 91ef67ef37
10 changed files with 774 additions and 0 deletions

53
src/panic.rs Normal file
View 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();
}
}
}