This driver supports USB Full and Low speeds.
Hardware resource relating to driver instance is shown in the table below:
| Driver Instance | Hardware Resource |
|---|---|
| Driver_USBH0 | USB_OTG_FS |
Definitions used for compile-time configuration of this driver are shown in the table below:
| Definition | Default value | Max value | Description |
|---|---|---|---|
| USBH_MAX_PIPE_NUM | 12 | 12 | Defines maximum number of Pipes that the driver will support. This value impacts driver memory requirements. |
| USBH_BULK_IN_NAK_DELAY | 0 | 65535 | Delay between NAKs on the Bulk IN pipe (in SOFs), value 0 = not used (no delay between NAKs) |
The USB Host driver requires:
Depending on the required peripherals it might be required to make some source code changes to support additional functionality.
For example, for the B-U585I-IOT02A board, to enable USB Power Delivery, which is necessary for power sourcing as well as fault handling it is necessary to make some source code changes.
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.
Required peripherals for the B-U585I-IOT02A board are listed in the table below:
| Peripheral | Mode | Description |
|---|---|---|
| USB_OTG_FS | Host_Only | USB Controller |
| PA11 | Alternate Function Push Pull | USB DM Pin |
| PA12 | Alternate Function Push Pull | USB DP Pin |
| I2C2 | I2C | USB-C Port Protection interface |
| PH4 | Alternate Function Open Drain | I2C2 SCL Pin |
| PH5 | Alternate Function Open Drain | I2C2 SDA Pin |
| UCPD1 | Dual Role | USB-C Power Delivery interface |
| PA15 | Analog mode | USB-C PD CC1 Pin |
| PB15 | Analog mode | USB-C PD CC2 Pin |
| PB5 | Output Push Pull | USB-C PP Power Pin |
| PD13 | Analog mode | USB-C PP VBUS current analog measurement |
| PE8 | External Interrupt Mode with Falling edge trigger detection | USB-C PP Fault Detect Pin |
| PF14 | Analog mode | VBUS Sense |
| EXTI Line 8 | . | External Interrupt |
| Pin | Functionality |
|---|---|
| PA11 | USB_OTG_FS_DM |
| PA12 | USB_OTG_FS_DP |
| PH4 | I2C2_SCL |
| PH5 | I2C2_SDA |
| PA15 | UCPD1_CC1 |
| PB15 | UCPD1_CC2 |
| PB5 | GPIO_Output |
| PD13 | GPIO_Analog + ADC4_IN17 |
| PE8 | GPIO_EXTI8 |
| PF14 | GPIO_Analog + ADC4_IN5 |
Under Categories: Connectivity select USB_OTG_FS:
Mode:
Configuration:
| 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 |
Under Categories: Connectivity select I2C2:
Mode:
Configuration:
| Pin Name | Signal on Pin | Pin Context.. | Pin Priv.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
|---|---|---|---|---|---|---|---|---|---|
| PH4 | I2C2_SCL | n/a | n/a | n/a | Alternate Function Open Drain | Pull-up | Low | n/a | . |
| PH5 | I2C2_SDA | n/a | n/a | n/a | Alternate Function Open Drain | Pull-up | Low | n/a | . |
Under Categories: Connectivity select UCPD1:
Mode:
Configuration:
| Pin Name | Signal on Pin | Pin Context.. | Pin Priv.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
|---|---|---|---|---|---|---|---|---|---|
| PA15 | UCPD1_CC1 | n/a | n/a | n/a | Analog mode | No pull-up and no.. | n/a | n/a | USB.UCPD_CC1 |
| PB15 | UCPD1_CC2 | n/a | n/a | n/a | Analog mode | No pull-up and no.. | n/a | n/a | USB.UCPD_CC2 |
Under Categories: System Core select GPIO:
Configuration:
| Pin Name | Signal on Pin | Pin Context.. | Pin Priv.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
|---|---|---|---|---|---|---|---|---|---|
| PB5 | n/a | n/a | n/a | Low | Output Push Pull | No pull-up and no.. | Low | n/a | UCPD_PWR |
| PD13 | GPIO_Analog | n/a | n/a | n/a | Analog mode | No pull-up and no.. | n/a | n/a | USB.IANA |
| PE8 | n/a | n/a | Non-priv.. | n/a | Ext Int Falling e.. | Pull-up | n/a | n/a | USB.UCPD_FLT |
| PF14 | GPIO_Analog | n/a | n/a | n/a | Analog mode | No pull-up and no.. | n/a | n/a | USB.VBUS_SENSE |
Under Categories: System Core select NVIC:
Configuration:
| NVIC Interrupt Table | Enabled | Preemption Priority | Sub Priority |
|---|---|---|---|
| USB OTG FS global interrupt | checked | 0 | 0 |
| I2C2 Event interrupt | unchecked | 0 | 0 |
| I2C2 Error interrupt | unchecked | 0 | 0 |
| UCPD1 global interrupt | unchecked | 0 | 0 |
| EXTI Line8 interrupt | checked | 0 | 0 |
| Enabled interrupt table | Select for.. | Generate Enable in.. | Generate IRQ h.. | Call HAL handler |
|---|---|---|---|---|
| USB OTG FS global interrupt | unchecked | checked | unchecked | n/a |
| EXTI Line8 interrupt | unchecked | unchecked | checked | checked |
Under Advanced Settings:
Generated Function Calls:
| Generate Code | Function Name | Peripheral Inst.. | Do not generate .. | Visibility (Static) |
|---|---|---|---|---|
| checked | MX_I2C2_Init | I2C2 | unchecked | checked |
| checked | MX_UCPD1_Init | UCPD1 | unchecked | checked |
| checked | MX_USB_OTG_FS_HCD_Init | USB_OTG_FS | checked | checked |
Generate source code by clicking on the GENERATE CODE button on the toolbar.
To enable USB Power Delivery, which is necessary for power sourcing as well as fault handling, please include b_u585i_iot02a_usbpd_pwr.c board driver into your project and make the following changes to your source code (in your source module, preferably main.c):
Include the b_u585i_iot02a_usbpd_pwr.h:
Add the code for initialization and enabling of the USB PD:
Add the code for VBUS driving:
Add the code for USB PD fault handling: