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


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.


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.


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

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

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

But give it a punt so we all know!


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.


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »