CrabUSB
A USB Host driver implementation written in Rust for embedded systems.
Overview
CrabUSB is a no_std USB Host driver library that provides async support for USB device communication. It currently supports xHCI (Extensible Host Controller Interface) and is designed for embedded systems and operating system kernels.
Features
- Async/Await Support: Built with async primitives for non-blocking USB operations
- xHCI Controller Support: Full implementation of xHCI specification
- USB Device Management: Device enumeration, configuration, and interface claiming
- Standard USB Descriptors: Complete parsing of device, configuration, interface, and endpoint descriptors
- Multiple Transfer Types: Support for Control, Bulk, Interrupt, and Isochronous transfers
- Embedded-Friendly:
no_stdcompatible with minimal memory footprint - Flexible Integration: Works with any async executor or can be used synchronously
Architecture
The driver uses a lock-free design based on TRB (Transfer Request Block) rings, where each TRB represents an async task. The future queries the ring to get async results without requiring a specific executor.
Usage
Basic Setup
-
setup dma-api
-
implement the
Kerneltrait for your systemuse *; // Implement the Kernel trait for your system ; // Set the kernel implementation set_impl!; // Initialize USB host controller let mut host = new; host.init.await?;
Device Communication
// Probe for connected devices
let devices = host.probe.await?;
for mut device in devices
Testing
QEMU Testing
Real Hardware (U-Boot)
Supported USB Features
- USB 1.1/2.0/3.x: Full speed, High speed, and SuperSpeed devices
- Device Classes: HID, Mass Storage, Video (UVC), Audio, etc.
- Transfer Types:
- Control transfers for device setup and configuration
- Bulk transfers for large data transfers
- Interrupt transfers for periodic data
- Isochronous transfers for real-time data (audio/video)
Platform Requirements
- Architecture: Currently tested on AArch64
- Memory: DMA-capable memory regions
- Interrupts: Interrupt handling capability for xHCI events
- Timer: For timeout and delay operations
Contributing
Contributions are welcome! Please ensure that:
- Code follows Rust conventions and passes
cargo clippy - All tests pass on both QEMU and real hardware
- Documentation is updated for new features
- Commit messages are descriptive
License
This project is licensed under the MIT License - see the LICENSE file for details.