1*4882a593Smuzhiyun=============================== 2*4882a593SmuzhiyunLinux Gadget Serial Driver v2.0 3*4882a593Smuzhiyun=============================== 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun11/20/2004 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun(updated 8-May-2008 for v2.3) 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunLicense and Disclaimer 11*4882a593Smuzhiyun---------------------- 12*4882a593SmuzhiyunThis program is free software; you can redistribute it and/or 13*4882a593Smuzhiyunmodify it under the terms of the GNU General Public License as 14*4882a593Smuzhiyunpublished by the Free Software Foundation; either version 2 of 15*4882a593Smuzhiyunthe License, or (at your option) any later version. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunThis program is distributed in the hope that it will be useful, 18*4882a593Smuzhiyunbut WITHOUT ANY WARRANTY; without even the implied warranty of 19*4882a593SmuzhiyunMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*4882a593SmuzhiyunGNU General Public License for more details. 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunYou should have received a copy of the GNU General Public 23*4882a593SmuzhiyunLicense along with this program; if not, write to the Free 24*4882a593SmuzhiyunSoftware Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25*4882a593SmuzhiyunMA 02111-1307 USA. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThis document and the gadget serial driver itself are 28*4882a593SmuzhiyunCopyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com). 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunIf you have questions, problems, or suggestions for this driver 31*4882a593Smuzhiyunplease contact Al Borchers at alborchers@steinerpoint.com. 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunPrerequisites 35*4882a593Smuzhiyun------------- 36*4882a593SmuzhiyunVersions of the gadget serial driver are available for the 37*4882a593Smuzhiyun2.4 Linux kernels, but this document assumes you are using 38*4882a593Smuzhiyunversion 2.3 or later of the gadget serial driver in a 2.6 39*4882a593SmuzhiyunLinux kernel. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunThis document assumes that you are familiar with Linux and 42*4882a593SmuzhiyunWindows and know how to configure and build Linux kernels, run 43*4882a593Smuzhiyunstandard utilities, use minicom and HyperTerminal, and work with 44*4882a593SmuzhiyunUSB and serial devices. It also assumes you configure the Linux 45*4882a593Smuzhiyungadget and usb drivers as modules. 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunWith version 2.3 of the driver, major and minor device nodes are 48*4882a593Smuzhiyunno longer statically defined. Your Linux based system should mount 49*4882a593Smuzhiyunsysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the 50*4882a593Smuzhiyun/dev nodes matching the sysfs /sys/class/tty files. 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunOverview 55*4882a593Smuzhiyun-------- 56*4882a593SmuzhiyunThe gadget serial driver is a Linux USB gadget driver, a USB device 57*4882a593Smuzhiyunside driver. It runs on a Linux system that has USB device side 58*4882a593Smuzhiyunhardware; for example, a PDA, an embedded Linux system, or a PC 59*4882a593Smuzhiyunwith a USB development card. 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunThe gadget serial driver talks over USB to either a CDC ACM driver 62*4882a593Smuzhiyunor a generic USB serial driver running on a host PC:: 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun Host 65*4882a593Smuzhiyun -------------------------------------- 66*4882a593Smuzhiyun | Host-Side CDC ACM USB Host | 67*4882a593Smuzhiyun | Operating | or | Controller | USB 68*4882a593Smuzhiyun | System | Generic USB | Driver |-------- 69*4882a593Smuzhiyun | (Linux or | Serial | and | | 70*4882a593Smuzhiyun | Windows) Driver USB Stack | | 71*4882a593Smuzhiyun -------------------------------------- | 72*4882a593Smuzhiyun | 73*4882a593Smuzhiyun | 74*4882a593Smuzhiyun | 75*4882a593Smuzhiyun Gadget | 76*4882a593Smuzhiyun -------------------------------------- | 77*4882a593Smuzhiyun | Gadget USB Periph. | | 78*4882a593Smuzhiyun | Device-Side | Gadget | Controller | | 79*4882a593Smuzhiyun | Linux | Serial | Driver |-------- 80*4882a593Smuzhiyun | Operating | Driver | and | 81*4882a593Smuzhiyun | System USB Stack | 82*4882a593Smuzhiyun -------------------------------------- 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunOn the device-side Linux system, the gadget serial driver looks 85*4882a593Smuzhiyunlike a serial device. 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunOn the host-side system, the gadget serial device looks like a 88*4882a593SmuzhiyunCDC ACM compliant class device or a simple vendor specific device 89*4882a593Smuzhiyunwith bulk in and bulk out endpoints, and it is treated similarly 90*4882a593Smuzhiyunto other serial devices. 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunThe host side driver can potentially be any ACM compliant driver 93*4882a593Smuzhiyunor any driver that can talk to a device with a simple bulk in/out 94*4882a593Smuzhiyuninterface. Gadget serial has been tested with the Linux ACM driver, 95*4882a593Smuzhiyunthe Windows usbser.sys ACM driver, and the Linux USB generic serial 96*4882a593Smuzhiyundriver. 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunWith the gadget serial driver and the host side ACM or generic 99*4882a593Smuzhiyunserial driver running, you should be able to communicate between 100*4882a593Smuzhiyunthe host and the gadget side systems as if they were connected by a 101*4882a593Smuzhiyunserial cable. 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunThe gadget serial driver only provides simple unreliable data 104*4882a593Smuzhiyuncommunication. It does not yet handle flow control or many other 105*4882a593Smuzhiyunfeatures of normal serial devices. 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunInstalling the Gadget Serial Driver 109*4882a593Smuzhiyun----------------------------------- 110*4882a593SmuzhiyunTo use the gadget serial driver you must configure the Linux gadget 111*4882a593Smuzhiyunside kernel for "Support for USB Gadgets", for a "USB Peripheral 112*4882a593SmuzhiyunController" (for example, net2280), and for the "Serial Gadget" 113*4882a593Smuzhiyundriver. All this are listed under "USB Gadget Support" when 114*4882a593Smuzhiyunconfiguring the kernel. Then rebuild and install the kernel or 115*4882a593Smuzhiyunmodules. 116*4882a593Smuzhiyun 117*4882a593SmuzhiyunThen you must load the gadget serial driver. To load it as an 118*4882a593SmuzhiyunACM device (recommended for interoperability), do this:: 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun modprobe g_serial 121*4882a593Smuzhiyun 122*4882a593SmuzhiyunTo load it as a vendor specific bulk in/out device, do this:: 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun modprobe g_serial use_acm=0 125*4882a593Smuzhiyun 126*4882a593SmuzhiyunThis will also automatically load the underlying gadget peripheral 127*4882a593Smuzhiyuncontroller driver. This must be done each time you reboot the gadget 128*4882a593Smuzhiyunside Linux system. You can add this to the start up scripts, if 129*4882a593Smuzhiyundesired. 130*4882a593Smuzhiyun 131*4882a593SmuzhiyunYour system should use mdev (from busybox) or udev to make the 132*4882a593Smuzhiyundevice nodes. After this gadget driver has been set up you should 133*4882a593Smuzhiyunthen see a /dev/ttyGS0 node:: 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun # ls -l /dev/ttyGS0 | cat 136*4882a593Smuzhiyun crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0 137*4882a593Smuzhiyun # 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunNote that the major number (253, above) is system-specific. If 140*4882a593Smuzhiyunyou need to create /dev nodes by hand, the right numbers to use 141*4882a593Smuzhiyunwill be in the /sys/class/tty/ttyGS0/dev file. 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunWhen you link this gadget driver early, perhaps even statically, 144*4882a593Smuzhiyunyou may want to set up an /etc/inittab entry to run "getty" on it. 145*4882a593SmuzhiyunThe /dev/ttyGS0 line should work like most any other serial port. 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun 148*4882a593SmuzhiyunIf gadget serial is loaded as an ACM device you will want to use 149*4882a593Smuzhiyuneither the Windows or Linux ACM driver on the host side. If gadget 150*4882a593Smuzhiyunserial is loaded as a bulk in/out device, you will want to use the 151*4882a593SmuzhiyunLinux generic serial driver on the host side. Follow the appropriate 152*4882a593Smuzhiyuninstructions below to install the host side driver. 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun 155*4882a593SmuzhiyunInstalling the Windows Host ACM Driver 156*4882a593Smuzhiyun-------------------------------------- 157*4882a593SmuzhiyunTo use the Windows ACM driver you must have the "linux-cdc-acm.inf" 158*4882a593Smuzhiyunfile (provided along this document) which supports all recent versions 159*4882a593Smuzhiyunof Windows. 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunWhen the gadget serial driver is loaded and the USB device connected 162*4882a593Smuzhiyunto the Windows host with a USB cable, Windows should recognize the 163*4882a593Smuzhiyungadget serial device and ask for a driver. Tell Windows to find the 164*4882a593Smuzhiyundriver in the folder that contains the "linux-cdc-acm.inf" file. 165*4882a593Smuzhiyun 166*4882a593SmuzhiyunFor example, on Windows XP, when the gadget serial device is first 167*4882a593Smuzhiyunplugged in, the "Found New Hardware Wizard" starts up. Select 168*4882a593Smuzhiyun"Install from a list or specific location (Advanced)", then on the 169*4882a593Smuzhiyunnext screen select "Include this location in the search" and enter the 170*4882a593Smuzhiyunpath or browse to the folder containing the "linux-cdc-acm.inf" file. 171*4882a593SmuzhiyunWindows will complain that the Gadget Serial driver has not passed 172*4882a593SmuzhiyunWindows Logo testing, but select "Continue anyway" and finish the 173*4882a593Smuzhiyundriver installation. 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunOn Windows XP, in the "Device Manager" (under "Control Panel", 176*4882a593Smuzhiyun"System", "Hardware") expand the "Ports (COM & LPT)" entry and you 177*4882a593Smuzhiyunshould see "Gadget Serial" listed as the driver for one of the COM 178*4882a593Smuzhiyunports. 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunTo uninstall the Windows XP driver for "Gadget Serial", right click 181*4882a593Smuzhiyunon the "Gadget Serial" entry in the "Device Manager" and select 182*4882a593Smuzhiyun"Uninstall". 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunInstalling the Linux Host ACM Driver 186*4882a593Smuzhiyun------------------------------------ 187*4882a593SmuzhiyunTo use the Linux ACM driver you must configure the Linux host side 188*4882a593Smuzhiyunkernel for "Support for Host-side USB" and for "USB Modem (CDC ACM) 189*4882a593Smuzhiyunsupport". 190*4882a593Smuzhiyun 191*4882a593SmuzhiyunOnce the gadget serial driver is loaded and the USB device connected 192*4882a593Smuzhiyunto the Linux host with a USB cable, the host system should recognize 193*4882a593Smuzhiyunthe gadget serial device. For example, the command:: 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun cat /sys/kernel/debug/usb/devices 196*4882a593Smuzhiyun 197*4882a593Smuzhiyunshould show something like this::: 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 5 Spd=480 MxCh= 0 200*4882a593Smuzhiyun D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 201*4882a593Smuzhiyun P: Vendor=0525 ProdID=a4a7 Rev= 2.01 202*4882a593Smuzhiyun S: Manufacturer=Linux 2.6.8.1 with net2280 203*4882a593Smuzhiyun S: Product=Gadget Serial 204*4882a593Smuzhiyun S: SerialNumber=0 205*4882a593Smuzhiyun C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr= 2mA 206*4882a593Smuzhiyun I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm 207*4882a593Smuzhiyun E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=32ms 208*4882a593Smuzhiyun I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm 209*4882a593Smuzhiyun E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms 210*4882a593Smuzhiyun E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms 211*4882a593Smuzhiyun 212*4882a593SmuzhiyunIf the host side Linux system is configured properly, the ACM driver 213*4882a593Smuzhiyunshould be loaded automatically. The command "lsmod" should show the 214*4882a593Smuzhiyun"acm" module is loaded. 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun 217*4882a593SmuzhiyunInstalling the Linux Host Generic USB Serial Driver 218*4882a593Smuzhiyun--------------------------------------------------- 219*4882a593SmuzhiyunTo use the Linux generic USB serial driver you must configure the 220*4882a593SmuzhiyunLinux host side kernel for "Support for Host-side USB", for "USB 221*4882a593SmuzhiyunSerial Converter support", and for the "USB Generic Serial Driver". 222*4882a593Smuzhiyun 223*4882a593SmuzhiyunOnce the gadget serial driver is loaded and the USB device connected 224*4882a593Smuzhiyunto the Linux host with a USB cable, the host system should recognize 225*4882a593Smuzhiyunthe gadget serial device. For example, the command:: 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun cat /sys/kernel/debug/usb/devices 228*4882a593Smuzhiyun 229*4882a593Smuzhiyunshould show something like this::: 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 6 Spd=480 MxCh= 0 232*4882a593Smuzhiyun D: Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 233*4882a593Smuzhiyun P: Vendor=0525 ProdID=a4a6 Rev= 2.01 234*4882a593Smuzhiyun S: Manufacturer=Linux 2.6.8.1 with net2280 235*4882a593Smuzhiyun S: Product=Gadget Serial 236*4882a593Smuzhiyun S: SerialNumber=0 237*4882a593Smuzhiyun C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 2mA 238*4882a593Smuzhiyun I: If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial 239*4882a593Smuzhiyun E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms 240*4882a593Smuzhiyun E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms 241*4882a593Smuzhiyun 242*4882a593SmuzhiyunYou must load the usbserial driver and explicitly set its parameters 243*4882a593Smuzhiyunto configure it to recognize the gadget serial device, like this:: 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id 246*4882a593Smuzhiyun 247*4882a593SmuzhiyunThe legacy way is to use module parameters:: 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun modprobe usbserial vendor=0x0525 product=0xA4A6 250*4882a593Smuzhiyun 251*4882a593SmuzhiyunIf everything is working, usbserial will print a message in the 252*4882a593Smuzhiyunsystem log saying something like "Gadget Serial converter now 253*4882a593Smuzhiyunattached to ttyUSB0". 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun 256*4882a593SmuzhiyunTesting with Minicom or HyperTerminal 257*4882a593Smuzhiyun------------------------------------- 258*4882a593SmuzhiyunOnce the gadget serial driver and the host driver are both installed, 259*4882a593Smuzhiyunand a USB cable connects the gadget device to the host, you should 260*4882a593Smuzhiyunbe able to communicate over USB between the gadget and host systems. 261*4882a593SmuzhiyunYou can use minicom or HyperTerminal to try this out. 262*4882a593Smuzhiyun 263*4882a593SmuzhiyunOn the gadget side run "minicom -s" to configure a new minicom 264*4882a593Smuzhiyunsession. Under "Serial port setup" set "/dev/ttygserial" as the 265*4882a593Smuzhiyun"Serial Device". Set baud rate, data bits, parity, and stop bits, 266*4882a593Smuzhiyunto 9600, 8, none, and 1--these settings mostly do not matter. 267*4882a593SmuzhiyunUnder "Modem and dialing" erase all the modem and dialing strings. 268*4882a593Smuzhiyun 269*4882a593SmuzhiyunOn a Linux host running the ACM driver, configure minicom similarly 270*4882a593Smuzhiyunbut use "/dev/ttyACM0" as the "Serial Device". (If you have other 271*4882a593SmuzhiyunACM devices connected, change the device name appropriately.) 272*4882a593Smuzhiyun 273*4882a593SmuzhiyunOn a Linux host running the USB generic serial driver, configure 274*4882a593Smuzhiyunminicom similarly, but use "/dev/ttyUSB0" as the "Serial Device". 275*4882a593Smuzhiyun(If you have other USB serial devices connected, change the device 276*4882a593Smuzhiyunname appropriately.) 277*4882a593Smuzhiyun 278*4882a593SmuzhiyunOn a Windows host configure a new HyperTerminal session to use the 279*4882a593SmuzhiyunCOM port assigned to Gadget Serial. The "Port Settings" will be 280*4882a593Smuzhiyunset automatically when HyperTerminal connects to the gadget serial 281*4882a593Smuzhiyundevice, so you can leave them set to the default values--these 282*4882a593Smuzhiyunsettings mostly do not matter. 283*4882a593Smuzhiyun 284*4882a593SmuzhiyunWith minicom configured and running on the gadget side and with 285*4882a593Smuzhiyunminicom or HyperTerminal configured and running on the host side, 286*4882a593Smuzhiyunyou should be able to send data back and forth between the gadget 287*4882a593Smuzhiyunside and host side systems. Anything you type on the terminal 288*4882a593Smuzhiyunwindow on the gadget side should appear in the terminal window on 289*4882a593Smuzhiyunthe host side and vice versa. 290