最后一步,在中断中调用GD的中断处理函数入口,mian函数中进行初始化和轮询,进行调用和测试,如下。usb_core_handle_struct cdc_acm =
{
.dev =
{
.dev_desc = (uint8_t *)&device_descriptor,
.config_desc = (uint8_t *)&configuration_descriptor,
.strings = usbd_strings,
.class_init = cdc_acm_init,
.class_deinit = cdc_acm_deinit,
.class_req_handler = cdc_acm_req_handler,
.class_data_handler = cdc_acm_data_handler
},
.udelay = NULL,
.mdelay = HAL_Delay
};
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] This function handles USB On The Go FS global interrupt.
*/
void OTG_FS_IRQHandler(void)
{
/* USER CODE BEGIN OTG_FS_IRQn 0 */
/* USER CODE END OTG_FS_IRQn 0 */
usbd_isr(&cdc_acm);
/* USER CODE BEGIN OTG_FS_IRQn 1 */
/* USER CODE END OTG_FS_IRQn 1 */
}
/**
* @brief The application entry point.
* @retval int
*/
void mian(void)
{
……
MX_USB_OTG_FS_PCD_Init();
usbd_init(&cdc_acm,USB_FS_CORE_ID);
while (usbhs_core_dev.dev.status != USB_STATUS_CONFIGURED) {}
while (1) {
if ((1 == packet_receive) && (1 == packet_sent)) {
packet_sent = 0;
/* receive datas from the host when the last packet datas have sent to the host */
cdc_acm_data_receive(&usbhs_core_dev);
} else {
if (0 != receive_length) {
/* send receive data */
cdc_acm_data_send(&usbhs_core_dev, receive_length);
receive_length = 0;
}
}
}
}
|