Use imxrt-uart-panic crate instead of custom panic handler

This commit is contained in:
Finomnis 2023-11-04 00:04:19 +01:00 committed by Emil Fresk
parent 2fd3b3c404
commit b5f9579b90
4 changed files with 17 additions and 45 deletions

View file

@ -194,6 +194,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"embedded-hal 0.2.7", "embedded-hal 0.2.7",
"imxrt-log", "imxrt-log",
"imxrt-uart-panic",
"log", "log",
"nb 1.1.0", "nb 1.1.0",
"rtic", "rtic",
@ -278,6 +279,19 @@ dependencies = [
"cortex-m-rt", "cortex-m-rt",
] ]
[[package]]
name = "imxrt-uart-panic"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbec2a318caf77dd2299f23982a2cc3435af8cc0b99787eaba3dbff711efc1d3"
dependencies = [
"cortex-m",
"embedded-hal 0.2.7",
"imxrt-hal",
"imxrt-ral",
"nb 1.1.0",
]
[[package]] [[package]]
name = "imxrt-usbd" name = "imxrt-usbd"
version = "0.2.2" version = "0.2.2"
@ -434,7 +448,6 @@ dependencies = [
"embedded-hal 1.0.0-rc.1", "embedded-hal 1.0.0-rc.1",
"fugit", "fugit",
"imxrt-ral", "imxrt-ral",
"log",
"rtic-time", "rtic-time",
] ]

View file

@ -32,6 +32,7 @@ imxrt-log = { version = "0.1.1", default-features = false, features = [
"lpuart", "lpuart",
] } ] }
log = "0.4.20" log = "0.4.20"
imxrt-uart-panic = "0.1.1"
# this lets you use `cargo fix`! # this lets you use `cargo fix`!
[[bin]] [[bin]]

View file

@ -1,42 +0,0 @@
macro_rules! uart_panic_handler {
($uart: ident, $tx_pin: ident, $rx_pin: ident, $baud: expr) => {
#[panic_handler]
fn panic(info: &::core::panic::PanicInfo) -> ! {
use ::core::fmt::Write as _;
use ::embedded_hal::serial::Write as _;
let ::teensy4_bsp::board::Resources {
$uart: uart, pins, ..
} = ::teensy4_bsp::board::t40(unsafe { ::teensy4_bsp::ral::Instances::instances() });
let uart = ::teensy4_bsp::board::lpuart(uart, pins.$tx_pin, pins.$rx_pin, $baud);
struct UartWriter<P, const N: u8> {
uart: ::teensy4_bsp::hal::lpuart::Lpuart<P, N>,
}
impl<P, const N: u8> ::core::fmt::Write for UartWriter<P, N> {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
for &b in s.as_bytes() {
if b == b'\n' {
let _ = ::nb::block!(self.uart.write(b'\r'));
}
let _ = ::nb::block!(self.uart.write(b));
}
Ok(())
}
}
let mut uart = UartWriter { uart };
::core::writeln!(uart).ok();
::core::writeln!(uart, "{}", info).ok();
::core::writeln!(uart).ok();
let _ = ::nb::block!(uart.uart.flush());
::teensy4_panic::sos()
}
};
}
pub(crate) use uart_panic_handler;

View file

@ -3,8 +3,8 @@
#![no_std] #![no_std]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
mod common; use bsp::pins::common::{P0, P1};
common::uart_panic_handler!(lpuart6, p1, p0, 115200); imxrt_uart_panic::register!(LPUART6, P1, P0, 115200, teensy4_panic::sos);
use teensy4_bsp as bsp; use teensy4_bsp as bsp;