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

  1. The Init() function generally performs the following operations, however, depending on the device being initialized, functionality may need to be added or removed:
    1. 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 in usbd_bsp_<driver_name>.c (see USBD_BSP_Init).
    2. Reset USB controller or USB controller registers.
    3. Disable and clear pending interrupts (should already be cleared).
    4. Set the device address to zero.
    5. 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 to USBD_ERR_ALLOC and return.
    6. Set p_err to USBD_ERR_NONE if initialization proceeded as expected. Otherwise, set p_err to an appropriate device error code.