#uart #serial

uart_16550

Minimal support for uart_16550 serial output

17 releases

0.2.15 Jun 6, 2021
0.2.13 Apr 30, 2021
0.2.12 Feb 2, 2021
0.2.10 Oct 1, 2020
0.1.0 May 21, 2018

#9 in Hardware support

Download history 3294/week @ 2021-08-09 1855/week @ 2021-08-16 2628/week @ 2021-08-23 2543/week @ 2021-08-30 2392/week @ 2021-09-06 2534/week @ 2021-09-13 1594/week @ 2021-09-20 1486/week @ 2021-09-27 1446/week @ 2021-10-04 1475/week @ 2021-10-11 1433/week @ 2021-10-18 1424/week @ 2021-10-25 1676/week @ 2021-11-01 1510/week @ 2021-11-08 1197/week @ 2021-11-15 1353/week @ 2021-11-22

5,982 downloads per month
Used in less than 10 crates

MIT license

15KB
197 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();

Crate Feature Flags

  • nightly: This is the default.
  • stable: Use this to build with non-nightly rust. Needs default-features = false.

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

~120KB