版权声明:本文为CSDN博主「MmikerR」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/MmikerR/article/details/106497732
1 概述
libusb是一个免费的跨平台USB库,本文在windows平台下使用libusb库开发上位机程序与ZYNQ的USB接口进行数据收发测试。libusb可以支持WinUSB驱动,因此为ZYNQ的USB接口设备安装WinUSB驱动。
libusb网址:https://libusb.info/
windows下开发指南:https://github.com/libusb/libusb/wiki/Windows
2 libusb库
在https://libusb.info/可以下载libusb库,目前的最新版本是1.0.23。解压后的目录如下:
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231895-1.png)
使用VS作为上位机驱动的开发环境,因此需要使用MS32或者MS64文件夹下的dll和lib文件。以及include里的头文件。
3 ZYNQ裸机程序设计
PS端的USB接口作为Endpoint Device。设计了3个Endpoint,分别为:
Endpoint 0:control endpoint
Endpoint 1:BULK endpoint
Endpoint 2:interrupt endpoint
分别对应控制传输、块传输和中断传输。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231896-2.png)
USB的PID设为0x0007,PID设为0x0001。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231897-3.png)
设计USB设备的字符串描述。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231898-4.png)
4 上位机测试程序设计
PC机作为HOST,调用libusb的API函数设计上位机程序,分别测试电脑与开发板USB接口之间的BULK和interrupt模式传输速率。实现如下功能:
5 USB驱动安装
安装libusb驱动。使用Zadig软件生产使用WinUSB内核的USB驱动,选择Create New Device。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231899-5.png)
选择advance mode
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231900-6.png)
选择提取驱动文件。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231901-7.png)
输入设备名称ZYNQ USB DEVICE,VID 0x0007,PID0x0001。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231902-8.png)
选择驱动文件提取的存放目录,然后点击Extract Files
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231903-9.png)
完成后,打开驱动文件所在目录,可以找到生成的驱动文件。
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231904-10.png)
对于Win10系统,首先要禁用数字签名。将开发板USB口与电脑连接,将程序通过SDK下载到开发板中,此时电脑设备管理器提示发现新的USB设备。选择设备,安装上述目录下已经生成的USB驱动程序。
6 USB传输速率测试
6.1 BULK模式
6.1.1 PC向ZYNQ单向发送
8字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231905-11.png)
64字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231906-12.png)
256字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231907-13.png)
1024字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231908-14.png)
2048字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231909-15.png)
4096字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231910-16.png)
6.1.2 PC与ZYNQ间数据回环
实际速率需要将图中的速率乘以2倍
8字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231911-17.png)
64字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231912-18.png)
256字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231913-19.png)
1024字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231914-20.png)
2048字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231915-21.png)
4096字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231916-22.png)
6.2 interrupt模式
6.2.1 PC向ZYNQ单向发送数据
8字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231917-23.png)
64字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231918-24.png)
256字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231919-25.png)
1024字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231920-26.png)
2048字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231921-27.png)
4096字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231922-28.png)
6.2.2 PC与ZYNQ间数据回环
实际速率需要将图中的速率乘以2倍
8字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231923-29.png)
64字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231924-30.png)
256字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231925-31.png)
1024字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231926-32.png)
2048字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231927-33.png)
4096字节包
![](http://xilinx.eetrend.com/files/2021-12/%E5%8D%9A%E5%AE%A2/100556402-231928-34.png)