mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Use imxrt-uart-panic crate instead of custom panic handler
This commit is contained in:
parent
2fd3b3c404
commit
b5f9579b90
4 changed files with 17 additions and 45 deletions
15
examples/teensy4_blinky/Cargo.lock
generated
15
examples/teensy4_blinky/Cargo.lock
generated
|
@ -194,6 +194,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"embedded-hal 0.2.7",
|
||||
"imxrt-log",
|
||||
"imxrt-uart-panic",
|
||||
"log",
|
||||
"nb 1.1.0",
|
||||
"rtic",
|
||||
|
@ -278,6 +279,19 @@ dependencies = [
|
|||
"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]]
|
||||
name = "imxrt-usbd"
|
||||
version = "0.2.2"
|
||||
|
@ -434,7 +448,6 @@ dependencies = [
|
|||
"embedded-hal 1.0.0-rc.1",
|
||||
"fugit",
|
||||
"imxrt-ral",
|
||||
"log",
|
||||
"rtic-time",
|
||||
]
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ imxrt-log = { version = "0.1.1", default-features = false, features = [
|
|||
"lpuart",
|
||||
] }
|
||||
log = "0.4.20"
|
||||
imxrt-uart-panic = "0.1.1"
|
||||
|
||||
# this lets you use `cargo fix`!
|
||||
[[bin]]
|
||||
|
|
|
@ -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;
|
|
@ -3,8 +3,8 @@
|
|||
#![no_std]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
mod common;
|
||||
common::uart_panic_handler!(lpuart6, p1, p0, 115200);
|
||||
use bsp::pins::common::{P0, P1};
|
||||
imxrt_uart_panic::register!(LPUART6, P1, P0, 115200, teensy4_panic::sos);
|
||||
|
||||
use teensy4_bsp as bsp;
|
||||
|
||||
|
|
Loading…
Reference in a new issue