Expand description

Experimental device-side USB stack for embedded devices.

Implementing a USB device

A USB device consists of a UsbDevice instance, one or more UsbClasses, and a platform-specific UsbBus implementation which together form a USB composite device.

In the future USB device implementors will be able to use pre-existing peripheral driver crates and USB class implementation crates. The necessary types for the basic USB composite device implementation are available with:

use usb_device::prelude::*.

See the device module for a more complete example.

USB classes

For information on how to implement new USB classes, see the class module and the TestClass source code for an example of a custom USB device class implementation. The necessary types for creating new classes are available with:

use usb_device::class_prelude::*.

USB peripheral drivers

New peripheral driver crates can be created by implementing the UsbBus trait.

Note about terminology

This crate uses standard host-centric USB terminology for transfer directions. Therefore an OUT transfer refers to a host-to-device transfer, and an IN transfer refers to a device-to-host transfer. This is mainly a concern for implementing new USB peripheral drivers and USB classes, and people doing that should be familiar with the USB standard.


For implementing peripheral drivers.

For implementing standard as well as vendor-specific USB classes.

Prelude for class implementors.

USB control transfers and the SETUP packet.

Creating USB descriptors

USB composite device.

USB endpoints.

Prelude for device implementors.

Test USB class for testing USB driver implementations. Peripheral driver implementations should include an example called “test_class” that creates a device with this class to enable the driver to be tested with the test_class_host example in this crate.


Direction of USB traffic. Note that in the USB standard the direction is always indicated from the perspective of the host, which is backward for devices, but the standard directions are used for consistency.

A USB stack error.

Type Definitions

Result for USB operations.