打印
[USB接口]

做的USB设备为什么获取不到AUDIO Class Requests

[复制链接]
1222|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
沙发
jinxuan97| | 2019-4-4 09:33 | 只看该作者
log呢?

使用特权

评论回复
板凳
xuqingli123|  楼主 | 2019-4-4 11:04 | 只看该作者
本帖最后由 xuqingli123 于 2019-4-4 11:12 编辑

log是什么?上面附件里面使用BUSHOUND抓的包,可以看出来不对,但是不知道怎么修改,用DEBUG看了一下,  case USB_REQ_TYPE_CLASS :
    switch (req->bRequest)
    {
    case AUDIO_REQ_GET_CUR:
      AUDIO_Req_GetCurrent(pdev, req);
      break;

    case AUDIO_REQ_SET_CUR:
      AUDIO_Req_SetCurrent(pdev, req);
      break;
        
                case AUDIO_REQ_GET_MIN:
                                USBD_CtlSendData(pdev, (uint8_t *)&VOL_MIN, req->wLength);
                                break;
                case AUDIO_REQ_GET_MAX:
                                USBD_CtlSendData(pdev, (uint8_t *)&VOL_MAX, req->wLength);
                                break;
                case AUDIO_REQ_GET_RES:
                                USBD_CtlSendData(pdev, (uint8_t *)&VOL_RES, req->wLength);
                                break;               
    default:
      USBD_CtlError (pdev, req);
      return USBD_FAIL;
    }
    break;
这段程序是不运行的。不知道怎么解决?大佬给支个招,对于USB里面的一些配置不太懂,找不出来问题出在哪?到最后显示驱动安装不成功,但是设备的PID,VID在电脑上面都是可以正常找到的,难道是我的配置描述符错了吗?下面是配置描述符:
  /* Configuration 1 */
  0x09,                                 /* bLength */
  0x02,                                 /* bDescriptorType */
  LOBYTE(AUDIO_CONFIG_DESC_SIZE),       /* wTotalLength */
  HIBYTE(AUDIO_CONFIG_DESC_SIZE),      
  0x02,                                 /* bNumInterfaces */
  0x01,                                 /* bConfigurationValue */
  0x00,                                 /* iConfiguration */
  0xC0,                                 /* bmAttributes BUS Powered*/
  0x32,                                 /* bMaxPower = 100 mA*/
  /* 09 byte*/

  0x08,
  0x0B,
  0x00,
  0x02,
  0x01,
  0x00,
  0x20,
  0x00,
  /* 08 byte */

  /* Standard AC Interface Descriptor */
  0x09,                                 /* bLength */
  0x04,                                 /* bDescriptorType */
  0x00,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x01,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* Class-specific AC Interface Descriptor */
  0x09,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x00,                                 /* bcdADC */
  0x02,                                 /* 2.00 */
  0x01,                                 /* bCategory */
  0x48,                                 /* wTotalLength */
  0x00,
  0x00,                                 /* bmControls */
  /* 09 byte*/

  /* USB HeadSet Clock Source Descriptor */
  0x08,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x0A,                                 /* bDescriptorSubtype */
  0x04,                                 /* bClockID */
  0x03,                                 /* bmAttributes */
  0x07,                                 /* bmControls TODO */
  0x00,                                 /* bAssocTerminal */
  0x00,                                 /* iClockSource */
  /* 08 byte*/

  /* USB HeadSet Input Terminal Descriptor */
  0x11,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType AUDIO_TERMINAL_USB_STREAMING   0x0201 */
  0x01,
  0x00,                                 /* bAssocTerminal */
  0x04,                                 /* bCSourceID*/
  0x02,                                 /* bNrChannels */
  0x03,                                 /* wChannelConfig 0x00000003  Stereo */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 17 byte*/

  /* USB HeadSet Audio Feature Unit Descriptor */
  0x12,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x06,                                 /* bDescriptorSubtype */
  0x02,                                 /* bUnitID */
  0x01,                                 /* bSourceID */
  AUDIO_20_CTL_MUTE(CONTROL_BITMAP_PROG)/* bmaControls(0) */
  | AUDIO_20_CTL_VOLUME(CONTROL_BITMAP_PROG),
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(1) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(2) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iFeature */
  /* 18 byte*/

  /*USB HeadSet Output Terminal Descriptor */
  0x0C,                                                    /* bLength */
  0x24,                                 /* bDescriptorType */
  0x03,                                 /* bDescriptorSubtype */
  0x03,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType  0x0301: Speaker, 0x0302: Headphone*/
  0x03,
  0x00,                                 /* bAssocTerminal */
  0x02,                                 /* bSourceID */
  0x04,                                 /* bCSourceID */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 12 byte*/

  /* USB HeadSet Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */
  /* Interface 1, Alternate Setting 0                                              */
  9,                                                      /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
  /* Interface 1, Alternate Setting 1                                           */
  9,                                                      /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB HeadSet Audio Streaming Interface Descriptor */
  0x10,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x01,                                 /* 0x01: bTerminalLink */
  0x00,                                 /* bmControls */
  0x01,                                 /* bFormatType */
  0x01,                                 /* bmFormats PCM */
  0x00,
  0x00,
  0x00,
  0x02,                                 /* bNrChannels */
  0x03,                                 /* bmChannelConfig */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  /* 16 byte*/

  /* USB Speaker Audio Type I Format Interface Descriptor */
  0x09,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bFormatType */
  0x02,                                 /* bSubslotSize */
  16,                                   /* bBitResolution */
  /* 6 byte*/

  /* Endpoint 1 - Standard Descriptor */
  0x07,                                /* bLength */
  0x05,                                /* bDescriptorType */
  0x03,                                /* bEndpointAddress 3 out endpoint for Audio */
  0x09,                                /* bmAttributes */
  AUDIO_PACKET_SZE(USBD_AUDIO_FREQ),   /* XXXX wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
  0x01,                                /* bInterval */
  /* 07 byte*/

  /* Endpoint - Audio Streaming Descriptor*/
  0x08,                                 /* bLength */
  0x25,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bmControls */
  0x00,                                 /* bLockDelayUnits */
  0x00,                                 /* wLockDelay */
  0x00
  /* 08 byte*/

