windows usb 驱动 DLL APP 框架

windows-x86 这块 做 host
freertos-stm32-usb-msc 这块 做 device
  • 整体框架
python  -> pyusb -> pyusb backend -> usb device

python代码 : 
	https://blog.csdn.net/weixin_42967006/article/details/108755972
	或全局搜索 python代码
	
pyusb的安装
	pip install pyusb

pyusb backend 包括如下 // 现(2021-7-29 14:15:46) 主要由两个组织提供,仅需安装即可
	usb 驱动
		// 安装驱动成功后才能(在设备插入usb时)在设备管理器的通用串行总线控制器中查找到 该设备 
	usb dll
		// 和 usb 驱动进行通信
谁能提供 usb dll 和 usb driver
Cypress 公司
Cypress
	是一个公司 //an Infineon Technologies Company
	
EZ-USB
	是 CyPress 开发的 8051 单片机 的 一个系列名
	参考 https://www.keil.com/dd/chip/3190.htm
	The Cypress EZ-USB (AN21XX) is a High-speed 8051-based USB Device with Two UARTs, Dual DPTRs, 13 Interrupts / 4 Priority Levels, 24 I/O Lines, 3 Timers/Counters, 3.3V Operation, ROMless, 256 Bytes On-chip RAM, and 4K or 8K Bytes XRAM.

CyPress 公司 的USB驱动 有两种
	cyusb.sys 是 新的USB驱动 规范
	ezusb.sys 是很久以前推出的USB驱动规范

cyusb
	是CyPress 公司新的USB驱动规范
	文件包括cyusb.sys和cyusb.inf和cyusb.cat
	sys是驱动程序二进制文件
	inf是驱动程序的配置文件
	cat是驱动程序的数字证书
	其中cyusb.inf文件中没有默认指定任何VID&PID,相关数字都以XXXX代替

Cypress 给开发者提供了什么接口
	1.0 时代
		驱动 : cyusb.sys
	2.0 时代 // Cypress USBSuite
		驱动 : cyusb.sys
		C++  : cyapi.lib // 封装了驱动 
		C# 	 : cyusb.dll // 封装了驱动 
		// C# 不能直接调用 cyapi.lib
		// C++  能直接调用 cyapi.lib 和 cyusb.dll
		// 对于C++ 来说, cyapi.lib 提供 静态链接, cyusb.dll 提供动态链接


Cypress 提供 dll 吗?
	提供,名称叫 CyUSB.dll
	https://www.cypress.com/file/121076/download

EZ-USB FX3 Software Development Kit 
	https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit

Cypress 支持 linux 吗?
	支持 ,在 https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit 中有 SDK "EZ-USB FX3 SDK 1.3.4 for Linux"

libwdi:debug [wdi_create_list] Hardware ID: USB\VID_20B4&PID_0002&REV_0200
libwdi:debug [wdi_create_list] Compatible ID: USB\Class_00&SubClass_06&Prot_50
libwdi:debug [wdi_create_list] Driver version: 1.2.3.14
libwdi:debug [wdi_create_list] CYUSB3 USB device (1): USB\VID_20B4&PID_0002\5&19353383&0&2
libwdi:debug [wdi_create_list] Device description: 'DX1'
zadig 组织
  • 第一种方法
WinUSB(libusb) + libusb // libusb 需要额外安装
	winusb(libusb) 提供 driver
	libusb 提供 dll // https://github.com/libusb/libusb/wiki/Windows
  • 第二种方法
libusb-win32
	提供了 driver 和 dll
  • 第三种方法
libusbK
	提供了 driver 和 dll
调试工具
Bus Hound
非官方的基于tk的pywinusb hid调试工具
zadig

选项框 // More information

WinUSB(libusb) // WinUSB (v6.1.7600.16385)
	// 包括驱动(仅支持NOT HID) // 驱动支持 libusb
	// 不包括 DLL
	libusb-win32 is a Windows only project which provide libusb-0.1 API compatible library for Windows and the associated kernel driver libusb0.sys.


libusb-win32 // libusb-win32 (v1.2.6.0)
	// 包括 驱动(支持HID)和DLL

	To use libusb-win32 in your own programs include the supplied header file usb.h, and link against the import library (libraries for GCC, BCC, and MSVC 32bit/64bit are available).
	To avoid any version conflicts, DO NOT include the DLL libusb0.dll in your application's directory. The DLL is part of the driver and installed automatically to the Windows system directory.


libusbK // libusbK (v3.0.7.0)
	// 包括 驱动(支持HID) 和DLL
	libusbK is a complete driver/library solution for vendor class usb device interfaces. If you are a usb developers or usb device manufacturer seeking a driver solution for a new USB widget then libusbK could be for you.
	libusbK encompasses a 100% WinUSB compatible api/funtion set. All WinUSB power/pipe polices are fully supported by the libusbK driver. In Addition, libusbK has full support for isochronous endpoints and an extensive set of additional modules to simplify development.

	libusbK is a Windows only project which provides a new set of API for Windows (supporting WinUSB, libusb0.sys and libusbk.sys) and kernel driver libusbK.sys.

	libusbK (http://libusbk.sourceforge.net/UsbK3/index.html) is the next-generation libusb-win32 kernel driver and associated library. The kernel driver (libusbK.sys) is based on KMDF and it will work with either libusb-win32 API or native libusbK API. The library (libusbK.dll) works with libusb0.sys, libusbK.sys and winusb.sys . It has dual licenses (Modified BSD and GPL).

	Currently libusbK is under active development. On the other hand, libusb0.sys and libusb-win32 API will still be supported (bug fix mode) even though no new features will be added.


NO 	// WinUSB(Microsoft)
	WinUSB is a generic driver for USB devices that is included with all versions of Windows since Windows Vista. It includes:

	A kernel-mode driver (Winusb.sys)
	A user-mode dynamic link library (Winusb.dll) that exposes WinUSB functions described in winusb.h. You can use these functions to manage USB devices with user-mode software.
	By default, Winusb.sys is installed in the device's kernel-mode stack as an upper filter driver, and apps communicate with the device's UMDF function driver to issue read, write, or device I/O control requests. In this configuration, Winusb.sys serves as the device stack's Plug and Play and power owner.

	Alternatively, you can install Winusb.sys as the function driver for a USB device.

USB Serial (CDC) // NO
	...


参考资料
python代码

#运行以下脚本进行测试
#usb.core.find(idVendor= 0x1908, idProduct= 0x0222)中的
#idVendor和idProduct改成上面查询到的VID和PID:

import usb.core
import usb.util

dev =  usb.core.find(idVendor= 0x1908, idProduct= 0x0222)
if dev is None:
    raise ValueError('Device not found')
print(dev)
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT)
print(ep)
assert ep is not None

# write the data
ep.write('test')
————————————————
版权声明:本文为CSDN博主「老孟(MLY)」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42967006/article/details/108755972
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值