HAL USB PCD How to Use ¶
- group PCD_How_To_Use
-
How to use the HAL USB PCD module driver ¶
Use the USB Peripheral Controller Driver (PCD) HAL driver as follows: ¶
Declare a hal_pcd_handle_t handle structure, for example: hal_pcd_handle_t gh_pcd_usb_drd_fs;
Initialize the USB PCD low-level resources:
USB PCD interface clock configuration:
Enable USB peripheral clock.
USB PCD interface power configuration:
Enable USB peripheral VddUSB power supply if applicable.
USB device 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_PCD_IRQHandler():
Set the USB PCD interrupt priority.
Enable the USB IRQ channel in the NVIC.
Initialize the USB PCD driver with HAL_PCD_Init() by selecting an instance, for example:
HAL_PCD_Init(&gh_pcd_usb_drd_fs, HAL_PCD_DRD_FS);
Declare a hal_pcd_config_t structure, for example:
hal_pcd_config_t config_pcd_usb_drd_fs;
In the configuration structure, program the PHY interface, core speed, and other parameters as required.
Apply the configuration with:
HAL_PCD_SetConfig(&gh_pcd_usb_drd_fs, &config_pcd_usb_drd_fs);
Configure required USB device endpoints.
USB PCD callback definitions: ¶
By default, all callbacks are initialized to their corresponding default weak functions. When the compilation define USE_HAL_PCD_REGISTER_CALLBACKS is set to 1U, configure the driver callbacks dynamically using the callback registration functions:
Default callback weak function
Callback registration function