STM32Cube  Version 1.2.0
Create Projects for STM32H5 Series with STM32Cube HAL and STM32CubeMX
USB Device

Revision History

  • Version 1.1
    • Updated PowerControl function (added check if Instance is valid)
    • Updated GetFrameNumber function (use LL function)
  • 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_DRD_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 2 7 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.
USBD_EP0_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 0. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP0_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 0.
USBD_EP0_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 0. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP0_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 0.
USBD_EP1_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 1. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP1_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 1.
USBD_EP1_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 1. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP1_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 1.
USBD_EP2_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 2. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP2_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 2.
USBD_EP2_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 2. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP2_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 2.
USBD_EP3_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 3. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP3_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 3.
USBD_EP3_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 3. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP3_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 3.
USBD_EP4_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 4. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP4_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 4.
USBD_EP4_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 4. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP4_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 4.
USBD_EP5_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 5. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP5_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 5.
USBD_EP5_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 5. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP5_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 5.
USBD_EP6_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 6. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP6_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 6.
USBD_EP6_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 6. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP6_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 6.
USBD_EP7_RX_BUF_KIND 0 1 Selects usage of double buffering for reception on Endpoint 7. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP7_RX_RAM_SIZE 64 128 Defines RAM size for reception on Endpoint 7.
USBD_EP7_TX_BUF_KIND 0 1 Selects usage of double buffering for transmission on Endpoint 7. Value 0 = do not use double buffering, 1 = use double buffering.
USBD_EP7_TX_RAM_SIZE 64 128 Defines RAM size for transmission on Endpoint 7.
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 peripheral configured as Device_Only
  • USB DP and DM pins

NUCLEO-H563ZI Board Configuration

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

Link to NUCLEO-H563ZI board schematic.

STM32CubeMX

Required peripherals for the NUCLEO-H563ZI board are listed in the table below:

Peripheral Mode Description
USB 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_DM
    PA12 USB_DP

  2. Under Categories: Connectivity select USB:

    Mode:

    • Mode: Device_Only
    • Activate_SOF: 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_DM n/a n/a n/a Alternate Function Push Pull No pull-up and no.. High n/a USB_FS_N
      PA12 USB_DP n/a n/a n/a Alternate Function Push Pull No pull-up and no.. High n/a USB_FS_P

  3. Under Categories: System Core select NVIC:

    Configuration:

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

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_PCD_Init USB unchecked checked

Generate Code

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