Getting started with USBX ¶
1. Common USBX core ¶
Architecture overview ¶
Common services ¶
USB protocol core
State machines
Transfer scheduling
Memory services
Tracing and error handling
RTOS/bare-metal integration hooks
Core system APIs ¶
System initialization ¶
|
Function |
Purpose |
|---|---|
|
|
Initialize USBX core, memory pool and internal objects. |
|
|
De-initialize USBX core. |
|
|
Initialize USBX device stack internals. |
|
|
Initialize USBX host stack and register host classes. |
Utility, memory and error handling ¶
|
Function |
Purpose |
|---|---|
|
|
Allocate memory from USBX pool (cache-safe or not). |
|
|
Free memory previously allocated by USBX. |
|
|
Millisecond delay via the underlying RTOS. |
|
|
Application hook to handle/log USBX errors. |
Low-level transfer and endpoint APIs ¶
|
Function |
Purpose |
|---|---|
|
|
Generic transfer submission (host or device). |
|
|
Reset endpoint and clear toggles / error state. |
|
|
Abort an ongoing transfer on the endpoint. |
|
|
Stall (halt) an endpoint. |
|
|
Clear endpoint stall condition. |
Common core configuration flags ¶
|
Flag |
Description |
|---|---|
|
|
USBX main thread stack size. |
|
|
Ticks per second for the platform. |
|
|
Minimal memory alignment (bytes). |
|
|
Debug log pool size. |
|
|
Build host side only. |
|
|
Build device side only. |
|
|
Enable standalone (bare-metal) mode. |
2. USB Device side ¶
Device stack APIs ¶
Device core ¶
|
Function |
Purpose |
|---|---|
|
|
Initialize device stack and register device classes. |
|
|
De-initialize device stack. |
|
|
Set active configuration (e.g. after SET_CONFIGURATION). |
|
|
Force logical device disconnect (re-enumeration, error handling). |
Device descriptors ¶
|
Function |
Purpose |
|---|---|
|
|
Send a descriptor over control endpoint (EP0). |
|
|
Get pointer and length for a descriptor (device, cfg, string, etc.). |
Device transfers ¶
|
Function |
Purpose |
|---|---|
|
|
Start a transfer on a non-control endpoint. |
|
|
Process standard control request (EP0 SETUP stage). |
Device callbacks and events ¶
The device stack calls user code for:
Device reset
Configuration set / cleared
Suspend / resume
Class-specific events (CDC line coding change, HID reports, etc.)
Device-side core configuration flags ¶
|
Flag |
Description |
|---|---|
|
|
Max number of device classes in the stack. |
|
|
Max interfaces in the device framework. |
|
|
Max SCSI logical units in device MSC. |
|
|
Max bytes received on control endpoint (EP0). |
|
|
Select endpoint buffer owner. |
|
|
Enable zero-copy for CDC-ACM device. |
|
|
Enable zero-copy and flexible queues for HID device. |
|
|
Enable zero-copy for Printer device. |
|
|
Max bytes for non-control endpoint transfers. |
|
|
Enable Get String Descriptor with zero language ID. |
|
|
Disable non-blocking transmission in CDC-ACM. |
|
|
Enable HID interrupt OUT support. |
|
|
Enable audio feedback endpoint for audio device. |
|
|
Enable audio interrupt endpoint for audio device. |
|
|
Enable bi-directional endpoints. |
|
|
Disable interface alternate setting support. |
|
|
Disable framework scanning (optimize memory). |
|
|
Max simultaneously active endpoints. |
|
|
Max simultaneously active interfaces. |
|
|
Disable DFU_UPLOAD support. |
|
|
Enable DFU_GETSTATUS/GETSTATE in ERROR state. |
|
|
Select DFU status mode. |
|
|
Default DFU
|
|
|
Enable DFU custom request callback. |
|
|
Auto ZLP on CDC-ACM write. |
|
|
Auto ZLP on Printer write. |
|
|
Enable PIMA MTP support (device + host). |
Device framework configuration (USBD_*) ¶
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
Enable USB Device Framework Builder. |
0 |
|
|
Max device power (mA). |
100 |
|
|
Use IAD for composite devices. |
1 |
|
|
Vendor ID. |
0x0483 |
|
|
Product ID. |
0x0001 |
|
|
Language ID string. |
0x0409 |
|
|
Manufacturer string. |
STMicroelectronics |
|
|
Product string. |
STM32 Device |
|
|
Serial number string. |
001 |
|
|
Max total descriptor size (bytes). |
256 |
Device-side class APIs and configuration ¶
HID (Device) ¶
|
Function |
Purpose |
|---|---|
|
|
HID device class entry (registered with device stack). |
|
|
Handle SET_REPORT from host. |
|
|
Handle GET_REPORT from host. |
|
|
Send HID input report (mouse/keyboard/custom IN). |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
HID mouse IN endpoint address. |
0x81 |
|
|
HID mouse IN FS Max Packet Size. |
4 |
|
|
HID mouse IN HS Max Packet Size. |
4 |
|
|
HID mouse IN FS polling interval (BInterval). |
10 |
|
|
HID mouse IN HS polling interval (BInterval). |
5 |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
HID keyboard IN endpoint address. |
0x81 |
|
|
HID keyboard IN FS Max Packet Size. |
8 |
|
|
HID keyboard IN HS Max Packet Size. |
8 |
|
|
HID keyboard IN FS polling interval. |
10 |
|
|
HID keyboard IN HS polling interval. |
10 |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
Custom HID IN endpoint address. |
0x81 |
|
|
Custom HID OUT endpoint address. |
0x01 |
|
|
Custom HID IN FS Max Packet Size. |
64 |
|
|
Custom HID IN HS Max Packet Size. |
512 |
|
|
Custom HID OUT FS Max Packet Size. |
64 |
|
|
Custom HID OUT HS Max Packet Size. |
512 |
|
|
Custom HID IN FS polling interval. |
10 |
|
|
Custom HID IN HS polling interval. |
5 |
|
|
Custom HID OUT FS polling interval. |
10 |
|
|
Custom HID OUT HS polling interval. |
5 |
MSC (Device) ¶
|
Function |
Purpose |
|---|---|
|
|
MSC device class entry. |
|
|
Read blocks from underlying media (user callback). |
|
|
Write blocks to underlying media (user callback). |
|
|
Get media status (user callback). |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
MSC OUT endpoint address. |
0x01 |
|
|
MSC IN endpoint address. |
0x81 |
|
|
MSC IN FS Max Packet Size. |
64 |
|
|
MSC IN HS Max Packet Size. |
512 |
|
|
MSC OUT FS Max Packet Size. |
64 |
|
|
MSC OUT HS Max Packet Size. |
512 |
CDC-ACM (Device) ¶
|
Function |
Purpose |
|---|---|
|
|
CDC-ACM device class entry. |
|
|
Send data to host (IN endpoint). |
|
|
Receive data from host (OUT endpoint). |
|
|
Handle line coding, control signals, etc. |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
CDC-ACM OUT data endpoint address. |
0x01 |
|
|
CDC-ACM IN data endpoint address. |
0x81 |
|
|
CDC-ACM command IN endpoint address. |
0x82 |
|
|
CMD IN FS Max Packet Size. |
8 |
|
|
CMD IN HS Max Packet Size. |
8 |
|
|
Data IN FS Max Packet Size. |
64 |
|
|
Data OUT FS Max Packet Size. |
64 |
|
|
Data IN HS Max Packet Size. |
512 |
|
|
Data OUT HS Max Packet Size. |
512 |
|
|
CMD IN FS polling interval. |
16 |
|
|
CMD IN HS polling interval. |
16 |
DFU (Device) ¶
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
DFU
|
11 |
|
|
Erase time (ms). |
50 |
|
|
Program time (ms). |
50 |
|
|
Detach timeout (ms). |
255 |
|
|
Transfer size (bytes). |
1024 |
|
|
DFU media string descriptor. |
(string) |
Audio (Device) ¶
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
audio OUT endpoint address. |
0x01 |
|
|
audio IN endpoint address. |
0x81 |
|
|
audio feedback endpoint address. |
0x82 |
|
|
audio OUT FS Max Packet Size. |
see class doc |
|
|
audio OUT HS Max Packet Size. |
see class doc |
|
|
audio IN FS Max Packet Size. |
see class doc |
|
|
audio IN HS Max Packet Size. |
see class doc |
|
|
audio feedback FS Max Packet Size. |
4 |
|
|
audio feedback HS Max Packet Size. |
4 |
|
|
Enable playback support. |
FALSE |
|
|
Enable record support. |
FALSE |
|
|
Number of playback channels. |
2 |
|
|
Number of record channels. |
2 |
|
|
Playback channel map. |
see note |
|
|
Record channel map. |
see note |
|
|
audio stream frequency. |
48 kHz |
|
|
audio resolution. |
16 bits |
|
|
audio IN FS polling interval. |
1 |
|
|
audio IN HS polling interval. |
1 |
|
|
audio OUT FS polling interval. |
1 |
|
|
audio OUT HS polling interval. |
1 |
|
|
Feedback IN FS polling interval. |
1 |
|
|
Feedback IN HS polling interval. |
1 |
|
|
Feedback OUT FS polling interval. |
1 |
|
|
Feedback OUT HS polling interval. |
1 |
Printer (Device) ¶
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
Printer OUT endpoint address. |
0x01 |
|
|
Printer IN endpoint address. |
0x81 |
|
|
Printer OUT FS Max Packet Size. |
64 |
|
|
Printer OUT HS Max Packet Size. |
512 |
|
|
Printer IN FS Max Packet Size. |
64 |
|
|
Printer IN HS Max Packet Size. |
512 |
|
|
Printer interface protocol. |
2 |
Video / UVC (Device) ¶
|
Function |
Purpose |
|---|---|
|
|
Video/UVC device class entry. |
|
|
Start streaming. |
|
|
Stop streaming. |
|
|
Send video frame (or chunk) to host. |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
video IN endpoint address. |
0x81 |
|
|
video IN FS Max Packet Size. |
256 |
|
|
video IN HS Max Packet Size. |
512 |
|
|
video IN FS polling interval. |
1 |
|
|
video IN HS polling interval. |
1 |
|
|
video payload format. |
UNCOMPRESSED |
|
|
UVC uncompressed GUID. |
UVC_GUID_YUY2 |
|
|
Bits per pixel. |
12 |
|
|
Color primaries. |
1 |
|
|
Transfer characteristics. |
1 |
|
|
Matrix coefficients. |
4 |
|
|
Frame width (pixels). |
400 |
|
|
Frame height (pixels). |
240 |
|
|
Full-Speed frame rate. |
5 |
|
|
High-Speed frame rate. |
5 |
PIMA / MTP (Device) ¶
|
Function |
Purpose |
|---|---|
|
|
MTP device class entry. |
|
|
Notify host of new object (file). |
|
|
Notify host object removed. |
|
|
Send MTP event to host. |
|
Function |
Purpose |
|---|---|
|
|
PIMA / MTP device class entry. |
|
|
Send object metadata to host. |
|
|
Send object data to host. |
|
|
Send MTP event (e.g. capture complete) to host. |
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
CMD IN endpoint address. |
0x82 |
|
|
CMD IN FS Max Packet Size. |
64 |
|
|
CMD IN HS Max Packet Size. |
512 |
|
|
Data OUT endpoint address. |
0x01 |
|
|
Data IN endpoint address. |
0x81 |
|
|
IN FS Max Packet Size. |
64 |
|
|
IN HS Max Packet Size. |
512 |
|
|
OUT FS Max Packet Size. |
64 |
|
|
OUT HS Max Packet Size. |
512 |
|
|
CMD IN FS polling interval. |
10 |
|
|
CMD IN HS polling interval. |
5 |
CCID (Device) ¶
|
Flag Name |
Description |
Default Value |
|---|---|---|
|
|
CCID OUT endpoint address. |
0x01 |
|
|
CCID IN endpoint address. |
0x81 |
|
|
CCID CMD IN endpoint address. |
0x82 |
|
|
OUT FS Max Packet Size. |
64 |
|
|
OUT HS Max Packet Size. |
512 |
|
|
IN FS Max Packet Size. |
64 |
|
|
IN HS Max Packet Size. |
512 |
|
|
Max slot index. |
0 |
|
|
Max busy slots. |
1 |
|
|
Supported clock count. |
1 |
|
|
Supported data rate count. |
1 |
|
|
Header max block size. |
271 |
|
|
Default data rate. |
10752 |
|
|
Max data rate. |
10752 |
|
|
Default clock frequency. |
4800 |
|
|
Max clock frequency. |
4800 |
|
|
Protocol. |
3 |
|
|
Voltage supply. |
7 |
|
|
CMD IN FS polling interval. |
10 |
|
|
CMD IN HS polling interval. |
5 |
3. USB Host side ¶
Host stack APIs ¶
Host core ¶
|
Function |
Purpose |
|---|---|
|
|
Initialize host stack, register host classes and HCDs. |
|
|
Register a Host Controller Driver (HCD). |
|
|
Unregister an HCD. |
|
|
Register a host class (CDC, MSC, HID, etc.). |
|
|
Inform stack of device insertion (called by HCD). |
|
|
Inform stack of device removal (called by HCD). |
|
|
Run periodic host tasks (for non-threaded ports, if implemented). |
Host device access and control ¶
|
Function |
Purpose |
|---|---|
|
|
Get a device handle by index. |
|
|
Get USB address of a device. |
|
|
Get current device configuration. |
|
|
Get interface by index from configuration. |
|
|
Read string descriptor from device. |
|
|
Submit host transfer (control/bulk/interrupt/isochronous). |
|
|
Reset host endpoint (clear toggle / recover errors). |
Host Plug & Play notifications ¶
|
Function |
Purpose |
|---|---|
|
|
Register callback for plug-and-play events. |
Host HCD interfaces ¶
|
Function |
Purpose |
|---|---|
|
|
Initialize specific HCD (OHCI / EHCI / DWC2 / …). |
|
|
HCD command dispatcher (port reset, transfer, etc.). |
Host-side configuration flags ¶
|
Flag |
Description |
|---|---|
|
|
Stack size for host enumeration thread. |
|
|
Stack size for host HCD thread. |
|
|
Max number of host classes. |
|
|
Max number of host controllers. |
|
|
Max attached devices. |
|
|
Max SCSI logical units in host MSC. |
|
|
Max storage payload buffer size. |
|
|
Max endpoint descriptors. |
|
|
Max transfer descriptors. |
|
|
Max isochronous transfer descriptors. |
|
|
Max HID decompressed buffer size. |
|
|
Max HID usages per device. |
|
|
Enable HID keyboard key change events. |
|
|
Report only key down events, lock key changes or modifier key changes (depending on variant). |
|
|
Max number of media for host MSC. |
|
|
Include CB/CBI legacy storage protocols. |
|
|
Enforce alignment via
|
|
|
HID report transfer timeout. |
|
|
Enable audio UAC 2.0 host support. |
|
|
Enable host audio feedback endpoint. |
|
|
Enable host audio interrupt endpoint. |
|
|
Control when configuration instances are created. |
|
|
Store names as pointers (not copies). |
|
|
Remove FileX dependency from host MSC. |
|
|
Max size of single SCSI data transfer. |
|
|
Enable validation of device class codes. |
|
|
Enable HID interrupt OUT support on host. |
Host-side class APIs ¶
HID (Host) ¶
|
Function |
Purpose |
|---|---|
|
|
HID host class entry (registered with host stack). |
|
|
Register HID client (mouse, keyboard, custom). |
|
|
Unregister HID client. |
|
|
Get HID report descriptor. |
|
|
GET_REPORT from device. |
|
|
SET_REPORT to device. |
MSC (Host) ¶
|
Function |
Purpose |
|---|---|
|
|
MSC host class entry. |
|
|
Read blocks from USB storage. |
|
|
Write blocks to USB storage. |
|
|
Eject / safely remove media. |
CDC-ACM (Host) ¶
|
Function |
Purpose |
|---|---|
|
|
CDC-ACM host class entry. |
|
|
Read data from CDC-ACM device. |
|
|
Write data to CDC-ACM device. |
|
|
Configure line coding, baud rate, control signals, etc. |
Bare-metal support matrices ¶
Device bare-metal support ¶
|
Class |
Bare-metal support |
|---|---|
|
HID |
Yes |
|
CDC-ACM |
Yes |
|
MSC (Mass Storage) |
Yes |
|
DFU |
Yes |
|
audio |
Yes |
|
video |
Yes |
|
Printer |
Yes |
|
MTP |
No |
|
CCID |
Yes |
Host bare-metal support ¶
|
Class |
Bare-metal support |
|---|---|
|
HID |
Yes |
|
CDC-ACM |
Yes |
|
MSC |
Yes |
|
audio |
No |
|
video |
No |
|
Printer |
Yes |
|
MTP |
No |
|
HUB |
Yes |
|
Gser |
No |
|
Prolific |
No |
|
Swar |
No |