1use core::fmt::{self, Write};
6
7use kernel::debug::{self, IoWrite};
8use kernel::hil::{
9 led,
10 uart::{self, Configure},
11};
12
13use crate::imxrt1060::gpio;
14use crate::imxrt1060::lpuart;
15
16struct Writer<'a> {
17 output: &'a mut lpuart::Lpuart<'a>,
18}
19
20const BAUD_RATE: u32 = 115_200;
21
22impl<'a> Writer<'a> {
23 pub unsafe fn new(output: &'a mut lpuart::Lpuart<'a>) -> Self {
24 let _ = output.configure(uart::Parameters {
25 baud_rate: BAUD_RATE,
26 stop_bits: uart::StopBits::One,
27 parity: uart::Parity::None,
28 hw_flow_control: false,
29 width: uart::Width::Eight,
30 });
31
32 Writer { output }
33 }
34}
35
36impl IoWrite for Writer<'_> {
37 fn write(&mut self, bytes: &[u8]) -> usize {
38 for byte in bytes {
39 self.output.send_byte(*byte);
40 }
41 bytes.len()
42 }
43}
44
45impl Write for Writer<'_> {
46 fn write_str(&mut self, s: &str) -> fmt::Result {
47 self.write(s.as_bytes());
48 Ok(())
49 }
50}
51
52#[panic_handler]
53unsafe fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
54 let ccm = crate::imxrt1060::ccm::Ccm::new();
55 let pin = crate::imxrt1060::gpio::Pin::from_pin_id(gpio::PinId::B0_03);
56 let led = &mut led::LedHigh::new(&pin);
57 let mut lpuart2 = lpuart::Lpuart::new_lpuart2(&ccm);
58 let mut writer = Writer::new(&mut lpuart2);
59 debug::panic(
60 &mut [led],
61 &mut writer,
62 panic_info,
63 &cortexm7::support::nop,
64 crate::PANIC_RESOURCES.get(),
65 )
66}