Debugging USB examples requires 2 PC programs:
PC-side HID Interactive program, provides the VC source program.
Graphical mode of button input, led output operation:
Bus traps:
The main program initialization section is simple:
/* Initialize USB */
Usbd_init (&usb_device_dev,
&usr_desc,
&USBD_HID_CB,
&USR_CB);
Open usbd_custom_hid_core.c
This data structure is the user's concern
Usbd_class_cb_typedef USBD_HID_CB =
{
Usbd_hid_init,
Usbd_hid_deinit,
Usbd_hid_setup,
NULL,/*ep0_txsent*/
Usbd_hid_ep0_rxready,/*ep0_rxready*//* STATUS STAGE in * *
Usbd_hid_datain,/*datain*/input-Output invoker
Usbd_hid_dataout,/*dataout*/
NULL,/*sof */
Usbd_hid_getcfgdesc,
};
USB Receive Data processing:
Open usbd_custom_hid_core.c
Find this program, you can see according to the host computer data parameters, respectively lit different LEDs
/**
* @brief Usbd_hid_dataout
* Handle Data in Stage
* @param Pdev:device Instance
* @param epnum:endpoint Index
* @retval Status
*/
uint8_t usbd_hid_dataout (void *pdev,
uint8_t epnum)
{
Bitaction led_state;
if (Epnum = = 1)
{
if (report_buf[1] = = 0)
{
Led_state = Bit_reset;
}
Else
{
Led_state = Bit_set;
}
Switch (report_buf[0])
{
Case 1:/* Led 3 */
if (led_state! = bit_reset)
{
Stm_eval_ledon (LED3);
}
Else
{
Stm_eval_ledoff (LED3);
}
Break
Case 2:/* Led 4 */
if (led_state! = bit_reset)
{
Stm_eval_ledon (LED4);
}
Else
{
Stm_eval_ledoff (LED4);
}
Break
Case 3:/* Led 5 */
if (led_state! = bit_reset)
{
Stm_eval_ledon (LED5);
}
Else
{
Stm_eval_ledoff (LED5);
}
Break
Case 4:/* Led 6 */
if (led_state! = bit_reset)
{
Stm_eval_ledon (LED6);
}
Else
{
Stm_eval_ledoff (LED6);
}
Break
Default
Stm_eval_ledoff (LED3);
Stm_eval_ledoff (LED4);
Stm_eval_ledoff (LED5);
Stm_eval_ledoff (LED6);
Break
}
}
Dcd_ep_preparerx (pdev,hid_in_ep,report_buf,2);
return USBD_OK;
}
Stm32f072b-disco in-depth study of USB systems