Device Configuration

The USB device characteristics must be shared with the USB device stack through configuration parameters. All of these parameters are provided through two global structures of type USBD_DRV_CFG and USBD_DEV_CFG. These structures are declared in the file usbd_dev_cfg.h, and defined in the file usbd_dev_cfg.c (refer to the Copying and Modifying Template Files section for an example of initializing these structures). These files are distributed as templates, and you should modify them to have the proper configuration for your USB device controller.

Driver Configuration

The fields of the following structure are the parameters needed to configure the USB device controller driver:

typedef  const  struct  usb_drv_cfg {
    CPU_ADDR           BaseAddr;                                              (1)
    CPU_ADDR           MemAddr;                                               (2)
    CPU_ADDR           MemSize;                                               (3)
    USBD_DEV_SPD       Spd;                                                   (4)
    USBD_DRV_EP_INFO  *EP_InfoTbl;                                            (5)
} USBD_DRV_CFG;

(1) Base address of the USB device controller hardware registers.

(2) Base address of the USB device controller dedicated memory.

(3) Size of the USB device controller dedicated memory.

(4) Speed of the USB device controller. Can be set to either USBD_DEV_SPD_LOW, USBD_DEV_SPD_FULL or USBD_DEV_SPD_HIGH.

(5) USB device controller endpoint information table.


Device Configuration

The fields of the following structure are the parameters needed to configure the USB device:

typedef  const  struct  usb_dev_cfg {
           CPU_INT16U   VendorID;                                             (1)
           CPU_INT16U   ProductID;                                            (2)
           CPU_INT16U   DeviceBCD;                                            (3)
    const  CPU_CHAR    *ManufacturerStrPtr;                                   (4)
    const  CPU_CHAR    *ProductStrPtr;                                        (5)
    const  CPU_CHAR    *SerialNbrStrPtr;                                      (6)
           CPU_INT16U   LangID;                                               (7)
} USBD_DEV_CFG;

(1) Vendor ID.

(2) Product ID.

(3) Device release number.

(4) Pointer to manufacturer string.

(5) Pointer to product string.

(6) Pointer to serial number ID.

(7) Language ID.


Driver Endpoint Information Table

The endpoint information table provides the hardware endpoint characteristics to the USB device stack. When an endpoint is opened, the USB device stack’s core iterates through the endpoint information table entries until the endpoint type and direction match the requested endpoint characteristics. The matching entry provides the physical endpoint number and maximum packet size information to the USB device stack. The entries on the endpoint information table are organized as follows:

typedef  const  struct  usbd_drv_ep_info {
    CPU_INT08U  Attrib;                                                       (1)
    CPU_INT08U  Nbr;                                                          (2)
    CPU_INT16U  MaxPktSize;                                                   (3)
} USBD_DRV_EP_INFO;

(1) The endpoint Attrib is a combination of the endpoint type USBD_EP_INFO_TYPE and endpoint direction USBD_EP_INFO_DIR attributes. The endpoint type can be defined as: USBD_EP_INFO_TYPE_CTRL, USBD_EP_INFO_TYPE_INTR, USBD_EP_INFO_TYPE_BULK, or USBD_EP_INFO_TYPE_ISOC. The endpoint direction can be defined as either USBD_EP_INFO_DIR_IN or USBD_EP_INFO_DIR_OUT.

(2) The endpoint Nbr is the logical endpoint number used by the USB device controller.

(3) The endpoint MaxPktSize defines the maximum packet size supported by the hardware. The maximum packet size used by the USB device stack is validated to comply with the USB standard guidelines.


An example of an endpoint information table for a high-speed capable device is provided below.

const  USBD_DRV_EP_INFO  USBD_DrvEP_InfoTbl_<controller>[] = {
                                                                              (1)
    {USBD_EP_INFO_TYPE_CTRL                       |USBD_EP_INFO_DIR_OUT, 0u,   64u},
    {USBD_EP_INFO_TYPE_CTRL                       |USBD_EP_INFO_DIR_IN,  0u,   64u},
                                                                              (2)
    {USBD_EP_INFO_TYPE_BULK|USBD_EP_INFO_TYPE_INTR|USBD_EP_INFO_DIR_OUT, 1u, 1024u},
    {USBD_EP_INFO_TYPE_BULK|USBD_EP_INFO_TYPE_INTR|USBD_EP_INFO_DIR_IN,  1u, 1024u},
                                                                              (3)
    {DEF_BIT_NONE                                                     ,  0u,    0u}
};

(1) An endpoint described only by one type and one direction is a dedicated endpoint. Most of the device controllers will have a dedicated endpoint for control OUT and IN endpoints. That’s why the table USBD_DrvEP_InfoTbl_<controller> is first initialized with two dedicated control endpoints.

(2) An endpoint indicating several types and two possible directions is a configurable endpoint. In this example, the endpoint can be configured as a bulk or interrupt OUT endpoint. An endpoint fully configurable in terms of type and direction would be OR’ed with this format:
USBD_EP_INFO_TYPE_CTRL | USBD_EP_INFO_TYPE_INTRUSBD_EP_INFO_TYPE_BULK | USBD_EP_INFO_TYPE_ISOCUSBD_EP_INFO_DIR_IN | USBD_EP_INFO_DIR_OUT.

(3) The last entry on the endpoint information table must be an empty entry to allow the USB device stack to determine the end of the table.


Related pages