msp_exp432p401r/
io.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::ptr::addr_of_mut;
8use kernel::debug;
9use kernel::debug::IoWrite;
10use kernel::hil::led;
11use msp432::gpio::IntPinNr;
12use msp432::wdt::Wdt;
13
14/// Uart is used by kernel::debug to panic message to the serial port.
15pub struct Uart {}
16
17/// Global static for debug writer
18pub static mut UART: Uart = Uart {};
19
20impl Write for Uart {
21    fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
22        self.write(s.as_bytes());
23        Ok(())
24    }
25}
26
27impl IoWrite for Uart {
28    fn write(&mut self, buf: &[u8]) -> usize {
29        let uart0 = msp432::uart::Uart::new(msp432::usci::USCI_A0_BASE, 0, 1, 1, 1);
30        uart0.transmit_sync(buf);
31        buf.len()
32    }
33}
34
35/// Panic handler
36#[panic_handler]
37pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
38    const LED1_PIN: IntPinNr = IntPinNr::P01_0;
39    let gpio_pin = msp432::gpio::IntPin::new(LED1_PIN);
40    let led = &mut led::LedHigh::new(&gpio_pin);
41    let writer = &mut *addr_of_mut!(UART);
42    let wdt = Wdt::new();
43
44    wdt.disable();
45    debug::panic(
46        &mut [led],
47        writer,
48        info,
49        &cortexm4::support::nop,
50        crate::PANIC_RESOURCES.get(),
51    )
52}