使用特权

评论回复
地板
zhs2007| | 2019-4-4 13:35 | 只看该作者
最好用硬件分析仪抓下包,看下异常通信的交互细节,有什么问题就一目了然了,BUSHOUND抓不到令牌包,握手包等细节。

使用特权

评论回复
5
xuqingli123|  楼主 | 2019-4-11 08:11 | 只看该作者

把全速改成高速要定义 #define USB_OTG_HS_INTERNAL_DMA_ENABLED,但是定义它之后,
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED   
    pdev->cfg.dma_enable       = 1;   
#endif
往里面写数据的函数判断条件就会不成立
USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev,
                                uint8_t             *src,
                                uint8_t             ch_ep_num,
                                uint16_t            len)
{
  USB_OTG_STS status = USB_OTG_OK;
  if (pdev->cfg.dma_enable == 0)
  {
    uint32_t count32b= 0 , i= 0;
    __IO uint32_t *fifo;
   
    count32b =  (len + 3) / 4;
    fifo = pdev->regs.DFIFO[ch_ep_num];
    for (i = 0; i < count32b; i++)
    {
      USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
      src+=4;
    }
  }
  return status;
}如果把if (pdev->cfg.dma_enable == 0)改成等于1条件成立,就枚举不出来,然后看了一下是USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );导致的,大佬,这是什么原因能给说一下吗?求!

使用特权

评论回复
6
jinxuan97| | 2019-4-11 10:07 | 只看该作者
问题似乎在GET_DESCRIPTOR, CONFIGURATION 失败! 枚举应该还没有成功...

使用特权

评论回复
7
xuqingli123|  楼主 | 2019-4-11 10:23 | 只看该作者
本帖最后由 xuqingli123 于 2019-4-11 15:39 编辑
jinxuan97 发表于 2019-4-11 10:07
问题似乎在GET_DESCRIPTOR, CONFIGURATION 失败! 枚举应该还没有成功...

应该是你说的问题,但是我描述符都配置正确了啊,  if (pdev->cfg.dma_enable == 1)  {
    uint32_t count32b= 0 , i= 0;
    __IO uint32_t *fifo;

    count32b =  (len + 3) / 4;
    fifo = pdev->regs.DFIFO[ch_ep_num];
    for (i = 0; i < count32b; i++)
    {
      USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
      src+=4;
    }
  }

