Skip to content
39 changes: 12 additions & 27 deletions boards/apollo3/lora_things_plus/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of_mut;

use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;

/// Writer is used by kernel::debug to panic message to the serial port.
pub struct Writer {}

/// Global static for debug writer
pub static mut WRITER: Writer = Writer {};

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
let uart = apollo3::uart::Uart::new_uart_0(); // Aliases memory for uart0. Okay bc we are panicking.
uart.transmit_sync(buf);
buf.len()
}
}

/// Panic handler.
#[panic_handler]
pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
Expand All @@ -42,11 +18,20 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin26,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
debug::panic::<_, apollo3::uart::Uart, _, _>(
&mut [led],
writer,
apollo3::uart::UartPanicWriterConfig {
params: kernel::hil::uart::Parameters {
baud_rate: 115200,
stop_bits: kernel::hil::uart::StopBits::One,
parity: kernel::hil::uart::Parity::None,
hw_flow_control: false,
width: kernel::hil::uart::Width::Eight,
},
tx_pin_index: 48,
rx_pin_index: 49,
},
info,
&cortexm4::support::nop,
crate::PANIC_RESOURCES.get(),
Expand Down
39 changes: 12 additions & 27 deletions boards/apollo3/redboard_artemis_atp/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of_mut;

use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;

/// Writer is used by kernel::debug to panic message to the serial port.
pub struct Writer {}

/// Global static for debug writer
pub static mut WRITER: Writer = Writer {};

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
let uart = apollo3::uart::Uart::new_uart_0(); // Aliases memory for uart0. Okay bc we are panicking.
uart.transmit_sync(buf);
buf.len()
}
}

/// Panic handler.
#[panic_handler]
pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
Expand All @@ -42,11 +18,20 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin19,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
debug::panic::<_, apollo3::uart::Uart, _, _>(
&mut [led],
writer,
apollo3::uart::UartPanicWriterConfig {
params: kernel::hil::uart::Parameters {
baud_rate: 115200,
stop_bits: kernel::hil::uart::StopBits::One,
parity: kernel::hil::uart::Parity::None,
hw_flow_control: false,
width: kernel::hil::uart::Width::Eight,
},
tx_pin_index: 48,
rx_pin_index: 49,
},
info,
&cortexm4::support::nop,
crate::PANIC_RESOURCES.get(),
Expand Down
39 changes: 12 additions & 27 deletions boards/apollo3/redboard_artemis_nano/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of_mut;

use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;

/// Writer is used by kernel::debug to panic message to the serial port.
pub struct Writer {}

/// Global static for debug writer
pub static mut WRITER: Writer = Writer {};

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
let uart = apollo3::uart::Uart::new_uart_0(); // Aliases memory for uart0. Okay bc we are panicking.
uart.transmit_sync(buf);
buf.len()
}
}

/// Panic handler.
#[panic_handler]
pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
Expand All @@ -42,11 +18,20 @@ pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
apollo3::gpio::Pin::Pin19,
);
let led = &mut led::LedLow::new(led_pin);
let writer = &mut *addr_of_mut!(WRITER);

debug::panic(
debug::panic::<_, apollo3::uart::Uart, _, _>(
&mut [led],
writer,
apollo3::uart::UartPanicWriterConfig {
params: kernel::hil::uart::Parameters {
baud_rate: 115200,
stop_bits: kernel::hil::uart::StopBits::One,
parity: kernel::hil::uart::Parity::None,
hw_flow_control: false,
width: kernel::hil::uart::Width::Eight,
},
tx_pin_index: 48,
rx_pin_index: 49,
},
info,
&cortexm4::support::nop,
crate::PANIC_RESOURCES.get(),
Expand Down
36 changes: 13 additions & 23 deletions boards/arty_e21/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::fmt::Write;
use core::panic::PanicInfo;
use core::str;
use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::gpio;
use kernel::hil::led;

struct Writer {}

static mut WRITER: Writer = Writer {};

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
sifive::uart::Uart::new(arty_e21_chip::uart::UART0_BASE, 32_000_000).transmit_sync(buf);
buf.len()
}
}

