X-024-OHTHERS-在windows平台下使用libusb
作者:wowo 发布于:2017-7-23 22:21 分类:X Project
1. 前言
话说我们“X Project”的第一个任务就是通过USB将主机上的Image文件下载到开发板的Ram中执行(参考[1]中有关的内容),为此我们在host中porting了一个简单的应用程序(称作DFU[2]),负责和开发板ROM中的代码交流,下载并执行Image文件。为了方便,该应用程序使用libusb[3]进行USB有关的操作。
libusb不止使用起来简单,还有一个极大的优点,就是“跨平台”的特性。我们之前的例子[4]都是在Linux平台下操作的,最近由于win10内置了Ubuntu,Linux平台有关的开发工作,基本上都可以在这里完成了,因此就不需要费时、费神地切换到纯Linux环境下工作了。
不过呢,Win10的Ubuntu好是好,但没法像纯Linux系统那样支持USB设备,DFU有关的工作就无法在这里正常工作,因此就发挥libusb的特性,把“X Project” DFU[2]有关的代码在Windows下跑起来,也算感受一下“跨平台”的魅力。具体步骤如下。
2. 步骤
1)安装MinGW[6]
参考[5]中的介绍,libusb在Windows下可以在MinGW环境下编译、使用,因此我们可以按照[7]中的步骤,在Windows中下载并安装MinGW。
2) 编译libusb、dfu,并运行dfu(具体可参考[1]中有关的文章)
发现没有USB的驱动程序(见下面的log):
cd /d/work/xprj/build && make libusb && make dfu
cd /d/work/xprj/tools/dfu && ./dfu.exe bubblegum 0
board_bubblegum_init
board bubblegum
address 0x0
filename (null)
need_run 0
bubblegum_init
b96_init_usb
b96_init_device
libusb: info [windows_get_device_list] The following device has no driver: '\\.\USB#VID_10D6&PID_10D6#5&A3E6D0F&0&3'
libusb: info [windows_get_device_list] libusb will not be able to access it.
Error: cannot open device 10d6:10d6
b96_init_device failed
board->init failed!
3)通过Zadig[8]安装USB的通用驱动
参考[5]中的说明,要在Windows访问USB设备,需要相应的驱动程序,例如WinUSB等,可以使用Zadig[8]工具辅助安装:
https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows
Driver InstallationIf your target device is not HID, you must install a driver before you can communicate with it using libusb. Currently, this means installing one of Microsoft's
WinUSB
, libusb-win32 or libusbK drivers. Two options are available:
- Recommended: Use the most recent version of Zadig, an Automated Driver Installer GUI application for
WinUSB
,libusb-win32
andlibusbK
...- Alternatively, if you are only interested in
WinUSB
, you can download the WinUSB driver files and customize theinf
file for your device.
http://zadig.akeo.ie/
Zadig is a Windows application that installs generic USB drivers, such as WinUSB, libusb-win32/libusb0.sys or libusbK, to help you access USB devices.
Zadig的使用极其简单,通过USB ID确定需要安装驱动的USB设备,然后再右边的列表中选择安装的驱动类型(这里以WinUSB为例),点击“Install Driver”即可,如下图所示:
4)再次运行dfu工具,已经和开发板对上暗号了,成功!!
$ /d/work/xprj/build/../tools/dfu/dfu bubblegum 0xe406b200 /d/work/xprj/build/../tools/actions/splboot.bin 1
board_bubblegum_init
board bubblegum
address 0xe406b200
filename d:/work/xprj/build/../tools/actions/splboot.bin
need_run 1
bubblegum_init
b96_init_usb
b96_init_device
bDescriptorType: 1
bNumConfigurations: 1
iManufacturer: 0
bNumInterfaces: 1
Info: cannot detach kernel driver: LIBUSB_ERROR_NOT_SUPPORTED
Configuiration: 1
Handler: 009AB270
bubblegum_upload, filename d:/work/xprj/build/../tools/actions/splboot.bin, addr 0xe406b200
writeBinaryFile
writeBinaryFileSeek
CBW: 55 53 42 43 00 00 00 00 83 43 00 00 00 00 10 05 00 b2 06 e4 83 43 00 00 00 00 00 00 00 00 00
Bulk transferred 17283 bytes
readCSW
CSW:55 53 42 53 00 00 00 00 00 00 00 00 00
bubblegum_run, addr 0xe406b200
unknownCMD07
CBW: 55 53 42 43 00 00 00 00 00 00 00 00 00 00 00 10 00 b2 06 e4 00 00 00 00 00 00 00 00 00 00 00
Transffered: 31
readCSW
CSW:55 53 42 53 00 00 00 00 00 00 00 00 00
bubblegum_exit
b96_uninit_device
b96_uninit_usb
3. 参考文档
[2] xprj dfu, https://github.com/wowotechX/tools/tree/master/dfu
[3] libusb, http://libusb.info/
[4] X-010-UBOOT-使用booti命令启动kernel(Bubblegum-96平台)
[5] https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows
[6] MinGW, www.mingw.org/
[8] zadig, http://zadig.akeo.ie/
[9] X-002-HW-S900芯片boot from USB有关的硬件描述
原创文章,转发请注明出处。蜗窝科技,www.wowotech.net。
标签: MinGW libusb windows zadig dfu

评论:
功能
最新评论
文章分类
随机文章
文章存档
- 2024年2月(1)
- 2023年5月(1)
- 2022年10月(1)
- 2022年8月(1)
- 2022年6月(1)
- 2022年5月(1)
- 2022年4月(2)
- 2022年2月(2)
- 2021年12月(1)
- 2021年11月(5)
- 2021年7月(1)
- 2021年6月(1)
- 2021年5月(3)
- 2020年3月(3)
- 2020年2月(2)
- 2020年1月(3)
- 2019年12月(3)
- 2019年5月(4)
- 2019年3月(1)
- 2019年1月(3)
- 2018年12月(2)
- 2018年11月(1)
- 2018年10月(2)
- 2018年8月(1)
- 2018年6月(1)
- 2018年5月(1)
- 2018年4月(7)
- 2018年2月(4)
- 2018年1月(5)
- 2017年12月(2)
- 2017年11月(2)
- 2017年10月(1)
- 2017年9月(5)
- 2017年8月(4)
- 2017年7月(4)
- 2017年6月(3)
- 2017年5月(3)
- 2017年4月(1)
- 2017年3月(8)
- 2017年2月(6)
- 2017年1月(5)
- 2016年12月(6)
- 2016年11月(11)
- 2016年10月(9)
- 2016年9月(6)
- 2016年8月(9)
- 2016年7月(5)
- 2016年6月(8)
- 2016年5月(8)
- 2016年4月(7)
- 2016年3月(5)
- 2016年2月(5)
- 2016年1月(6)
- 2015年12月(6)
- 2015年11月(9)
- 2015年10月(9)
- 2015年9月(4)
- 2015年8月(3)
- 2015年7月(7)
- 2015年6月(3)
- 2015年5月(6)
- 2015年4月(9)
- 2015年3月(9)
- 2015年2月(6)
- 2015年1月(6)
- 2014年12月(17)
- 2014年11月(8)
- 2014年10月(9)
- 2014年9月(7)
- 2014年8月(12)
- 2014年7月(6)
- 2014年6月(6)
- 2014年5月(9)
- 2014年4月(9)
- 2014年3月(7)
- 2014年2月(3)
- 2014年1月(4)
2017-07-28 14:37