7 releases (2 stable)
Uses new Rust 2024
| new 1.0.1 | Apr 12, 2026 |
|---|---|
| 1.0.0 | Apr 7, 2026 |
| 0.5.0 | Mar 10, 2025 |
| 0.4.0 | Mar 11, 2024 |
| 0.1.0 | Aug 29, 2021 |
#277 in Embedded development
1,129 downloads per month
Used in 4 crates
(2 directly)
17KB
177 lines
NS16550A UART Driver
A no_std Rust driver for the NS16550A UART peripheral, designed for embedded systems.
Features
- No_std compatible: Works in embedded environments without standard library
- FIFO support: Utilizes NS16550A's 16-byte transmit/receive FIFOs
- Comprehensive configuration: Full control over baud rate, word length, parity, stop bits
- Easy integration: Simple API with
core::fmt::Writesupport - Memory-mapped I/O: Direct hardware register access for maximum performance
Basic Usage
use ns16550a::*;
use core::fmt::Write;
fn main() {
// Create UART instance at memory-mapped address
let mut uart = Uart::new(0x1000_0000);
// Configure UART with common settings
let config = UartConfig {
word_length: WordLength::EIGHT, // 8 data bits
stop_bits: StopBits::ONE, // 1 stop bit
parity_bit: ParityBit::DISABLE, // No parity
parity_select: ParitySelect::EVEN, // Even parity (if enabled)
stick_parity: StickParity::DISABLE, // No stick parity
break_: Break::DISABLE, // No break signal
dma_mode: DMAMode::MODE0, // DMA mode 0
};
// Initialize with 1200 baud rate
uart.init(config, Divisor::BAUD1200);
// Write using fmt::Write trait
writeln!(&mut uart, "Hello, world!").unwrap();
// Simple echo loop
loop {
if let Some(byte) = uart.get() {
while uart.put(byte).is_none() {}
}
}
}
For a complete working example that runs with QEMU, see the example directory.
License
This project is licensed under the MIT License.