11

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.

uɐɪ
  • 2,540
  • 1
  • 20
  • 23
  • I believe that you first have to look into the USB specification to see if these things are allowed. If the specification allows it, then standard browsers will probably support it. – kgiannakakis Jul 24 '09 at 11:17
  • In the USB 2.0 specification the device descriptor allows for a number of configurations, each of which can specify that it requires a certain amount of power from the interface. It would then, I presume, be up to the driver to choose between these different configurations. – uɐɪ Jul 24 '09 at 12:18

5 Answers5

7

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.

Vicky
  • 12,934
  • 4
  • 46
  • 54
  • 1
    I'm trying to install this driver automatically as opposed to the user needing to go to device manager (though this does work). I've tried just using right-click install and also using the method described at http://stackoverflow.com/questions/677686/how-do-i-deploy-a-inf-based-driver. In either case when I plug in the device it brings up the New Hardware Wizard and, while it shows up under Ports in device manager, there is no driver associated with it. Some more details: – Edwin Evans Jun 30 '11 at 16:37
  • ... I'm trying on Windows XP and using a Cypress chip. Cypress provides an .inf file for this (http://www.cypress.com/?rID=40248) that is quite a bit different, for example CopyFiles is set to DriverCopyFiles, not FakeModemCopyFileSection. Any suggestion? – Edwin Evans Jun 30 '11 at 17:01
  • We have used usbser.sys as the driver for a number of products produced by my company and I have never found an easy way to avoid the "Found New Hardware Wizard" in Windows XP. If you do, please let me know. The good news is that, using the same inf file, the drivers can get installed automatically with no Wizard in Windows Vista and Windows 7 if the device is plugged in after the inf file has been installed. – David Grayson Jul 31 '11 at 03:31
  • Can you clarify "Windows ignores the device class which is why you need to supply the .inf file"? Is it not enough to report a VID/PID that Windows could use to match up device w/usbser.sys? – Edwin Evans Sep 15 '11 at 00:32
  • 1
    @Edwin Evans: Yes, and that's exactly what the .inf file is for - to match up your VID/PID with usbser.sys. – Vicky Sep 15 '11 at 08:35
  • Thank you. I'm still confused though. Some devices work just by plugging them in. How is this possible? – Edwin Evans Sep 15 '11 at 15:02
  • @Edwin Evans: USB serial devices? I've not seen Windows able to auto install those. Some other types of device have the inf files already installed with Windows by default, though. – Vicky Sep 15 '11 at 15:45
  • @Vicky. Actually I'm still confused on one point. Even if a device works automatically with a generic driver, it will still have a unique VID/PID right? So then how does Windows match it up with the generic driver inf file? – Edwin Evans Sep 15 '11 at 23:22
  • 1
    @Edwin Evans: for something like a mass storage device (memory stick), presumably by using the device class. But for USB serial devices it does not use the device class. At a guess MS realised it would be way too annoying if you had to install drivers for every memory stick you ever put in, but serial devices aren't THAT common in user land. – Vicky Sep 16 '11 at 09:13
2

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.

naven87
  • 964
  • 1
  • 7
  • 24
1

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.

CrazyChris
  • 106
  • 2
  • 6
1

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!

Tim Williscroft
  • 3,705
  • 24
  • 37
  • Note that a device ID consists of a Vendor ID and Product ID, and the owner of that Vendor ID may not appreciate your hijacking of their ID. For personal projets that's no issue of course, but don't sell such devices. – MSalters Aug 24 '09 at 14:49
  • of course, getting your own id is not that expensive, and we'll all want to buy your marvelous device, right ? – Tim Williscroft Aug 25 '09 at 02:26
1

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

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.

marcus
  • 11
  • 1