windows 我是否需要为 CDC 设备编写自己的主机端 USB 驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1176939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:51:28  来源:igfitidea点击:

Do I need to write my own host side USB driver for a CDC device

windowshardwareusb

提问by u??

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.

这可能不被认为与编程直接相关,但我不知道还能在哪里问。我曾尝试查看各种网站,但到目前为止 Google 还不是我的朋友。

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.

我无法确定是否需要为我正在开发的设备可能连接到的各种 windows/linux/mac 平台编写自己的设备驱动程序,或者标准驱动程序是否提供功能。

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.

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

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.

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

采纳答案by Vicky

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):

您需要为 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"

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

请注意,这仅适用于 32 位操作系统。它也适用于 Vista,尽管文件头没有这么说!

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.

请注意,某些版本的 usbser.sys 存在严重问题,包括蓝屏,例如在传输 64 字节的精确倍数的数据包时。如果您使用的是 XP SP2 或之前版本,请安装修补程序 KB943198。XP SP3 和 Vista 都很好。

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).

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

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.

编辑:对不起,我应该更清楚。如果它不能完全加载,这将不会无法枚举 - 我不确定这是否可能。

回答by marcus

If your device is connecting as USB CDC-ACM device to the windows desktop host, the windows desktop already provides the driver usbser.sys. But there are some some issues in windows Vista. You just need the inf to install the usbser.sys on desktop. For WinCE you do not have the driver and for you need to write or get one from any third party vendor. Here is one

如果您的设备作为 USB CDC-ACM 设备连接到 windows 桌面主机,则 windows 桌面已提供驱动程序 usbser.sys。但是在 Windows Vista 中存在一些问题。您只需要 inf 即可在桌面上安装 usbser.sys。对于 WinCE,您没有驱动程序,因此您需要编写或从任何第三方供应商处获取驱动程序。这是一个

http://www.em.avant-garde-lab.com/Products.html

http://www.em.avant-garde-lab.com/Products.html

If your device specifies itself as self powered in its device descriptor then the host would rely on the devices self power capability. You can check at usb.org for details. Thanks.

如果您的设备在其设备描述符中将自身指定为自供电,则主机将依赖于设备的自供电能力。您可以在 usb.org 上查看详细信息。谢谢。

回答by CrazyChris

I am not sure about power question but ther is pleanty CDC drivers (or I think there is) so you could use one. For the power question, the solution with many configuration is probably good one, I have never encountered this in work (I have USB analyzer) but at home sometimes when I have 3 or more different devices that requires power from USB I got failed enumeration. I supose this is operating system choice if it can't supply power to new device it cut's it off (sensible choice as it can't power it). This is my gues rather checking USB standart.

我不确定电源问题,但有很多 CDC 驱动程序(或者我认为有),因此您可以使用一个。对于电源问题,具有多种配置的解决方案可能是一个不错的解决方案,我在工作中从未遇到过这种情况(我有 USB 分析仪),但有时在家里,当我有 3 个或更多不同的设备需要 USB 供电时,我的枚举失败了。我认为这是操作系统的选择,如果它无法为新设备供电,则会将其切断(明智的选择,因为它无法为它供电)。这是我的猜测,而不是检查 USB 标准。

回答by Tim Williscroft

If your device reports a device ID that the host OS already supports, then they won't need a driver.

如果您的设备报告主机操作系统已经支持的设备 ID,则它们将不需要驱动程序。

You may need to impersonate an existing USB uart. Data sheets are readily available. (But I figure you already knew that.)

您可能需要模拟现有的 USB uart。数据表很容易获得。(但我想你已经知道了。)

I'm not sure that the host OS will honour your multi-configuration idea.

我不确定主机操作系统是否会尊重您的多配置想法。

But give it a punt so we all know!

但是给它一个平底船,所以我们都知道!

回答by naven87

You are correct on the driver question. When the device is plugged in and goes through the enumeration process it is required to stay < 100mA. The host will interrogate and determine the configuration(s). If there are more than one which support different power levels, then the driver will need to decide to select the appropriate configuration. If there is only high-power and it is not available, then it will not enumerate the device. In general, the standard driver doing CDC wouldn't be aware of the different device level configurations that would possible and so would require some degree of customization to handle them.

您在驱动程序问题上是正确的。当设备插入并通过枚举过程时,它需要保持 < 100mA。主机将询问并确定配置。如果支持不同功率级别的不止一个,那么驱动程序将需要决定选择合适的配置。如果只有高功率,没有可用,则不会枚举设备。通常,执行 CDC 的标准驱动程序不会意识到可能存在的不同设备级配置,因此需要一定程度的自定义来处理它们。