custom panic to preserve type checking
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -32,7 +32,6 @@ dependencies = [
|
||||
"arduino-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"nb 1.1.0",
|
||||
"panic-serial",
|
||||
"proc-macro2",
|
||||
"ufmt",
|
||||
]
|
||||
@@ -141,15 +140,6 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||
|
||||
[[package]]
|
||||
name = "panic-serial"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3afc60d58b0825ea32dd8d8a2796098f7b87ad3b9392cace3b6dc79e450afd9"
|
||||
dependencies = [
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
|
||||
@@ -14,7 +14,6 @@ bench = false
|
||||
ufmt = "0.2.0"
|
||||
nb = "1.1.0"
|
||||
embedded-hal = "1.0"
|
||||
panic-serial = { version = "0.1.2", features = ["full"] }
|
||||
|
||||
[dependencies.arduino-hal]
|
||||
git = "https://github.com/rahix/avr-hal"
|
||||
|
||||
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