学前班
最后登录1970-1-1
在线时间 小时
注册时间2017-7-22
|
如题,stm32f407 移植了F4鼠标键盘实验例程驱动HOTAS Warthog一套游戏手柄,添加代码(其他代码未动)如下:
else if(pphost->device_prop.Itf_Desc[0].bInterfaceSubClass==0X00)//×Ô¶¨òåHIDé豸
{
//×Ô¶¨òåD-òé £¬Ö§3ÖóÎÏ·êÖ±ú
if(pphost->device_prop.Itf_Desc[0].bInterfaceProtocol == 0X00)
{
HID_Machine.cb = &HID_GAMEDIR_cb;//óÎÏ·êÖ±ú
}
HID_Machine.state = HID_IDLE;
HID_Machine.ctl_state = HID_REQ_IDLE;
HID_Machine.ep_addr = pphost->device_prop.Ep_Desc[0][0].bEndpointAddress;
HID_Machine.length = pphost->device_prop.Ep_Desc[0][0].wMaxPacketSize;
HID_Machine.poll = pphost->device_prop.Ep_Desc[0][0].bInterval ;
if (HID_Machine.poll < HID_MIN_POLL)
{
HID_Machine.poll = HID_MIN_POLL;
}
/* Check fo available number of endpoints ¼ì2é¿éóöËμãêy*/
/* Find the number of EPs in the Interface Descriptor 2éÕò½ó¿úÃèêö·ûÖDμÄEPêyá¿*/
/* Choose the lower number in order not to overrun the buffer allocated Ñ¡Ôñ½ÏμíμÄêyá¿òÔÃa3¬1y·ÖÅäμÄ»o3åÇø*/
maxEP = ( (pphost->device_prop.Itf_Desc[0].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ?
pphost->device_prop.Itf_Desc[0].bNumEndpoints :
USBH_MAX_NUM_ENDPOINTS);
/* Decode endpoint IN and OUT address from interface descriptor */
for (num=0; num < maxEP; num++)
{
printf("Ep_Desc[0][%d]:%x",num,pphost->device_prop.Ep_Desc[0][num].bEndpointAddress);
if(pphost->device_prop.Ep_Desc[0][num].bEndpointAddress & 0x80)
{
HID_Machine.HIDIntInEp = (pphost->device_prop.Ep_Desc[0][num].bEndpointAddress);
HID_Machine.hc_num_in = USBH_Alloc_Channel(pdev, pphost->device_prop.Ep_Desc[0][num].bEndpointAddress);
printf("hc_num_in:%x",HID_Machine.hc_num_in);
/* Open channel for IN endpoint */
USBH_Open_Channel (pdev,
HID_Machine.hc_num_in,
pphost->device_prop.address,
pphost->device_prop.speed,
EP_TYPE_INTR,
HID_Machine.length);
}
else
{
HID_Machine.HIDIntOutEp = (pphost->device_prop.Ep_Desc[0][num].bEndpointAddress);
HID_Machine.hc_num_out = USBH_Alloc_Channel(pdev, pphost->device_prop.Ep_Desc[0][num].bEndpointAddress);
printf(" hc_num_out:%x ",HID_Machine.hc_num_out);
/* Open channel for OUT endpoint */
USBH_Open_Channel (pdev,
HID_Machine.hc_num_out,
pphost->device_prop.address,
pphost->device_prop.speed,
EP_TYPE_INTR,
HID_Machine.length);
}
}
start_toggle =0;
status = USBH_OK;
}
一个驱动成功,如下图:
另一个则,枚举通过了,但是获得不到数据,如下图:
通过调试发现问题:
static uint32_t USB_OTG_USBH_handle_hc_ISR (USB_OTG_CORE_HANDLE *pdev)
{
USB_OTG_HAINT_TypeDef haint;
USB_OTG_HCCHAR_TypeDef hcchar;
uint32_t i = 0;
uint32_t retval = 0;
/* Clear appropriate bits in HCINTn to clear the interrupt bit in
* GINTSTS */
haint.d32 = USB_OTG_ReadHostAllChannels_intr(pdev);
for (i = 0; i < pdev->cfg.host_channels ; i++)
{
if (haint.b.chint & (1 << i))
{
hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS->HCCHAR);
if (hcchar.b.epdir) //Ö¸ê¾ê¼têÇêäèë»1êÇêä3ö
{
retval |= USB_OTG_USBH_handle_hc_n_In_ISR (pdev, i);
}
else
{
retval |= USB_OTG_USBH_handle_hc_n_Out_ISR (pdev, i);
}
}
}
return retval;
}
总是进USB_OTG_USBH_handle_hc_n_In_ISR 中断中的
else if (hcint.b.datatglerr)
{
UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , nak);
pdev->host.HC_Status[num] = HC_DATATGLERR;
CLEAR_HC_INT(hcreg , datatglerr);
}
也就是OTG_HS 主机通道 x 中断寄存器 (OTG_HS_HCINTx)的位 10 DTERR: 数据同步错误 (Data toggle error)
由于对USB协议还不是特别熟,网上尚未查到此错误缘由。还望大神们告知问题之处,不胜感激。。。
|
|