uart_16550

Build Status Docs.rs Badge

Minimal support for serial communication through UART devices, which are compatible to the 16550 UART. This crate supports I/O port-mapped (x86 only) and memory-mapped UARTS.

Usage

Depending on the system architecture, the UART can be either accessed through port-mapped I/O or memory-mapped I/O.

With port-mappd I/O

The UART is accessed through port-mapped I/O on architectures such as x86_64. On these architectures, the SerialPort type can be used:

```rust use uart_16550::SerialPort;

const SERIALIOPORT: u16 = 0x3F8;

let mut serialport = unsafe { SerialPort::new(SERIALIOPORT) }; serialport.init();

// Now the serial port is ready to be used. To send a byte: serial_port.send(42);

// To receive a byte: let data = serial_port.receive(); ```

With memory mapped serial port

Most other architectures, such as RISC-V, use memory-mapped I/O for accessing the UARTs. On these architectures, the MmioSerialPort type can be used:

```rust use uart_16550::MmioSerialPort;

const SERIALPORTBASEADDRESS: usize = 0x10000000;

let mut serialport = unsafe { MmioSerialPort::new(SERIALPORTBASEADDRESS) }; serial_port.init();

// Now the serial port is ready to be used. To send a byte: serial_port.send(42);

// To receive a byte: let data = serial_port.receive(); ```

Building with stable rust

This needs to have the compile-time requirements of the cc crate installed on your system. It was currently only tested on Linux and MacOS.

License

Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).