我是否需要为CDC设备编写自己的主机侧USB驱动程序 [英] Do I need to write my own host side USB driver for a CDC device

查看:192
本文介绍了我是否需要为CDC设备编写自己的主机侧USB驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能不被认为与编程直接相关,但是我不知所措.我曾尝试查看各种网站,但到目前为止Google并不是我的朋友.

我很难确定是否需要为正在开发的设备所连接的各种Windows/linux/mac平台编写自己的设备驱动程序,或者功能是否由标准驱动程序提供. /p>

我的设备是USB CDC(通信设备),显示为COM:端口.它还包括一个电池充电器,一旦对设备进行了枚举,就需要从USB连接器汲取的5单位负载(500mA)的全部供电电流.我的问题是,如果主机中的USB驱动程序决定无法提供完整的电源电流,那么它将无法枚举设备.

如果作为备用,我提供了第二个配置集,该配置集仅允许设备从接口连接器汲取1单位负载,则标准驱动程序将使用此配置来枚举设备.

解决方案

您需要为Windows编写一个.inf文件,该文件将设备的VID和PID与系统usbser.sys联系起来.我的看起来像这样(根据需要替换YourCompany,输入您的VID和PID(以十六进制表示),并将DriverVer行更改为所需的任何日期和版本):

; -----------------------------------------------------------------------------
; XP/2000 USB Comms Port Setup
; -----------------------------------------------------------------------------

[Version] 
DriverVer=12/03/2008,1.0.0000.0000
Signature="$Windows NT$"
Class=Ports 
ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} 
Provider=%YourCompany% 

[DestinationDirs]
DefaultDestDir=10,system32\drivers
DriverCopyFiles=12

[ControlFlags]
ExcludeFromSelect = *

[Manufacturer] 
%YourCOmpany%=YourCompanySerialPort 

[YourCompanySerialPort] 
%YourCompanyUSBSerialPort%=YOURCOMPANYUSB,USB\VID_1234&PID_ABCD

; 
; Win 2000/XP
;
[YOURCOMPANYUSB]
Include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection

[YOURCOMPANYUSB.HW] 
AddReg=YOURCOMPANYUSBAddReg.HW 

[YOURCOMPANYUSBAddReg.HW] 
HKR,,DevLoader,0,*ntkern 
HKR,,NTMPDriver,,"usbser.sys" 

[YOURCOMPANYUSB.Services] 
AddService=usbser, 0x00000002, FuncDrv_Service_Inst 

[FuncDrv_Service_Inst] 
DisplayName=%USBFilterString% 
ServiceType= 1 
StartType = 3 
ErrorControl = 0 
ServiceBinary = %12%\usbser.sys 

[Strings] 
YourCompany="YourCompany" 
YourCompanySerialPort="Your Company USB Serial Port" 
USBFilterString = "USB Serial Service"

请注意,这仅适用于32位操作系统.它也可以与Vista一起使用,尽管文件头没有说明!

请注意,usbser.sys的某些版本存在严重问题,包括蓝屏,例如,在传输64字节正整数倍的数据包时.如果您使用的是XP SP2或更早版本,则安装修补程序KB943198. XP SP3和Vista都可以.

对于Mac,您只需要正确报告设备类别,驱动程序扫描就会选择正确的驱动程序. (Windows会忽略设备类,这就是为什么您需要提供.inf文件的原因).

对不起,我应该更清楚了.如果无法提取全部负载,这将不会一一列举-我不确定这是可能的.

This may not be considered to be directly programming related but I am at a loss to know where else to ask. I have tried looking at a variety of websites but so far Google has not been my friend.

I am having trouble finding out whether I need to write my own device driver for the various windows/linux/mac platforms that the device I am developing may be connected to, or whether the functionality is provided by the standard drivers.

My device is a USB CDC (communications device) that appears as a COM: port. It also includes a battery charger that will, once the device has been enumerated require the full 5 unit load (500mA) supply current that can be drawn from the USB connector. My problem is that if the USB driver in the host decides that it cannot deliver the full supply current then it should fail to enumerate the device.

If, as a fallback, I provide a second configuration set that only allows the device to draw 1 unit load from the interface connector will the standard drivers enumerate the device using this configuration.

解决方案

You need to write a .inf file for Windows that ties up your device VID and PID with the system usbser.sys. Mine looks like this (Replace YourCompany as necessary, put in your VID and PID (in hex), and change the DriverVer line to whatever date and version you want):

; -----------------------------------------------------------------------------
; XP/2000 USB Comms Port Setup
; -----------------------------------------------------------------------------

[Version] 
DriverVer=12/03/2008,1.0.0000.0000
Signature="$Windows NT$"
Class=Ports 
ClassGUID={4d36e978-e325-11ce-bfc1-08002be10318} 
Provider=%YourCompany% 

[DestinationDirs]
DefaultDestDir=10,system32\drivers
DriverCopyFiles=12

[ControlFlags]
ExcludeFromSelect = *

[Manufacturer] 
%YourCOmpany%=YourCompanySerialPort 

[YourCompanySerialPort] 
%YourCompanyUSBSerialPort%=YOURCOMPANYUSB,USB\VID_1234&PID_ABCD

; 
; Win 2000/XP
;
[YOURCOMPANYUSB]
Include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection

[YOURCOMPANYUSB.HW] 
AddReg=YOURCOMPANYUSBAddReg.HW 

[YOURCOMPANYUSBAddReg.HW] 
HKR,,DevLoader,0,*ntkern 
HKR,,NTMPDriver,,"usbser.sys" 

[YOURCOMPANYUSB.Services] 
AddService=usbser, 0x00000002, FuncDrv_Service_Inst 

[FuncDrv_Service_Inst] 
DisplayName=%USBFilterString% 
ServiceType= 1 
StartType = 3 
ErrorControl = 0 
ServiceBinary = %12%\usbser.sys 

[Strings] 
YourCompany="YourCompany" 
YourCompanySerialPort="Your Company USB Serial Port" 
USBFilterString = "USB Serial Service"

Note this works with 32 bit OSs only. It also works with Vista although the file header doesn't say so!

Be aware that some versions of usbser.sys have significant problems, including bluescreening, for example when transferring packets that are exact multiples of 64 bytes. If you're using XP SP2 or previous then install hotfix KB943198. XP SP3 and Vista are fine.

For the Mac you simply need to report your device class correctly and the driver scan picks up the correct drivers. (Windows ignores the device class which is why you need to supply the .inf file).

EDIT: Sorry, I should have been clearer. This will not fail to enumerate if it can't draw the full load - I'm not sure that's possible.

这篇关于我是否需要为CDC设备编写自己的主机侧USB驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