USBD_DrvInit
Description
Driver initialization/Init()
function. This function is called by USBD_DevStart()
exactly once for each specific device added by the application. If multiple instances of the same device are present on the development board, then this function is called for each instance of the device. However, applications should not try to add the same specific device more than once. If a device fails to initialize, it is recommend debugging to find and correct the cause of failure.
Note: This function relies heavily on the implementation of several device board support package (BSP) functions. See Device Driver BSP Functions for more information on device BSP functions.
Files
Every device driver’s usbd_drv.c
Prototype
static void USBD_DrvInit (USBD_DRV *p_drv USBD_ERR *p_err);
Note that since every device driver function is accessed only by function pointer via the device driver’s API structure, they do not need to be globally available and should therefore be declared as ‘static
’.
Arguments
p_drv
Pointer to USB device driver structure.
p_err
Pointer to variable that will receive the return error code from this function.
Returned Value
None.
Callers
USB device core layer.
Notes / Warnings
- The
Init()
function generally performs the following operations, however, depending on the device being initialized, functionality may need to be added or removed:- Configure clock gating to the USB device, configure all necessary I/O pins, and configure the host interrupt controller. This is generally performed via the device’s BSP function pointer,
Init()
, implemented inusbd_bsp_<driver_name>.c
(seeUSBD_BSP_Init
). - Reset USB controller or USB controller registers.
- Disable and clear pending interrupts (should already be cleared).
- Set the device address to zero.
- For DMA devices: Allocate memory for all necessary descriptors. This is performed via calls to µC/LIB’s memory module. If memory allocation fails, set
p_err
toUSBD_ERR_ALLOC
and return. - Set
p_err
toUSBD_ERR_NONE
if initialization proceeded as expected. Otherwise, setp_err
to an appropriate device error code.
- Configure clock gating to the USB device, configure all necessary I/O pins, and configure the host interrupt controller. This is generally performed via the device’s BSP function pointer,