The first step to integrate the demo application into your application code is to call App_USBD_Init()
. This function is responsible for the following steps:
...
The App_USBD_Init()
function is described in Listing - App_USBD_Init() Function.
Anchor | ||||
---|---|---|---|---|
|
Code Block | ||||
---|---|---|---|---|
| ||||
CPU_BOOLEAN App_USBD_Init (void)
{
CPU_INT08U dev_nbr;
CPU_INT08U cfg_hs_nbr;
CPU_INT08U cfg_fs_nbr;
CPU_BOOLEAN ok;
USBD_ERR err;
USBD_Init(&err); (1)
if (err != USBD_ERR_NONE) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
dev_nbr = USBD_DevAdd(&USBD_DevCfg_<controller>, (2)
&App_USBD_BusFncts,
&USBD_DrvAPI_<controller>,
&USBD_DrvCfg_<controller>,
&USBD_DrvBSP_<board name>,
&err);
if (err != USBD_ERR_NONE) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
cfg_hs_nbr = USBD_CFG_NBR_NONE;
cfg_fs_nbr = USBD_CFG_NBR_NONE;
if (USBD_DrvCfg_<controller>.Spd == USBD_DEV_SPD_HIGH) {
cfg_hs_nbr = USBD_CfgAdd(dev_nbr, (3)
USBD_DEV_ATTRIB_SELF_POWERED,
100u,
USBD_DEV_SPD_HIGH,
"HS configuration",
&err);
if (err != USBD_ERR_NONE) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
}
cfg_fs_nbr = USBD_CfgAdd(dev_nbr, (4)
USBD_DEV_ATTRIB_SELF_POWERED,
100u,
USBD_DEV_SPD_FULL,
"FS configuration",
&err);
if (err != USBD_ERR_NONE) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
if ((cfg_fs_nbr != USBD_CFG_NBR_NONE) &&
(cfg_hs_nbr != USBD_CFG_NBR_NONE)) {
USBD_CfgOtherSpeed(dev_nbr, (5)
cfg_hs_nbr,
cfg_fs_nbr,
&err);
if (err != USBD_ERR_NONE) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
}
#if (APP_CFG_USBD_XXXX_EN == DEF_ENABLED) (6)
ok = App_USBD_XXXX_Init(dev_nbr,
cfg_hs_nbr,
cfg_fs_nbr);
if (ok != DEF_OK) {
/* $$$$ Handle error. */
return (DEF_FAIL);
}
#endif
if (APP_CFG_USBD_XXXX_EN == DEF_ENABLED) (6)
.
.
.
#endif
USBD_DevStart(dev_nbr, &err); (7)
(void)ok;
return (DEF_OK);
} |
Panel | ||
---|---|---|
| ||
(1) (2) (3) Create and add a high-speed configuration to your device. (4) Create and add a full-speed configuration to your device. (5) Associate the high-speed configuration to it’s full-speed counterpart. This inform the stack that both configurations offer comparable functionality regardless of speed. This is useful to generate the “Other Speed Configuration” descriptor. (6) Initialize the class-specific application demos by calling the function (7) After all the class instances are created and added to the device configurations, the application should call |
Table - USB Class Demos Init Functions lists the sections you should refer to for more details about each App_USBD_XXXX_Init()
function.
Anchor | ||||
---|---|---|---|---|
|
Panel | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||
|
After building and downloading the application into your target, you should be able to successfully connect your target to a host PC through USB. Once the USB sample application is running, the host detects the connection of a new device and starts the enumeration process. If you are using a Windows PC, it will load a driver which will manage your device. If no driver is found for your device, Windows will display the “found new hardware” wizard so that you can specify which driver to load. Once the driver is loaded, your device is ready for communication. lists Table - USB Class Demos References lists the different section(s) you should refer to for more details on each USB class demo.
Anchor | ||||
---|---|---|---|---|
|