on 2025-05-06 5:30 AM
This article gives you the key info you need to dive into USB development on STM32. It mentions various resources, including training (MOOCs), articles, and application notes, that can help understand USB theory and hardware implementation.
To dive deep into USB theory and understand the fundamentals, check the following resources:
Watch the STM32 USB transfers training and read the USB transfers PDF. You can also read the "How to select suitable endpoints for your STM32 USB application" article that helps you to know how to choose the necessary number of endpoints.
You can also read the ST Wiki: USB protocol basics from section 1.0 to 1.15.
For more technical information related to USB, see the USB specification and USB class specifications that can be downloaded from https://www.usb.org/developers
USB requires specific hardware components and principals to function correctly, and it is essential to understand them such as:
All the points listed down below are covered in STM32 USB hardware design training in a basic way. Additionally, in the ST USB hardware design PDF.
Check the relevant datasheet for your product. For more information, check section 2.4 "Clock" in AN4879.
For this point, you can also check this article about ULPI compatibility or section 3.3 OTG applications through embedded PHY to 3.5 USB applications through the embedded OTG_HS PHY of AN4879.
Check this article for more specific overview or check section 2.6 "VBUS sensing detection point" and section 2.3 "Protection against ESD and EMI" in AN4879.
To see STM32 products USB specifications, you can refer to the section 2, “USB on STM32 products” in AN4879.
Refer to specific application notes and datasheets for detailed hardware implementation guidance like the application notes for H5, F7, H7R/S, and H72x/H73x.
Application notes are titled under the name: “Getting started with STM32Xx MCU hardware development”.
To dive deeper, refer to each product’s datasheets, reference manual, application note, and schematics (noted as MBxx example: MB997 for F407G-Disco.)
ST USB middleware provides libraries and tools to facilitate USB device and host functionality on STM32 microcontrollers. It is composed mainly of the device library and host library. We recommend referring to the links in section 1.3.1 and 1.3.2.
For a general understanding of device mode, watch the STM32 USB device library training, read the fifth section in the wiki and view the STM32 USB device library PDF.
For more in-depth review, check UM1734, sixth point USB device library of UM1021 or UM0424 for USB-FS demos.
If you are still searching for helpful resources on the subject, here are some extra links that might help:
You can watch the STM32 USB host library training, read the "USB host library overview" in the ST wiki, and explore the STM32 USB host library PDF.
For a deep explanation, check the section 7. "USB host library" in UM1021.
Almost each board has a simple example in its cube firmware for certain USB classes in both device and host mode. To access them, you just need to follow this path and open the project in your toolchain.
C:\Users\xxxxxx\STM32Cube\Repository\STM32Cube_FW_xx_Vx.xx.x\Projects\xxxxxxxxx\Applications\
This is the default path, but it may change if you chose another location for installing the firmware.
Other than that, there are projects and guidelines available.
Class |
Mode |
Projects/AN’s |
Details |
HID
|
Device
|
Mouse project |
Check your board firmware or visit this lab |
Custom device |
How to implement a custom device project lab and check USB HID articles part 1 and part 2 |
||
Other basics |
Section 6.10.2 USB human interface device example of UM1021 |
||
Host
|
Mouse project |
Check your board firmware or visit this lab |
|
Display message |
Section 7.10.2 "USB HID host" example in UM1021 |
||
CDC
|
Device
|
Receive and transmit project |
Check your firmware if you have an evaluation board, or follow this lab |
Basics |
Section 6.10.5 "USB virtual com port (VCP) device" example in UM1021 |
||
How to set line coding |
Check out this "How to set USB CDC line coding" article |
||
Host |
Basic |
Check your firmware if you have evaluation board or visit this LAB |
|
DFU
|
Device
|
Enable DFU mode |
Check your firmware or follow the device mode hands-on |
Basics |
Check AN3156 for DFU basic commands |
||
Basics |
Section 6.10.4 "USB device firmware upgrade example" in UM1021 |
||
How to modify DFU firmware examples |
Check this article
|
||
How to jump to system bootloader |
Check this article |
||
Open bootloader |
Check this article |
||
Dual bank demo |
Check this GitHub example (H5 board) |
||
Host |
Basics |
Check your firmware or follow the host mode hands-on |
|
MSC
|
Device
|
Mass storage |
Check your firmware or follow the device mode lab |
Basics |
Section 6.10.1 "USB mass storage device example" in UM1021 |
||
Bootloader USB mass storage |
Check this GitHub example for the STM32G0 |
||
Host
|
Basics |
Check your firmware or follow the device mode lab |
|
Basics |
Section 7.10.1 "USB mass storage host example" in UM1021 |
||
AUDIO
|
Device
|
Basics |
Section 6.10.6 "USB audio device example" in UM1021 |
Bridge example |
AN4711 for the STM32F0 |
This tutorial explains how to import and use the legacy STMicroelectronics USB middleware in the new STM32 lines to implement a CDC class for opening a virtual COM port.
Note that some products are native STM32 classic middleware but there are some products that have also available USBX Azure package like H7, H7RS, L5, WB, G4, G0, F7, F4, WL, and L4.
Some boards use USBX stack natively. Refer to the classic middleware accordingly.
Overall, the article provides a thorough guide for USB development on STM32. It includes various resources such as MOOCs, articles, and application notes.
All useful links are directly accessible.