24 releases

0.3.2 Nov 13, 2024
0.3.1 Jul 11, 2024
0.3.0 Aug 4, 2023
0.2.19 Jul 7, 2023
0.1.0 May 21, 2018

#18 in Hardware support

Download history 6884/week @ 2024-09-20 6314/week @ 2024-09-27 4862/week @ 2024-10-04 5982/week @ 2024-10-11 6337/week @ 2024-10-18 6999/week @ 2024-10-25 5954/week @ 2024-11-01 5696/week @ 2024-11-08 5538/week @ 2024-11-15 6296/week @ 2024-11-22 6304/week @ 2024-11-29 7207/week @ 2024-12-06 9017/week @ 2024-12-13 5455/week @ 2024-12-20 4287/week @ 2024-12-27 4444/week @ 2025-01-03

24,789 downloads per month
Used in 24 crates (19 directly)

MIT license

18KB
234 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 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:

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

~2.5MB
~20K SLoC