USB system bus
Created 2022-12-26 Updated 2025-03-07
A USB device may be a single class type, or it may be composed of multiple classes. Classes may be of a standard type (e.g. for HID, Audio, or Telephony), or you may roll-your-own type. Classes which are of a standard type should conform to the same interface specification, so that drivers can be shared across different vendor products.
TinyUSB - stm32f401
cd tinyub/examples/device/cdc_msc/src make BOARD=stm32f401blackpill get-deps # once only make BOARD=stm32f401blackpill all
Flash the bin file under the _build directory
The example provides a small drive and a serial port
Transfer types
The transfer types are:
- Control transfers - used for configuration
- Isochronous transfers - for continuous data like audio. If a packet fails, then it won't be resend.
- Interrupt transfers - for regular, small data, like keyboards
- Bulk transfers - for large data like hard disks
The transfer method is determined by the device endpoint. A device must always have at least endpoint 0. Endpoint 0 is a control type, so data can go both in and out.
keyboards can use endpoint 1 for keypresses.
Classes
Storage:
- MSC - Mass Storage Class - transfer based on raw data, filesystem managed by the USB host, used by USB drives
- MTP - Multimedia Transfer Protocol - filesystem managed by the USB device, transfer is based on files, used mainly by smart phones, audio players and cameras
CDC class (Virtual COM port) - used as USB-to-serial bridge, usually bulk transfer (isochronous also possible). Transfer is finished when packet smaller than maximum packet size is received
HID - Human interface device - encompassing:
- HID devices: mouse, keyboard, gaming controllers (gamepads, joysticks, steering wheels, etc.)
- Interrupt oriented communication
- HID specific descriptors: describes the format and meaning of the data
- Custom HID: Custom communicaztion with USB device without the need for vendor specific drivers. Low bandwidth
DFU - Device firmware update - for changing the firmware. Bidirectional. A DfuSe extension enables to update parts of the memory
Audio class - used for speakers and microphones. Real-time audio transfer, uses isochronous transfers - close sync might be required. Supports various data formats, sampling frequencies. USB uses unaligned/packed format. This can be an issue for 24-bit formats. STM32 peripherals expect 32-bit aligned data - single 32-bit write to data register via DMA. Additional unpacking required by software.
Composite device - contains multiple interfaces for different USB classes. All classes can operate at the same time. It's possible to use OS system drivers for standard interfaces. An example would be an ST-Link, which contains a debug interface, mass-storage for downloading the firmware, CDC class for communicating with the device through UART.
Glossary
CDC
Abbrev: Communications Device Class.
It is used for computer networking devices akin to a network card, providing an interface for transmitting ethernet of ATM frames into some pyhical media.
HID
Abbrev: Human Interface Device
A device such as keyboard, mouse and "pointing device" such as controller pads or joystick.
MSC
Abbrev: Mass Storage Class
TUH
Abbrev: Tinyusb Host
EXITS
7h : USB for HAL stm32