Introduction to USBX

Revision as of 14:24, 26 January 2021 by Registered User (→‎STM32 Device Porting layer)

1. Introduction

Besides offering STMicroelectronics’s USB stack, USBX, the Azure RTOS USB embedded stack, is currently supported and offered with a set of applications on STM32 MCUs.
The USB Overview is a dedicated wiki page that was implemented to provide a general overview of the Universal Serial Bus and its main features.
USBX is the Azure RTOS USB Host and USB Device embedded stack. It is tightly coupled with ThreadX. For some classes, it requires the FileX and NetXDuo stacks. It allows to work with USB devices with multiple configurations, composite devices, USB OTG and supports the USB power management.
USBX provides both USB Host and USB Device stack with a large set of the USB classes. The modular architecture makes the porting on different USB hardware IPs easier as soon as the low-level driver can answer the USBX requests. In the STM32 context, the USB IPs either host or device, vary from a family to another. Even though all IP should be supported transparently by the USBX thanks to the common STM32 HAL driver API.
USBX provides all common USB features and classes. The following figure provides the list of currently supported classes:

USBX supported classes


  • HUB class cannot be supported on current STM32 products due to a HW limitation.

Besides ThreadX integration with USBX, the USB events are managed through interrupts.
The USBX stack has mainly three layers:

  • The lower layer is the controller layer that ensures the interfacing with the Hardware USB peripheral and for STM32 MCUs this layer is compatible with the HAL.
  • The middle layer ensures the USB stack requirements processing and the interfacing between the low and high layers.
  • The higher layer includes the different classes and ensures the interfacing with the application layer.

The following figure provides an overview of the USBX three layers architecture and main components.

USBX layers and components overeview

As presented in the following figure, the different layers can be easily found within the USBX folder.

USBX Folder architecture overview

For more details, please refer to Azure RTOS USBX documentation.

2. USBX Device for STM32

This section provides the main guidelines allowing to use the USBX Stack with the HAL on the STM32 MCUs.

2.1. STM32 Device Porting layer

As described in the previous section, the USBX is based on three layers that must be referenced within any application project. To be able to interface with the STM32 HAL, the project must integrate the STM32 Device controllers. The drivers presented in the figure below include all the APIs allowing the interfacing with the STM32 HAL.

USBX STM32 Device Controllers

An overview of the main APIs is provided in the table below:

Function’s name Function’s description
HAL_PCD_SetupStageCallback Callback allowing to handle the setup stage callback.
HAL_PCD_DataInStageCallback Callback allowing to handle the Data IN stage callback.
HAL_PCD_DataOutStageCallback Callback allowing to handle the Data OUT stage callback
HAL_PCD_ResetCallback Callback allowing to re-initializes the device.
HAL_PCD_DisconnectCallback Callback allowing to detect the device disconnect event.
ux_dcdc_stm32_endpoint_create Ensures the creation of a new endpoint.
ux_dcd_stm32_endpoint_destroy Ensures the destruction of an endpoint.
ux_dcd_stm32_endpoint_reset Ensures the reset of an endpoint.
ux_dcd_stm32_endpoint_stall Ensures the stall of an endpoint.
ux_dcd_stm32_endpoint_status Allows to get the status of the endpoint.
ux_dcd_stm32_frame_number_get Allows to get the frame number currently used by the controller.
ux_dcd_stm32_function Allows to dispatch the Device Controller Driver function internally to the STM32 controller to:
  • Create endpoint
  • Destroy endpoint
  • Reset endpoint
  • Stall endpoint
  • Get endpoint status
  • Get frame number
  • Request data transfer
ux_dcd_stm32_initialize Allows to initialize the STM32 USB Device controller.
ux_dcd_stm32_initialize_complete Allows to complete the initialization of the USB Device controller.
ux_dcd_stm32_interrupt_handler Allows to call the interrupt handler of the STM32 device controller.
ux_dcd_stm32_transfer_request Allows to initiate a transfer to a specific IN or OUT endpoint.
ux_dcd_stm32_uninitialize Allows to un-initialize the STM32 USB device controller.


3. USBX Host for STM32


No categories assignedEdit