野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11499|回复: 3

STM32 USB口高速数据传输

[复制链接]
发表于 2016-3-31 11:14:09 | 显示全部楼层 |阅读模式
最近在做stm32相关USB口的数据传输,之前使用自定义的Bulk模式下,数据发送和接收速度在本人WIN7电脑上可达到300KB/s的速度,但是看网上说是可以达到500-700KB/s。
程序上位机使用的libusb库,下位机STM32f103VE,没有采用双缓冲。求论坛大神指导,希望速度能达到500KB/s左右。
回复

使用道具 举报

 楼主| 发表于 2016-3-31 11:17:11 | 显示全部楼层
USB驱动描述
  1. const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =
  2. {
  3.     0x12,                       /*bLength */
  4.     USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
  5.     0x00,                       /*bcdUSB */
  6.     0x02,
  7.     0x00,                       /*bDeviceClass*/
  8.     0x00,                       /*bDeviceSubClass*/
  9.     0x00,                       /*bDeviceProtocol*/
  10.     0x40,                       /*bMaxPacketSize40*/
  11.     LOBYTE(USBD_VID),           /*idVendor*/
  12.     HIBYTE(USBD_VID),           /*idVendor*/
  13.     LOBYTE(USBD_PID),           /*idVendor*/
  14.     HIBYTE(USBD_PID),           /*idVendor*/
  15.     0x00,                       /*bcdDevice rel. 2.00*/
  16.     0x02,
  17.     1,                          /*Index of string descriptor describing manufacturer */
  18.     2,                          /*Index of string descriptor describing product*/
  19.     3,                          /*Index of string descriptor describing the device serial number */
  20.     0x01                        /*bNumConfigurations*/
  21. }; /* CustomHID_DeviceDescriptor */
复制代码

  1. const uint8_t CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
  2. {
  3.     0x09, /* bLength: Configuation Descriptor size */
  4.     USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
  5.     CUSTOMHID_SIZ_CONFIG_DESC,
  6.     /* wTotalLength: Bytes returned */
  7.     0x00,
  8.     0x01,         /* bNumInterfaces: 1 interface */
  9.     0x01,         /* bConfigurationValue: Configuration value */
  10.     0x00,         /* iConfiguration: Index of string descriptor describing
  11.                                  the configuration*/
  12.     0xE0,         /* bmAttributes: Bus powered */
  13.                   /*Bus powered: 7th bit, Self Powered: 6th bit, Remote wakeup: 5th bit, reserved: 4..0 bits */
  14.     0xFA,         /* MaxPower 500 mA: this current is used for detecting Vbus */
  15.     /************** Descriptor of Custom HID interface ****************/
  16.     /* 09 */
  17.     0x09,         /* bLength: Interface Descriptor size */
  18.     USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
  19.     0x00,         /* bInterfaceNumber: Number of Interface */
  20.     0x00,         /* bAlternateSetting: Alternate setting */
  21.     0x04,         /* bNumEndpoints */
  22.     0xDC,         /* bInterfaceClass: Class code = 0DCH */
  23.     0xA0,         /* bInterfaceSubClass : Subclass code = 0A0H */
  24.     0xB0,         /* nInterfaceProtocol : Protocol code = 0B0H */
  25.     0,            /* iInterface: Index of string descriptor */
  26.     /******************** endpoint descriptor ********************/
  27.     /* 18 */
  28.     0x07,         /* endpoint descriptor length = 07H */
  29.     USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
  30.     0x81,         /* endpoint 1 IN */
  31.     0x02,                                        /* bulk transfer = 02H */
  32.     0x40,0x00,    /* endpoint max packet size = 0040H */
  33.     0x00,         /* the value is invalid when bulk transfer */

  34.     0x07,         /* endpoint descriptor length = 07H */
  35.     USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
  36.     0x01,         /* endpoint 1 OUT */
  37.     0x02,                                        /* bulk transfer = 02H */
  38.     0x40,0x00,    /* endpoint max packet size = 0040H */
  39.     0x00,         /* the value is invalid when bulk transfer */
  40.                
  41.     0x07,         /* endpoint descriptor length = 07H */
  42.     USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
  43.     0x82,         /* endpoint 2 IN */
  44.     0x02,                                        /* bulk transfer = 02H */
  45.     0x40,0x00,    /* endpoint max packet size = 0040H */
  46.     0x00,         /* the value is invalid when bulk transfer */
  47.                
  48.     0x07,         /* endpoint descriptor length = 07H */
  49.     USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
  50.     0x02,         /* endpoint 2 OUT */
  51.     0x02,                                        /* bulk transfer = 02H */
  52.     0x40,0x00,    /* endpoint max packet size = 0040H */
  53.     0x00,         /* the value is invalid when bulk transfer */
  54. }; /* CustomHID_ConfigDescriptor */
复制代码

下位机接收中断
  1. void EP1_OUT_Callback(void)
  2. {
  3.         EP1_ReceivedCount = GetEPRxCount(ENDP1);
  4.         PMAToUserBufferCopy(USB_Receive_Buffer, ENDP1_RXADDR, EP1_ReceivedCount);
  5.         SetEPRxStatus(ENDP1, EP_RX_VALID);
  6. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2016-3-31 11:36:24 | 显示全部楼层
估计要使用高速phy才可以吧
F1不支持高速phy
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-31 11:40:31 | 显示全部楼层
flyleaf 发表于 2016-3-31 11:36
估计要使用高速phy才可以吧
F1不支持高速phy

暂时我硬件不支持,能否在不使用高速phy的情况下,
1、速度达到最高,
2、最高能否到500KB/s。
3、在软件层面使用双缓冲的必要性大不大
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-20 11:44 , Processed in 0.036125 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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