custom panic to preserve type checking
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -3,13 +3,38 @@
|
||||
|
||||
use arduino_hal::prelude::*;
|
||||
|
||||
panic_serial::impl_panic_handler!(
|
||||
arduino_hal::usart::Usart<
|
||||
arduino_hal::pac::USART0,
|
||||
arduino_hal::port::Pin<arduino_hal::port::mode::Input, arduino_hal::hal::port::PD0>,
|
||||
arduino_hal::port::Pin<arduino_hal::port::mode::Output, arduino_hal::hal::port::PD1>
|
||||
>
|
||||
);
|
||||
// NOTE: 115200 @ 16MHz is 3.5% off, try 9600 or 1M if it causes issues (https://wormfood.net/avrbaudcalc.php)
|
||||
const SERIAL_BAUD: u32 = 115200;
|
||||
|
||||
#[cfg(not(doc))]
|
||||
#[panic_handler]
|
||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||
// disable interrupts - firmware has panicked so no ISRs should continue running
|
||||
// avr_device::interrupt::disable();
|
||||
|
||||
// SAFETY: Main code aborted.
|
||||
let dp = unsafe { arduino_hal::Peripherals::steal() };
|
||||
let pins = arduino_hal::pins!(dp);
|
||||
let mut serial = arduino_hal::default_serial!(dp, pins, SERIAL_BAUD);
|
||||
|
||||
ufmt::uwriteln!(&mut serial, "Firmware panic!\r").unwrap_infallible();
|
||||
if let Some(loc) = info.location() {
|
||||
ufmt::uwriteln!(
|
||||
&mut serial,
|
||||
" At {}:{}:{}\r",
|
||||
loc.file(),
|
||||
loc.line(),
|
||||
loc.column(),
|
||||
)
|
||||
.unwrap_infallible();
|
||||
}
|
||||
|
||||
let mut led = pins.d13.into_output();
|
||||
loop {
|
||||
led.toggle();
|
||||
arduino_hal::delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
#[arduino_hal::entry]
|
||||
fn main() -> ! {
|
||||
@@ -17,9 +42,7 @@ fn main() -> ! {
|
||||
let pins = arduino_hal::pins!(dp);
|
||||
|
||||
let mut led = pins.d13.into_output();
|
||||
// NOTE: 115200 @ 16MHz is 3.5% off, try 9600 or 1M if it causes issues (https://wormfood.net/avrbaudcalc.php)
|
||||
let serial = arduino_hal::default_serial!(dp, pins, 115200);
|
||||
let mut serial = share_serial_port_with_panic(serial);
|
||||
let mut serial = arduino_hal::default_serial!(dp, pins, SERIAL_BAUD);
|
||||
|
||||
ufmt::uwriteln!(&mut serial, "Hello from Arduino!").unwrap_infallible();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user