OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 10323|回复: 7

求助USB HID MaxPacketSize的问题。

[复制链接]

6

主题

14

帖子

0

精华

初级会员

Rank: 2

积分
78
金钱
78
注册时间
2013-6-17
在线时间
4 小时
发表于 2013-7-16 17:06:38 | 显示全部楼层 |阅读模式

我根据范例修改usb_desc.c  .部分内容如下
const u8 CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
  {
    0x09, /* bLength: Configuation Descriptor size */
    USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
    CUSTOMHID_SIZ_CONFIG_DESC,
    /* wTotalLength: Bytes returned */
    0x00,
    0x01,         /* bNumInterfaces: 1 interface */
    0x01,         /* bConfigurationValue: Configuration value */
    0x00,         /* iConfiguration: Index of string descriptor describing
                                 the configuration*/
    0xC0,         /* bmAttributes: Bus powered */
                  /*Bus powered: 7th bit, Self Powered: 6th bit, Remote wakeup: 5th bit, reserved: 4..0 bits */
    0x32,         /* MaxPower 100 mA: this current is used for detecting Vbus */
//    0x96,         /* MaxPower 300 mA: this current is used for detecting Vbus */
    /************** Descriptor of Custom HID interface ****************/
    /* 09 */
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x00,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x02,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0,            /* iInterface: Index of string descriptor */
    /******************** Descriptor of Custom HID HID ********************/
    /* 18 */
    0x09,         /* bLength: HID Descriptor size */
    HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
    0x10,         /* bcdHID: HID Class Spec release number */
    0x01,
    0x00,         /* bCountryCode: Hardware target country */
    0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
    0x22,         /* bDescriptorType */
    CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
    0x00,
    /******************** Descriptor of Custom HID endpoints ******************/
    /* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

    0x82,          /* bEndpointAddress: Endpoint Address (IN) */              
                   // bit 3...0 : the endpoint number
                   // bit 6...4 : reserved
                    // bit 7     : 0(OUT), 1(IN)
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x40,//0x02,          /* wMaxPacketSize: 20 Bytes max */
    0x00,
    //0x20,          /* bInterval: Polling Interval (21 ms) */
 0x0A,          /*bInterval: Polling Interval (10 ms)*/

    /* 34 */
     
    0x07, /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
   /* Endpoint descriptor type */
    0x01, /* bEndpointAddress: */
   /* Endpoint Address (OUT) */
    0x03, /* bmAttributes: Interrupt endpoint */
    0x40,//0x02, /* wMaxPacketSize: 20 Bytes max  */
    0x00,
 //   0x10, /* bInterval: Polling Interval (32 ms) */
 0x0A,          /*bInterval: Polling Interval (10 ms)*/

    /* 41 */
  }
想设置为一包64字节的~用USB调试助手发送 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 到端点2.有中断。void EP1_OUT_Callback(void)
{
     USB_ReceiveFlg = TRUE;
     PMAToUserBufferCopy(Receive_Buffer, ENDP1_RXADDR,60);
     MsgCmd = Receive_Buffer[0];
     SetEPRxStatus(ENDP1, EP_RX_VALID);
}
在这里将缓冲区数据存到Receive_Buffer[64]里。但是在线调试看到的结果是Receive_Buffer[0]到Receive_Buffer[21]的内容是正确的。后面的都乱了~如果我把 wMaxPacketSize的内容改为0x02.则只有Receive_Buffer[0]和Receive_Buffer[1]的数据是对的。。
求解是哪里不对?

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

6

主题

14

帖子

0

精华

初级会员

Rank: 2

积分
78
金钱
78
注册时间
2013-6-17
在线时间
4 小时
 楼主| 发表于 2013-7-16 17:33:27 | 显示全部楼层
@正点原子  求大神拯救
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-7-16 21:17:03 | 显示全部楼层
USB我也不熟啊,呵呵.帮不到你.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

6

主题

14

帖子

0

精华

初级会员

Rank: 2

积分
78
金钱
78
注册时间
2013-6-17
在线时间
4 小时
 楼主| 发表于 2013-7-17 08:45:02 | 显示全部楼层
回复【3楼】正点原子:
---------------------------------
。。。大神竟然会不熟。。。我完了
回复 支持 反对

使用道具 举报

54

主题

537

帖子

0

精华

高级会员

Rank: 4

积分
797
金钱
797
注册时间
2012-2-27
在线时间
7 小时
发表于 2013-7-17 10:13:52 | 显示全部楼层
.h 文件里关于 length 你有没有改啊。
回复 支持 反对

使用道具 举报

54

主题

537

帖子

0

精华

高级会员

Rank: 4

积分
797
金钱
797
注册时间
2012-2-27
在线时间
7 小时
发表于 2013-7-17 10:17:14 | 显示全部楼层
修改endpoint需要在desc文件的CustomHID_ConfigDescriptor以及prop中的reset修改

修改完desc.c中的CustomHID_ReportDescriptor 需要在desc.h中修改#define CUSTOMHID_SIZ_REPORT_DESC
回复 支持 反对

使用道具 举报

6

主题

14

帖子

0

精华

初级会员

Rank: 2

积分
78
金钱
78
注册时间
2013-6-17
在线时间
4 小时
 楼主| 发表于 2013-7-17 11:31:28 | 显示全部楼层
回复【6楼】wwjdwy:
---------------------------------
多谢回复。根据你的提示,修改了CustomHID_ReportDescriptor中的REPORT_COUNT就好了。万分感谢啊
回复 支持 反对

使用道具 举报

0

主题

1

帖子

0

精华

新手入门

积分
21
金钱
21
注册时间
2014-12-17
在线时间
0 小时
发表于 2017-3-8 10:11:19 | 显示全部楼层
0x40,//0x02, /* wMaxPacketSize: 20 Bytes max  */
这个地方我认为有点问题,0x02应该是2bytes才对。
0x40是40bytes
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-10 10:18

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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