diff --git a/examples/teensy4_blinky/Cargo.lock b/examples/teensy4_blinky/Cargo.lock index 8253a71bbd..daec54f7e5 100644 --- a/examples/teensy4_blinky/Cargo.lock +++ b/examples/teensy4_blinky/Cargo.lock @@ -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", ] diff --git a/examples/teensy4_blinky/Cargo.toml b/examples/teensy4_blinky/Cargo.toml index 800ad58b7f..a81a155acd 100644 --- a/examples/teensy4_blinky/Cargo.toml +++ b/examples/teensy4_blinky/Cargo.toml @@ -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]] diff --git a/examples/teensy4_blinky/examples/common/mod.rs b/examples/teensy4_blinky/examples/common/mod.rs deleted file mode 100644 index 9851feab1c..0000000000 --- a/examples/teensy4_blinky/examples/common/mod.rs +++ /dev/null @@ -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 { - uart: ::teensy4_bsp::hal::lpuart::Lpuart, - } - impl ::core::fmt::Write for UartWriter { - 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; diff --git a/examples/teensy4_blinky/examples/with_logs.rs b/examples/teensy4_blinky/examples/with_logs.rs index dd4fef0b7d..cdf0315e4d 100644 --- a/examples/teensy4_blinky/examples/with_logs.rs +++ b/examples/teensy4_blinky/examples/with_logs.rs @@ -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;