这是我把判断条件改成1后然后枚举出错,用BUSHOUND看了一下就是这样的了

QQ截图20190411153813.png (80.5 KB )

QQ截图20190411153813.png

使用特权

评论回复
8
xuqingli123|  楼主 | 2019-4-11 13:49 | 只看该作者
jinxuan97 发表于 2019-4-11 10:07
问题似乎在GET_DESCRIPTOR, CONFIGURATION 失败! 枚举应该还没有成功...

但是如果定义 #define USB_OTG_HS_INTERNAL_DMA_ENABLED,但是定义它之后,
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED   
    pdev->cfg.dma_enable       = 1;   
#endif
把pdev->cfg.dma_enable       = 1; 然后后面传输数据要pdev->cfg.dma_enable       = 0才能进入传输,我看了一下程序,等于1之后,后面就没有程序再把pdev->cfg.dma_enable等于0了,这样就进不符合判断条件了

使用特权

评论回复
9
qinchxiong| | 2019-8-6 11:48 | 只看该作者
楼主,遇到一样的问题,指导一下

使用特权

评论回复
10
xuqingli123|  楼主 | 2019-8-7 09:18 | 只看该作者
qinchxiong 发表于 2019-8-6 11:48
楼主,遇到一样的问题,指导一下

我这个做的是USB AUDIO2.0,刚开始是在WIN7上面枚举的,所以出现了这种情况,因为WIN7不支持USB AUDIO2.0,后来换到WIN10上面就可以了。

使用特权

评论回复
11
qinchxiong| | 2019-8-7 10:21 | 只看该作者
xuqingli123 发表于 2019-8-7 09:18
我这个做的是USB AUDIO2.0,刚开始是在WIN7上面枚举的,所以出现了这种情况,因为WIN7不支持USB AUDIO2.0 ...

https://bbs.21ic.com/icview-2754794-1-1.html     我看到楼主这个帖子,专门枚举扬声器的是可以枚举出来的,除了win系统外,是不是描述符有细节要改

使用特权

评论回复
12
xuqingli123|  楼主 | 2019-8-7 13:32 | 只看该作者
本帖最后由 xuqingli123 于 2019-8-7 13:49 编辑
qinchxiong 发表于 2019-8-7 10:21
https://bbs.21ic.com/icview-2754794-1-1.html     我看到楼主这个帖子,专门枚举扬声器的是可以枚举出来 ...

