HAL USB HCD How to Use

group HCD_How_To_Use

How to use the HAL USB HCD module driver

Use the USB Host Controller Driver (HCD) HAL driver as follows:

  1. Declare a hal_hcd_handle_t handle structure, for example: hal_hcd_handle_t gh_hcd_usb_drd_fs;

  2. Initialize the USB HCD low-level resources:

    • USB HCD interface clock configuration:

      • Enable USB peripheral clock.

    • USB HCD interface Power configuration:

      • Enable USB peripheral VddUSB power supply if applicable.

    • USB host pins configuration: USB data pins are automatically configured by the hardware during USB peripheral initialization; no additional user action is required.

    • NVIC configuration for interrupt handling with HAL_HCD_IRQHandler():

      • Set the USB HCD interrupt priority.

      • Enable the USB IRQ channel in the NVIC.

  3. Initialize the USB HCD driver with HAL_HCD_Init() by selecting an instance, for example:

    • HAL_HCD_Init(&gh_hcd_usb_drd_fs, HAL_HCD_DRD_FS);

  • Declare a hal_hcd_config_t structure, for example:

  • In the configuration structure, program the PHY interface, core speed, and other parameters as required.

  • Apply the configuration with:

    • HAL_HCD_SetConfig(&gh_hcd_usb_drd_fs, &config_hcd_usb_drd_fs);

USB HCD callback definitions:

By default, all callbacks are initialized to their corresponding default weak functions. When the compilation define USE_HAL_HCD_REGISTER_CALLBACKS is set to 1U, configure the driver callbacks dynamically using the callback registration functions: