[STM32F1] STM32全速USB BULK通讯,把最大包设置成128B竟然可以成功

[复制链接]
5136|5
 楼主| xiaoergao 发表于 2015-9-9 20:05 | 显示全部楼层 |阅读模式
本帖最后由 xiaoergao 于 2015-9-9 20:07 编辑

看USB协议说全速通讯BULK最大包是64Byte,但是突然心血来潮试了一下128byte的设定。居然通讯成功。
先上图。 1.png

可以确定不是驱动导致的抓了2次数据包合并的。

在ENDPOINT1 回调函数中是这样定义的。
  1. void EP1_IN_Callback (void)
  2. {
  3.         int i=0;
  4.         for(i=0;i<1024;i++) buf[i] = flag;
  5.         UserToPMABufferCopy(buf, ENDP1_TXADDR, 128);
  6.         SetEPTxCount(ENDP1, 128);
  7.         SetEPTxValid(ENDP1);
  8.         printf("%d\r\n",flag);
  9.         flag++;
  10. }


描述符是这样:(只修改了ENDPOINT1 IN的最大包数)
  1. /* USB Standard Device Descriptor */
  2. const uint8_t Virtual_Com_Port_DeviceDescriptor[] =
  3.   {
  4.     0x12,   /* bLength */
  5.     USB_DEVICE_DESCRIPTOR_TYPE,     /* bDescriptorType   01*/
  6.     0x10,
  7.     0x01,   /* bcdUSB = 2.00 /
  8.                 0xd0,   /* 测试设备/
  9.     0x00,   /* bDeviceSubClass */
  10.     0x00,   /* bDeviceProtocol */
  11.                
  12.     0x40,   /* bMaxPacketSize0 */
  13.     0x83,
  14.     0x04,   /* idVendor = 0x0483 */
  15.     0x40,
  16.     0x57,   /* idProduct = 0x5740 */
  17.     0x00,
  18.     0x01,   /* bcdDevice = 2.00 */
  19.     0,              /* Index of string descriptor describing manufacturer */
  20.     0,              /* Index of string descriptor describing product */
  21.     0,              /* Index of string descriptor describing the device's serial number */
  22.     0x01    /* bNumConfigurations */
  23.   };

  24. const uint8_t Virtual_Com_Port_ConfigDescriptor[] =
  25.   {
  26.     /*Configuration Descriptor*/
  27.     0x09,   /* bLength: Configuration Descriptor size */
  28.     USB_CONFIGURATION_DESCRIPTOR_TYPE,      /* bDescriptorType: Configuration */
  29.                 VIRTUAL_COM_PORT_SIZ_CONFIG_DESC,       /* wTotalLength:no of returned bytes *///ÃèÊö·û×ܳ¤¶È
  30.                 0x00,
  31.     0x01,   /* bNumInterfaces: 2 interface */
  32.     0x01,   /* bConfigurationValue: Configuration value */
  33.     0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
  34.     0x60,   /* bmAttributes: self powered */
  35.     0x32,   /* MaxPower 0 mA */
  36.                
  37.                
  38.     /*Interface Descriptor*/
  39.     0x09,   /* bLength: Interface Descriptor size */
  40.     0x04,  /* bDescriptorType: Interface */
  41.     /* Interface descriptor type */
  42.     0x00,   /* bInterfaceNumber: Number of Interface */
  43.     0x00,   /* bAlternateSetting: Alternate setting */
  44. 0x02,   /* bNumEndpoints: One endpoints used *///¶ËµãÊý
  45. 0xdc,   /* bInterfaceClass: Communication Interface Class²âÊÔÉ豸ÀàÐÍ */
  46. 0xa0,   /* bInterfaceSubClass: Abstract Control Model */
  47. 0xb0,   /* bInterfaceProtocol: Common AT commands */
  48.     0x00,   /* iInterface: */
  49.                
  50.                
  51.                
  52.     /*Endpoint 1 Descriptor*/
  53.     0x07,   /* bLength: Endpoint Descriptor size */
  54.     0x05,   /* bDescriptorType: Endpoint */
  55. 0x81,   /* bEndpointAddress: (IN1) */
  56. 0x02,   /* bmAttributes: Bulk */
  57. 0x80,             /* wMaxPacketSize: */
  58.     0x00,
  59.     0x00,    /* bInterval */               
  60.                
  61.                
  62.                
  63.     /*Endpoint 3 Descriptor*/
  64.     0x07,   /* bLength: Endpoint Descriptor size */
  65.     0x05,   /* bDescriptorType: Endpoint */
  66. 0x02,   /* bEndpointAddress: (OUT2) */
  67. 0x02,   /* bmAttributes: Bulk */
  68.     0x40,             /* wMaxPacketSize: */
  69.     0x00,
  70.     0x00   /* bInterval: ignore for Bulk transfer */



  71.   };
到底是怎么回事,望高手答疑。
 楼主| xiaoergao 发表于 2015-9-9 20:17 | 显示全部楼层
补一张抓包的截图 2.png

想做大牛的小马 发表于 2015-11-6 14:21 | 显示全部楼层
full speed协议是64字节,这肯定是没有问题的,我觉得楼主这样可以是因为usb模块有缓冲,实际还是按照64bytes每个packet发出去的,
请问可以看到时间吗,包发出的时间
icecut 发表于 2015-11-6 14:28 | 显示全部楼层
必须是64字节一包发的.pc 端驱动发现你设置错了.就会自动给你改成64.然后按64读.设备端是可以计数128的.当然,你这么算只是硬件容错范围.你应该用协议分析仪看.bushond 不行.不能证明正确
huangqi412 发表于 2015-11-6 15:11 | 显示全部楼层
填充1-128试试
leonliu_1128 发表于 2015-11-9 13:49 | 显示全部楼层
用beagle看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

5

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部