#uart #serial

uart_16550

Minimal support for uart_16550 serial output

20 releases

0.2.18 Apr 16, 2022
0.2.17 Mar 28, 2022
0.2.16 Jan 8, 2022
0.2.15 Jun 6, 2021
0.1.0 May 21, 2018

#36 in Hardware support

Download history 3024/week @ 2022-01-29 2214/week @ 2022-02-05 2192/week @ 2022-02-12 2007/week @ 2022-02-19 2185/week @ 2022-02-26 2131/week @ 2022-03-05 2328/week @ 2022-03-12 2047/week @ 2022-03-19 2466/week @ 2022-03-26 2345/week @ 2022-04-02 2542/week @ 2022-04-09 2343/week @ 2022-04-16 2013/week @ 2022-04-23 1805/week @ 2022-04-30 2069/week @ 2022-05-07 2366/week @ 2022-05-14

8,614 downloads per month
Used in less than 10 crates

MIT license

14KB
188 lines

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 port-mapped 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:

use uart_16550::SerialPort;

const SERIAL_IO_PORT: u16 = 0x3F8;

let mut serial_port = unsafe { SerialPort::new(SERIAL_IO_PORT) };
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();

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:

use uart_16550::MmioSerialPort;

const SERIAL_PORT_BASE_ADDRESS: usize = 0x1000_0000;

let mut serial_port = unsafe { MmioSerialPort::new(SERIAL_PORT_BASE_ADDRESS) };
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).

Dependencies

~125KB