#uart

no-std ns16550a

A no_std Rust driver for the NS16550A UART peripheral, designed for embedded systems

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

Download history 55/week @ 2025-12-28 27/week @ 2026-01-04 56/week @ 2026-01-11 64/week @ 2026-01-18 74/week @ 2026-01-25 114/week @ 2026-02-01 142/week @ 2026-02-08 78/week @ 2026-02-15 129/week @ 2026-02-22 184/week @ 2026-03-01 344/week @ 2026-03-08 436/week @ 2026-03-15 294/week @ 2026-03-22 366/week @ 2026-03-29 203/week @ 2026-04-05 259/week @ 2026-04-12

1,129 downloads per month
Used in 4 crates (2 directly)

MIT license

17KB
177 lines

NS16550A UART Driver

crates.io doc CI github

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::Write support
  • 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.

No runtime deps