`usb-device` logo

`usb-device`

Free

Abstraction layer between USB peripheral crates & USB class crates - [![crates.io](https://img.shields.io/crates/v/usb-device.svg)](https://crates.io/crates/usb-device)

FreeFree tier
Type
Open Source

About `usb-device`

A Rust library for building USB device firmware on microcontrollers. It provides an abstraction layer between hardware-specific USB peripheral drivers (UsbBus) and USB class implementations (UsbClass), allowing developers to implement composite USB devices. Supports a wide range of microcontrollers including ATSAM, i.MX RT, RP2040, STM32, and MUSP-based chips, along with standard USB classes such as HID, CDC-ACM serial, mass storage, DFU, MIDI, and audio. This is an experimental, community-maintained project under the rust-embedded-community organization, licensed under MIT.

Key Features

Composite USB device support via UsbDevice object
UsbBus trait for hardware-specific USB peripheral drivers
UsbClass trait for implementing USB classes (HID, serial, mass storage, DFU, MIDI, audio, etc.)
Supports multiple MCU families: ATSAM4, ATSAMD, i.MX RT, RP2040, STM32, MUSP-based chips
Provides a set of class crates: usbd-hid, usbd-serial, usbd-storage, usbd-dfu, usbd-midi, usbd-audio, etc.
Hardware driver crates available for popular ARM Cortex-M and RISC-V microcontrollers
MIT licensed and community-maintained

Pros & Cons

Pros
  • Provides a clean abstraction between hardware and class logic
  • Supports a broad range of popular microcontrollers
  • Composable design allows multiple USB classes in a single device
  • Community-maintained with active development
  • MIT license enables use in both open and closed source projects
Cons
  • Experimental status; not recommended for production without thorough testing
  • Lacks async support compared to alternatives like embassy-usb
  • Only covers device-side USB (no host mode support)
  • Documentation is limited to the README and crate examples

Best For

Implementing custom USB HID devices (keyboards, mice, game controllers)Building CDC-ACM virtual serial ports for embedded systemsCreating USB mass storage devices (experimental)Device firmware upgrade (DFU) over USBUSB MIDI controllers for musical instrumentsUSB audio devices (experimental)

FAQ

What microcontrollers are supported?
The library provides hardware driver crates for ATSAM4, ATSAMD, NXP i.MX RT, Raspberry Pi RP2040, STM32, and MUSP-based chips from vendors like TI, MediaTek, and Allwinner.
What USB classes are available?
Class crates include usbd-hid (HID), usbd-serial (CDC-ACM serial port), usbd-storage (mass storage, experimental), usbd-dfu (device firmware upgrade), usbd-midi (MIDI), and usbd-audio (audio, experimental).
Is there an alternative to this library?
Yes, the Embassy project provides an async USB stack called embassy-usb.