cancel
Showing results for 
Search instead for 
Did you mean: 

Guide to USB development resources on STM32

Gyessine
ST Employee

Introduction

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.

1. USB theory

1.1 Starting with the fundamentals

To dive deep into USB theory and understand the fundamentals, check the following resources:

  • USB protocol basicWatch the first 14 minutes of the STM32 USB training introduction and read the USB introduction PDF
  • Endpoints and data packets structure: Endpoints are specific channels within a USB device. For data transfer, data packets are structured units of information transmitted through these endpoints

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

1.2 USB hardware implementation on an STM32

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.

  • Internal and external clocks 

Check the relevant datasheet for your product. For more information, check section 2.4 "Clock" in AN4879.

  • Internal and external PHYs required for HS and internal PHYs

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.

  • Hardware architecture for DEVICE and HOST mode
  • ESDs and concept of VBUS sensing

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 H5F7H7R/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.)

1.3 ST USB middleware

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.

1.3.1 Device mode

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:

  • DFU class: AN3156 for DFU basic commands explanation
  • Audio class: UM2195 

1.3.2 Host mode

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.

2. Projects and application notes

2.1 One class projects

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

2.2 USB + DMA

  • How to set up USB DMA controller with STM32H7 devices article

2.3 Composite classes projects

  • How to implement the USB device composite class (DFU + HID) article and its associated project
  • How to implement USB device composite class in STM32H5 microcontrollers (HID + CDC) tutorial and project
  • How to implement USB device composite class DUAL CDC article
  • For STM32H7 boards, you can download this branch of firmware for composite examples

2.4 USB + Other IPs

  • How to run Bluetooth® Low Energy P2P server with USB CDC on STM32WB article part 1 and part 2.

3. STM32 Legacy middleware articles

  • How to use classic USB device middleware with the new STM32 families article

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.

  • How to implement USB Communication Device Class (CDC) article

Note that some products are native STM32 classic middleware but there are some products that have also available USBX Azure package like H7, H7RSL5, WB, G4, G0F7, F4WL, and L4.

4. STM32 USBX Azure package articles

  • How to implement the USB device composite class using the Azure hands-on and associated project
  • How to implement the USB device CDC class using the Azure hands-on
  • How to implement USB host using the Azure package hands-on
  • How to implement USBX in standalone mode article
  • Dual CDC project with USBX stack GitHub link

Some boards use USBX stack natively. Refer to the classic middleware accordingly.

5. FAQ and common errors

Conclusion

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.

Version history
Last update:
‎2025-05-06 2:34 AM
Updated by:
Contributors