What happens when a new device is plugged into a USB port? - Page 1
Forum section: electronics / projects

author: Merlysys
author_rank: Regular Contributor
timestamp: January 05, 2014, 05:00:40 pm
content: When we buy a new USB device and plug it in a series of events takes place. I want to build such a device so I am trying to find how to go about it.The PC detects something is plugged in, starts looking for a driver etc. Sometimes it seems to find it, other times we have to direct it to where the file is. The PC recognizes something new is inside but nothing can be done with it, then we install the application.Is there a breakout board for building such a device?Is there a ready-made software that can be modified to use as the driver?Ditto for the application.My future USB device will transfer data from the outside world to the PC's (virtual) serial port. I read its easier to design something for virtual serial via the USB than any other way.Know any websites that explains the process? I searched but didn't come up with enough info as I don't know what keywords to use.

author: mariush
author_rank: Super Contributor
timestamp: January 05, 2014, 06:14:12 pm
content: You'll have to read the USB standards for this, or some books.It is however relatively difficult to bit-bang stuff and emulate an usb port .. lots of timings and bits back and forth. It would be easier to use an already made serial-to-usb chips like the ones made by FTDIThere are microcontrollers that have USB functionality built in (some pic32 for example) and you can enable virtual serial port through usb with a few lines of code on such processors

author: zapta
author_rank: Super Contributor
timestamp: January 05, 2014, 06:46:38 pm
content: Here is a breakout board that converts USB to 5V serial signals.https://www.sparkfun.com/products/9716Here is the same, embedded within the cablehttps://www.sparkfun.com/products/9717Just two examples, there are many more.

author: calzap
author_rank: Frequent Contributor
timestamp: January 05, 2014, 09:26:59 pm
content: USB Complete: The Developer's Guide by Jan Axelson has been highly recommended in a number of forums, but I confess I haven't read it.Mike in California

author: Kohanbash
author_rank: Regular Contributor
timestamp: January 05, 2014, 10:31:09 pm
content: HiTwo of the more common chips to convert serial to USB are the CP2102 and FTDI chip to emulate a serial port.I have not checked recently but it used to be that the CP2102 had better driver support but was a pain to solder by hand since it is a QFN package (leadless).The FTDI chip gets a vendor ID and product ID code and is a bit less compatible out of the box (and requires the computer to grab drivers) but much easier to solder.

author: AlfBaz
author_rank: Super Contributor
timestamp: January 05, 2014, 11:46:16 pm
content: Quote from: Merlysys on January 05, 2014, 05:00:40 pmAside from chips such as those from FTDI which convert a simple serial interface into USB, many microcontrollers have an USB peripheral on board which may be LS/FS (Low Speed 1.5Mbps/Full Speed 12Mbps USB 1.0) or FS/HS (FS + high speed 480Mbps USB 2.0). You'll find the majority of these peripherals are OTG which means they can act as device or host depending on how they are plugged in. They usually do this by sensing pullup pulldown voltages on a "5th" pin called the ID pin. These peripherals can also be configure as device only and host onlyQuoteAssuming you don't meanbuilding the actual physical layerthen some of the links already provided will do the trick as well as a plethora of development boards with all the necessary hardware built in and example code for the device sideQuoteThere are a number of digitally signed drivers out there who's main aim is to provide auser spaceinterface to usb. There's winusb.sys, libusb0.sys and libusbK.sys to name the ones I am aware of. These files contain the kernel mode code that does the bare metal work on the USB side but also provide a user mode interface by way of function calls accessible by either dynamically loading a library (dll) or statically by having all the functions compiled and included in your source. libusb provides source code and documentation for both dll and static library access for most if not all the sys files above. Be aware that features between these drivers vary.It doesn't end there though. Most likely your device will be using an existing USB "class" and the OS (I only know windows) will attempt to load standard system drivers for that class which may or may not be accessible via windows API for your software to access. I'm fairly certain there is a window api for the HID class, not sure about others.To set up your own drivers (the ones mentioned above) for a device that windows wants to assign standard drivers to you'll be needing something like libusb-win32 or better stillzidagzadig, which is basically a gui for libusb-win32. With zadig you see a list of plugged in devices and simply tell it to replace the system driver with the one of your choice and it will carry out the necessary file creation and installation. It can also generate a folder with all the required "Install" files for distribution.QuoteAlthough the are a bunch of functions in the above mentioned libraries, you will have to get your head around the basics of usb communications as the functions provided are meant for maximum flexibility and hence are quite "low level".QuoteThe USB 2.0 spec is freely available out there and is quite heavy reading.The already mention "USB Complete" by Jan Axelson is a comprehensive easy to read guide.Most of this pdf is an explanation of the low level usb workingshttp://www.silabs.com/Support%20Documents/Software/USB_Overview.pdfThis web site is quite good alsohttp://www.beyondlogic.org/usbnutshell/usb1.shtml

author: free_electron
author_rank: Super Contributor
timestamp: January 05, 2014, 11:58:31 pm
content: no need to go down to that level. you're gonna spend a year getting it to work. slap on a ftdi or silabs usb-uart and off you go.low level here is what happens :usb controller detects a device plug and exchanges some information with the device. this trips the USB stack in the computer to fire off a plug event. the USB stack interrogates the devices : what are you ? who made you ? ( it reads the VID and PID code of the device . these codes are unique for a device. you cannot arbitrarily assign codes. you need to BUY these codes 1500$ for a VID. use a FTDI or Silabs chip and you get a VID/PID pair to use)the usb stack then otifies the operating system : we got a device with vid/pid on port xyz. please load driver.the operating system checks to see if this is a known device ( it looks for the vid/pid pair in the driver signatures it has access to. if this is a vid/pid/port combination that has been used in the past it will have an entry for which driver to load. if th vid/pid is known but the port is new then anew entry is made in the catalog and the driver is loaded. (driver is determinded by vid/pid pair)if no driver is found for the vid/pid pair you get a popup asking where the driver is , or the os goes to look on the internet if it can find one in the master catalog.that's it in a nustshell.there are a few universal devices such as usb-uart device ( the CDC cor communications device class). these generally do not need a driver

author: mrkev
author_rank: Regular Contributor
timestamp: January 06, 2014, 12:06:04 am
content: The FTDI chip is really easy to work with... The drivers are in every Win. system i came across and you can use it as either USB to RS232 (with 0-5V output) converter (wich means that new COM port will be awaible in the system) or you can write your own software to control the whole thing...

author: amyk
author_rank: Super Contributor
timestamp: January 06, 2014, 08:12:01 am
content: Quote from: AlfBaz on January 05, 2014, 11:46:16 pmHere's another recommendation for that site.AVR309 is another good read if you want to try bitbang USB.

author: nowlan
author_rank: Frequent Contributor
timestamp: January 06, 2014, 08:48:07 am
content: Yeah, I would recommend axelsons book.I bought the usb v1 book by intel once upon a time.You might be interested in this toolhttp://www.nirsoft.net/utils/usb_devices_view.htmlMy advice would be to find some chip that has usb stack already licensed.I dont think this is something you want to do on your own.

author: AlfBaz
author_rank: Super Contributor
timestamp: January 06, 2014, 08:53:44 am
content: Myseriousquestion is, will you be wearing a gimp mask and/or mouth gag whilst creating bitbangin' version of the usb phy?