/// Panic handler.
#[cfg(not(test))]
#[panic_handler]
Expand Down Expand Up @@ -59,10 +39,20 @@ pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
);

let led_red = &mut led::LedHigh::new(led_red_pin);
let writer = &mut *core::ptr::addr_of_mut!(WRITER);
debug::panic(

debug::panic::<_, sifive::uart::Uart, _, _>(
&mut [led_red],
writer,
sifive::uart::UartPanicWriterConfig {
registers: arty_e21_chip::uart::UART0_BASE,
clock_frequency: 32_000_000,
params: kernel::hil::uart::Parameters {
baud_rate: 115200,
stop_bits: kernel::hil::uart::StopBits::One,
parity: kernel::hil::uart::Parity::None,
hw_flow_control: false,
width: kernel::hil::uart::Width::Eight,
},
},
pi,
&rv32i::support::nop,
crate::PANIC_RESOURCES.get(),
Expand Down
8 changes: 4 additions & 4 deletions boards/nordic/nrf52_components/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ impl Component for UartChannelComponent {
UartChannel::Pins(uart_pins) => {
unsafe {
self.uarte0.initialize(
nrf52::pinmux::Pinmux::new(uart_pins.txd as u32),
nrf52::pinmux::Pinmux::new(uart_pins.rxd as u32),
uart_pins.cts.map(|x| nrf52::pinmux::Pinmux::new(x as u32)),
uart_pins.rts.map(|x| nrf52::pinmux::Pinmux::new(x as u32)),
nrf52::pinmux::Pinmux::new(uart_pins.txd),
nrf52::pinmux::Pinmux::new(uart_pins.rxd),
uart_pins.cts.map(|x| nrf52::pinmux::Pinmux::new(x)),
uart_pins.rts.map(|x| nrf52::pinmux::Pinmux::new(x)),
)
};
self.uarte0
Expand Down
64 changes: 16 additions & 48 deletions boards/nordic/nrf52dk/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,35 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::fmt::Write;
use core::panic::PanicInfo;
use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;
use kernel::hil::uart::{self, Configure};
use kernel::hil::uart;
use nrf52832::gpio::Pin;
use nrf52832::uart::{Uarte, UARTE0_BASE};

struct Writer {
initialized: bool,
}

static mut WRITER: Writer = Writer { initialized: false };

impl Write for Writer {
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
self.write(s.as_bytes());
Ok(())
}
}

impl IoWrite for Writer {
fn write(&mut self, buf: &[u8]) -> usize {
// Here, we create a second instance of the Uarte struct.
// This is okay because we only call this during a panic, and
// we will never actually process the interrupts
let uart = Uarte::new(UARTE0_BASE);
if !self.initialized {
self.initialized = true;
let _ = uart.configure(uart::Parameters {
baud_rate: 115200,
stop_bits: uart::StopBits::One,
parity: uart::Parity::None,
hw_flow_control: false,
width: uart::Width::Eight,
});
}
for &c in buf {
unsafe {
uart.send_byte(c);
}
while !uart.tx_ready() {}
}
buf.len()
}
}

#[cfg(not(test))]
#[panic_handler]
/// Panic handler
pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
// The nRF52 DK LEDs (see back of board)

use core::ptr::addr_of_mut;
let led_kernel_pin = &nrf52832::gpio::GPIOPin::new(Pin::P0_17);
let led = &mut led::LedLow::new(led_kernel_pin);
let writer = &mut *addr_of_mut!(WRITER);
debug::panic(

debug::panic::<_, nrf52832::uart::Uarte, _, _>(
&mut [led],
writer,
nrf52832::uart::UartPanicWriterConfig {
params: uart::Parameters {
baud_rate: 115200,
stop_bits: uart::StopBits::One,
parity: uart::Parity::None,
hw_flow_control: false,
width: uart::Width::Eight,
},
txd: crate::UART_TXD,
rxd: crate::UART_RXD,
cts: crate::UART_CTS,
rts: crate::UART_CTS,
},
pi,
&cortexm4::support::nop,
crate::PANIC_RESOURCES.get(),
Expand Down
Loading
Loading