STM32Cube  Version 2.1.0
Create Projects for STM32U5 Series with STM32Cube HAL and STM32CubeMX
USB Device

Revision History

  • Version 1.0
    • Initial release

Capabilities

This driver supports USB Full and Low speeds.

Instances

Hardware resource relating to driver instance is shown in the table below:

Driver Instance Hardware Resource
Driver_USBD0 USB_OTG_FS

Configuration

Compile-time

Definitions used for compile-time configuration of this driver are shown in the table below:

Definition Default value Max value Description
USBD_MAX_ENDPOINT_NUM 5 5 Defines maximum number of IN/OUT Endpoint pairs that the driver will support with Control Endpoint 0 not included. This value impacts driver memory requirements.
Note
To change the default value just provide a desired define with a desired value when compiling the driver

STM32CubeMX

The USB Device driver requires:

  • USB peripheral clock at 48 MHz
  • USB_OTG_FS peripheral configured as Device_Only
  • USB DP and DM pins

B-U585I-IOT02A Board Configuration

These settings are relevant for this board, for different board please refer to the board schematic for proper configuration.

Link to B-U585I-IOT02A board schematic.

STM32CubeMX

Required peripherals for the B-U585I-IOT02A board are listed in the table below:

Peripheral Mode Description
USB_OTG_FS Device_Only USB Controller
PA11 Alternate Function Push Pull USB DM Pin
PA12 Alternate Function Push Pull USB DP Pin
Note
All settings have to be configured as described in the procedure below. Important settings, typically the ones different from default, are emphasized in bold.

Pinout & Configuration tab

  1. In the Pinout view window click on a pin and select it's functionality:
    Pin Functionality
    PA11 USB_OTG_FS_DM
    PA12 USB_OTG_FS_DP

  2. Under Categories: Connectivity select USB_OTG_FS:

    Mode:

    • Mode: Device_Only
    • Activate_VBUS: Disable
    • Activate_SOF: unchecked
    • Activate_NOE: unchecked

    Configuration:

    • Parameter Settings: not used
    • User Constants: not used
    • NVIC Settings: configured in later step (under Category: System Core: NVIC)
    • GPIO Settings:
      Pin Name Signal on Pin Pin Context.. Pin Priv.. GPIO output.. GPIO mode GPIO Pull-up/Pull.. Maximum out.. Fast Mode User Label
      PA11 USB_OTG_FS_DM n/a n/a n/a Alternate Function Push Pull No pull-up and no.. High n/a USB.C_N
      PA12 USB_OTG_FS_DP n/a n/a n/a Alternate Function Push Pull No pull-up and no.. High n/a USB.C_P

  3. Under Categories: System Core select NVIC:

    Configuration:

    • NVIC:
      NVIC Interrupt Table Enabled Preemption Priority Sub Priority
      USB OTG FS global interrupt checked 0 0
    • Code generation:
      Enabled interrupt table Select for.. Generate Enable in.. Generate IRQ h.. Call HAL handler
      USB OTG FS global interrupt unchecked checked unchecked n/a

Clock Configuration tab

  1. Configure To USB (MHz): 48

Project Manager tab

  1. Under Advanced Settings:

    Generated Function Calls:

    Generate Code Function Name Peripheral Inst.. Do not generate .. Visibility (Static)
    checked MX_USB_OTG_FS_PCD_Init USB_OTG_FS checked checked

Generate Code

Generate source code by clicking on the GENERATE CODE button on the toolbar.