各位大神,我用的是STM32F407,先用CUBMX生成了一个HID设备,然后改成自定义的设备,现在是接收数据正常,发送数据不正常,发送用的是这个函数USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); 接收用的是这个函数USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8); static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) { uint8_t i; USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; if((rxbuff2[0]==0xfe)&&(rxbuff2[1]==0xa1)) { for(i=0;i<8;i++) { rxbuff=rxbuff2; } txbuff2[0]=0xfc; txbuff2[1]=0xa1; txbuff2[2]=0xff; txbuff2[3]=0xff; txbuff2[4]=0xff; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0xff; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x00)) { for(i=0;i<8;i++) { rxbuff[8+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x01; txbuff2[3]=0x00; txbuff2[4]=0x01; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x01)) { for(i=0;i<8;i++) { rxbuff[16+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x02; txbuff2[3]=0x00; txbuff2[4]=0x00; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x02)) { for(i=0;i<8;i++) { rxbuff[24+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x03; txbuff2[3]=0x00; txbuff2[4]=0x02; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x03)) { for(i=0;i<8;i++) { rxbuff[32+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x04; txbuff2[3]=0x09; txbuff2[4]=0x0b; txbuff2[5]=0x03; txbuff2[6]=0x72; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x04)) { for(i=0;i<8;i++) { rxbuff[40+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x05; txbuff2[3]=0x00; txbuff2[4]=0x64; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x05)) { for(i=0;i<8;i++) { rxbuff[48+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x06; txbuff2[3]=0x00; txbuff2[4]=0x00; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfe)&&(rxbuff2[1]==0xa0)) { txbuff2[0]=0xfc; txbuff2[1]=0xa0; txbuff2[2]=0xff; txbuff2[3]=0xff; txbuff2[4]=0xff; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0xff; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } if (pdev->dev_state == USBD_STATE_CONFIGURED ) { while(hhid->state != CUSTOM_HID_IDLE); hhid->state = CUSTOM_HID_BUSY; USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8); } // USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8); // USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; // // ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], // hhid->Report_buf[1]); // // USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf, // USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); return USBD_OK; } 以上是处理过程 只发出一个? |
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40);
评分
查看全部评分
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40);
先用CUBMX生成了一个HID设备,然后改成自定义的设备,
设备描述符 接口描述符 HID描述符 端点描述符之类都是cubemx给你生成的?
评分
查看全部评分
不是,自己在基础上修改的
我现在在用F3做HID双向通信,接收有问题,怀疑还是报告描述符的问题,楼主有代码吗,贴上来