Revision History
- Version 3.1
- Corrected PMA configuration
- Added support for devices without Vbus sensing capability
- Updated GetFrameNumber function to always return 0 because of missing HAL support
- Version 3.0
Requirements
This driver requires the STM32 device specific HAL and STM32CubeMX (CubeMX) initialization code generator. The driver instance is mapped to hardware as shown in the table below:
CMSIS Driver Instance | STM32 Hardware Resource |
Driver_USBD0 | USB_OTG_FS or USB_FS or USB_DRD_FS |
Driver_USBD1 | USB_OTG_HS |
Deviations
This driver has the following deviations from the CMSIS-Driver specification:
Conceptual deviations:
- CubeMX generated initialization code (function MX_USB_...PCD_Init) already configures the peripheral. Power, clocks, pins, and interrupts are enabled after execution of initialization that executes in
main.c
.
- Role (Device to Host) cannot be changed at run-time.
Functional deviations:
- GetCapabilities:
- depends on the code generated by CubeMX.
- Initialize:
- depends on the code generated by CubeMX.
- does not initialize the pins.
- Uninitialize:
- does not de-initialize the pins.
- PowerControl:
- depends on the code generated by CubeMX.
- low-power mode is not supported by HAL.
- EndpointTransfer:
- on Endpoint 0 the HAL does not support transfers longer than maximum packet size.
- EndpointTransferAbort:
- HAL function fails when aborting transfer on Interrupt OUT Endpoint.
CubeMX Configuration
This driver requires the following configuration in CubeMX:
- clock: USB peripheral clock at 48 MHz.
- peripheral:
- for USB or USB_OTG_FS configured as Device (FS) or Mode = Device_Only , and configure the following Parameter Settings:
- Enable internal IP DMA set to Disabled.
- Battery charging, if it exists, set to Disabled.
- for USB_OTG_HS in high-speed mode: configured as External Phy = Device_Only if ULPI Phy is populated , and configure the following Parameter Settings:
- Enable internal IP DMA set to Disabled.
- Speed set to speed required by the application: if the application is configured for full-speed operation set this setting to Device Full Speed 12MBit/s, if the application is configured for high-speed operation set this setting to Device High Speed 480MBit/s.
- Battery charging, if it exists, set to Disabled.
- for USB_OTG_HS in full-speed mode: configured as Internal FS Phy = Device_Only if ULPI Phy is not populated , and configure the following Parameter Settings:
- Enable internal IP DMA set to Disabled.
- Battery charging, if it exists, set to Disabled.
- pins:
- for USB or USB_OTG_FS in full-speed mode: USB_OTG_FS_VBUS, USB_OTG_FS_DM and USB_OTG_FS_DP pins.
- for USB_OTG_HS in high-speed mode: USB_OTG_HS_ULPI_CK, USB_OTG_HS_ULPI_D0, USB_OTG_HS_ULPI_D1 , USB_OTG_HS_ULPI_D2, USB_OTG_HS_ULPI_D3, USB_OTG_HS_ULPI_D4, USB_OTG_HS_ULPI_D5, USB_OTG_HS_ULPI_D6 , USB_OTG_HS_ULPI_D7, USB_OTG_HS_ULPI_DIR, USB_OTG_HS_ULPI_NXT and USB_OTG_HS_ULPI_STP pins.
- for USB_OTG_HS in full-speed mode: USB_OTG_HS_VBUS, USB_OTG_HS_DM and USB_OTG_HS_DP pins.
- interrupts:
- for USB or USB_FS or USB_OTG_FS enabled USB or USB FS global interrupt or USB On The Go FS global interrupt and IRQ handlers that Call HAL handlers.
- for USB_OTG_HS enabled USB On The Go HS global interrupt and IRQ handlers that Call HAL handlers.
Example
Pinout & Configuration tab
- In the Pinout view window click on a pin and select it's functionality:
Pin | Functionality |
PA9 | USB_OTG_FS_VBUS (required for VBUS sensing) |
PA11 | USB_OTG_FS_DM |
PA12 | USB_OTG_FS_DP |
PA5 | USB_OTG_HS_ULPI_CK |
PA3 | USB_OTG_HS_ULPI_D0 |
PB0 | USB_OTG_HS_ULPI_D1 |
PB1 | USB_OTG_HS_ULPI_D2 |
PB10 | USB_OTG_HS_ULPI_D3 |
PB11 | USB_OTG_HS_ULPI_D4 |
PB12 | USB_OTG_HS_ULPI_D5 |
PB13 | USB_OTG_HS_ULPI_D6 |
PB5 | USB_OTG_HS_ULPI_D7 |
PI11 | USB_OTG_HS_ULPI_DIR |
PH4 | USB_OTG_HS_ULPI_NXT |
PC0 | USB_OTG_HS_ULPI_STP |
Under Categories: Connectivity select USB_OTG_FS:
Mode:
- Mode: Device_Only
- Activate_VBUS: VBUS sensing
- Activate_SOF: unchecked
Configuration:
- Parameter Settings:
- Enable internal IP DMA: Disabled
- Battery charging: Disabled
- GPIO Settings:
Pin Name | Signal on Pin | Pin Context.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
PA9 | USB_OTG_FS_VBUS | n/a | n/a | Input mode | No pull-up and no.. | n/a | n/a | . |
PA11 | USB_OTG_FS_DM | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PA12 | USB_OTG_FS_DP | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
Under Categories: Connectivity select USB_OTG_HS:
Mode:
- External Phy: Device_Only
- Internal FS Phy: Disable
- Activate_SOF: unchecked
- Activate_VBUS: Disable
Configuration:
- Parameter Settings:
- Speed: set to speed required by the application
- Enable internal IP DMA: Disabled
- Battery charging: Disabled
- GPIO Settings:
Pin Name | Signal on Pin | Pin Context.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
PA5 | USB_OTG_HS_ULPI_CK | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PA3 | USB_OTG_HS_ULPI_D0 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB0 | USB_OTG_HS_ULPI_D1 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB1 | USB_OTG_HS_ULPI_D2 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB10 | USB_OTG_HS_ULPI_D3 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB11 | USB_OTG_HS_ULPI_D4 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB12 | USB_OTG_HS_ULPI_D5 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB13 | USB_OTG_HS_ULPI_D6 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PB5 | USB_OTG_HS_ULPI_D7 | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PI11 | USB_OTG_HS_ULPI_DIR | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PH4 | USB_OTG_HS_ULPI_NXT | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
PC0 | USB_OTG_HS_ULPI_STP | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | High | n/a | . |
Under Categories: System Core select NVIC:
Configuration:
- NVIC:
NVIC Interrupt Table | Enabled | Preemption Priority | Sub Priority |
USB On The Go HS global interrupt | checked | 0 | 0 |
USB On The Go FS global interrupt | checked | 0 | 0 |
- Code generation:
Enabled interrupt table | Select for.. | Generate Enable in.. | Generate IRQ h.. | Call HAL handler |
USB On The Go HS global interrupt | unchecked | checked | checked | checked |
USB On The Go FS global interrupt | unchecked | checked | checked | checked |
Clock Configuration tab
- Configure To USB (MHz): 48
Project Manager tab
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 | unchecked | checked |
checked | MX_USB_OTG_HS_PCD_Init | USB_OTG_HS | unchecked | checked |