野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11022|回复: 1

USB_HOST + 游戏手柄 一个成功了,一个枚举通过但获得不到数据。。。

[复制链接]
发表于 2017-7-22 09:25:37 | 显示全部楼层 |阅读模式
如题,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 &#188;ì2é&#191;éó&#195;&#182;&#203;μ&#227;êy*/
                        /* Find the number of EPs in the Interface Descriptor 2é&#213;ò&#189;ó&#191;ú&#195;èê&#246;·&#251;&#214;Dμ&#196;EPêyá&#191;*/     
                        /* Choose the lower number in order not to overrun the buffer allocated &#209;&#161;&#212;&#241;&#189;&#207;μíμ&#196;êyá&#191;ò&#212;&#195;a3&#172;1y·&#214;&#197;&#228;μ&#196;&#187;o3&#229;&#199;&#248;*/
                        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) //&#214;&#184;ê&#190;ê&#194;&#188;tê&#199;ê&#228;è&#235;&#187;1ê&#199;ê&#228;3&#246;
      {
        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协议还不是特别熟,网上尚未查到此错误缘由。还望大神们告知问题之处,不胜感激。。。
回复

使用道具 举报

 楼主| 发表于 2017-7-22 09:30:10 | 显示全部楼层
奇怪为什么图片上传不了,补发个成功的 下载.jpg QQ图片20170722090144.png 。。。。。。。。。。驱动失败的 6.jpg QQ图片20170722091126.png
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-30 02:11 , Processed in 0.049519 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表