Stm32f072b-disco in-depth study of USB systems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.