你可以参考一下正点原子里面的例程,探索者407里面就有声卡,扬声器的你可以看下        /* Configuration 1 */
  0x09,                                 /* bLength */
  0x02,                                 /* bDescriptorType */
  LOBYTE(AUDIO_CONFIG_DESC_SIZE),       /* wTotalLength  109 bytes*/
  HIBYTE(AUDIO_CONFIG_DESC_SIZE),      
  0x02,                                 /* bNumInterfaces */
  0x01,                                 /* bConfigurationValue */
  0x00,                                 /* iConfiguration */
  0xC0,                                 /* bmAttributes  BUS Powred*/
  0x32,                                 /* bMaxPower = 100 mA*/
  /* 09 byte*/

  /* USB Speaker Standard interface descriptor */
  0x09,                                 /* bLength */
  0x04,                                 /* bDescriptorType */
  0x00,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x01,                                 /* bInterfaceSubClass */
  0x00,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB Speaker Class-specific AC Interface Descriptor */
  0x09,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x00,           /* 1.00 */            /* bcdADC */
  0x01,
  0x27,                                 /* wTotalLength = 39*/
  0x00,
  0x01,                                 /* bInCollection */
  0x01,                                 /* baInterfaceNr */
  /* 09 byte*/

  /* USB Speaker Input Terminal Descriptor */
  0x0c,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType AUDIO_TERMINAL_USB_STREAMING   0x0101 */
  0x01,
  0x00,                                 /* bAssocTerminal */
  0x02,                                 /* bNrChannels */
  0x03,                                 /* wChannelConfig 0x0000  Mono */
  0x00,
  0x00,                                 /* iChannelNames */
  0x00,                                 /* iTerminal */
  /* 12 byte*/

  /* USB Speaker Audio Feature Unit Descriptor */
  0x09,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x06,                                 /* bDescriptorSubtype */
  0x02,                                 /* bUnitID */
  0x01,                                 /* bSourceID */
  0x01,                                 /* bControlSize */
  0x01,                                 /* bmaControls(0) */
  0x00,                                 /* bmaControls(1) */
  0x00,                                 /* iTerminal */
  /* 09 byte*/

  /*USB Speaker Output Terminal Descriptor */
  0x09,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x03,                                 /* bDescriptorSubtype */
  0x03,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType  0x0301*/
  0x03,
  0x00,                                 /* bAssocTerminal */
  0x02,                                 /* bSourceID */
  0x00,                                 /* iTerminal */
  /* 09 byte*/

  /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
  /* Interface 1, Alternate Setting 0                                             */
  0x09,                                 /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x00,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
  /* Interface 1, Alternate Setting 1                                           */
  0x09,                                 /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x00,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB Speaker Audio Streaming Interface Descriptor */
  0x07,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x01,                                 /* bTerminalLink */
  0x01,                                 /* bDelay */
  0x01,                                 /* wFormatTag AUDIO_FORMAT_PCM  0x0001*/
  0x00,
  /* 07 byte*/

  /* USB Speaker Audio Type III Format Interface Descriptor */
  0x0B,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x03,                                 /* bFormatType */
  0x02,                                 /* bNrChannels */
  0x02,                                 /* bSubFrameSize :  2 Bytes per frame (16bits) */
  16,                                   /* bBitResolution (16-bits per sample) */
  0x01,                                 /* bSamFreqType only one frequency supported */
  SAMPLE_FREQ(USBD_AUDIO_FREQ),         /* Audio sampling frequency coded on 3 bytes */
  /* 11 byte*/

  /* Endpoint 1 - Standard Descriptor */
  0x09,                                 /* bLength */
  0x05,                                 /* bDescriptorType */
  0x01,                                 /* bEndpointAddress 1 out endpoint*/
  0x01,                                 /* bmAttributes */
  AUDIO_PACKET_SZE(USBD_AUDIO_FREQ),    /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
  0x01,                                 /* bInterval */
  0x00,                                 /* bRefresh */
  0x00,                                 /* bSynchAddress */
  /* 09 byte*/

  /* Endpoint - Audio Streaming Descriptor*/
  0x07,                                 /* bLength */
  0x25,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bLockDelayUnits */
  0x00,                                 /* wLockDelay */
  0x00,
  /* 07 byte*/ 这是我用的扬声器的描述符,可能有不对的地方吧,但是可以枚举出来的,你可以拿过去试一下,我在WIN7和WIN10上面都是可以正常枚举出来的



使用特权

评论回复
13
xuqingli123|  楼主 | 2019-8-7 13:51 | 只看该作者
qinchxiong 发表于 2019-8-7 10:21
https://bbs.21ic.com/icview-2754794-1-1.html     我看到楼主这个帖子,专门枚举扬声器的是可以枚举出来 ...

我看了你的帖子,你可以先分开枚举,看看各自都是否能枚举出来,然后在复合在一起。

使用特权

评论回复
14
qinchxiong| | 2019-8-7 17:31 | 只看该作者
xuqingli123 发表于 2019-8-7 13:51
我看了你的帖子,你可以先分开枚举,看看各自都是否能枚举出来,然后在复合在一起。 ...

我是在分开枚举均测试正常后做的复合设备

使用特权

评论回复
15
qinchxiong| | 2019-8-7 17:38 | 只看该作者
本帖最后由 qinchxiong 于 2019-8-7 17:40 编辑
qinchxiong 发表于 2019-8-7 17:31
我是在分开枚举均测试正常后做的复合设备

##

使用特权

评论回复
16
qinchxiong| | 2019-8-7 17:40 | 只看该作者
xuqingli123 发表于 2019-8-7 13:51
我看了你的帖子,你可以先分开枚举,看看各自都是否能枚举出来,然后在复合在一起。 ...

楼主方便留个联系方式请教一下吗?我的QQ是895047269

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

29

主题

174

帖子

2

粉丝