290 lines · plain
1===============================2Linux Gadget Serial Driver v2.03===============================4 511/20/20046 7(updated 8-May-2008 for v2.3)8 9 10License and Disclaimer11----------------------12This program is free software; you can redistribute it and/or13modify it under the terms of the GNU General Public License as14published by the Free Software Foundation; either version 2 of15the License, or (at your option) any later version.16 17This program is distributed in the hope that it will be useful,18but WITHOUT ANY WARRANTY; without even the implied warranty of19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20GNU General Public License for more details.21 22You should have received a copy of the GNU General Public23License along with this program; if not, write to the Free24Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,25MA 02111-1307 USA.26 27This document and the gadget serial driver itself are28Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com).29 30If you have questions, problems, or suggestions for this driver31please contact Al Borchers at alborchers@steinerpoint.com.32 33 34Prerequisites35-------------36Versions of the gadget serial driver are available for the372.4 Linux kernels, but this document assumes you are using38version 2.3 or later of the gadget serial driver in a 2.639Linux kernel.40 41This document assumes that you are familiar with Linux and42Windows and know how to configure and build Linux kernels, run43standard utilities, use minicom and HyperTerminal, and work with44USB and serial devices. It also assumes you configure the Linux45gadget and usb drivers as modules.46 47With version 2.3 of the driver, major and minor device nodes are48no longer statically defined. Your Linux based system should mount49sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the50/dev nodes matching the sysfs /sys/class/tty files.51 52 53 54Overview55--------56The gadget serial driver is a Linux USB gadget driver, a USB device57side driver. It runs on a Linux system that has USB device side58hardware; for example, a PDA, an embedded Linux system, or a PC59with a USB development card.60 61The gadget serial driver talks over USB to either a CDC ACM driver62or a generic USB serial driver running on a host PC::63 64 Host65 --------------------------------------66 | Host-Side CDC ACM USB Host |67 | Operating | or | Controller | USB68 | System | Generic USB | Driver |--------69 | (Linux or | Serial | and | |70 | Windows) Driver USB Stack | |71 -------------------------------------- |72 |73 |74 |75 Gadget |76 -------------------------------------- |77 | Gadget USB Periph. | |78 | Device-Side | Gadget | Controller | |79 | Linux | Serial | Driver |--------80 | Operating | Driver | and |81 | System USB Stack |82 --------------------------------------83 84On the device-side Linux system, the gadget serial driver looks85like a serial device.86 87On the host-side system, the gadget serial device looks like a88CDC ACM compliant class device or a simple vendor specific device89with bulk in and bulk out endpoints, and it is treated similarly90to other serial devices.91 92The host side driver can potentially be any ACM compliant driver93or any driver that can talk to a device with a simple bulk in/out94interface. Gadget serial has been tested with the Linux ACM driver,95the Windows usbser.sys ACM driver, and the Linux USB generic serial96driver.97 98With the gadget serial driver and the host side ACM or generic99serial driver running, you should be able to communicate between100the host and the gadget side systems as if they were connected by a101serial cable.102 103The gadget serial driver only provides simple unreliable data104communication. It does not yet handle flow control or many other105features of normal serial devices.106 107 108Installing the Gadget Serial Driver109-----------------------------------110To use the gadget serial driver you must configure the Linux gadget111side kernel for "Support for USB Gadgets", for a "USB Peripheral112Controller" (for example, net2280), and for the "Serial Gadget"113driver. All this are listed under "USB Gadget Support" when114configuring the kernel. Then rebuild and install the kernel or115modules.116 117Then you must load the gadget serial driver. To load it as an118ACM device (recommended for interoperability), do this::119 120 modprobe g_serial121 122To load it as a vendor specific bulk in/out device, do this::123 124 modprobe g_serial use_acm=0125 126This will also automatically load the underlying gadget peripheral127controller driver. This must be done each time you reboot the gadget128side Linux system. You can add this to the start up scripts, if129desired.130 131Your system should use mdev (from busybox) or udev to make the132device nodes. After this gadget driver has been set up you should133then see a /dev/ttyGS0 node::134 135 # ls -l /dev/ttyGS0 | cat136 crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0137 #138 139Note that the major number (253, above) is system-specific. If140you need to create /dev nodes by hand, the right numbers to use141will be in the /sys/class/tty/ttyGS0/dev file.142 143When you link this gadget driver early, perhaps even statically,144you may want to set up an /etc/inittab entry to run "getty" on it.145The /dev/ttyGS0 line should work like most any other serial port.146 147 148If gadget serial is loaded as an ACM device you will want to use149either the Windows or Linux ACM driver on the host side. If gadget150serial is loaded as a bulk in/out device, you will want to use the151Linux generic serial driver on the host side. Follow the appropriate152instructions below to install the host side driver.153 154 155Installing the Windows Host ACM Driver156--------------------------------------157To use the Windows ACM driver you must have the "linux-cdc-acm.inf"158file (provided along this document) which supports all recent versions159of Windows.160 161When the gadget serial driver is loaded and the USB device connected162to the Windows host with a USB cable, Windows should recognize the163gadget serial device and ask for a driver. Tell Windows to find the164driver in the folder that contains the "linux-cdc-acm.inf" file.165 166For example, on Windows XP, when the gadget serial device is first167plugged in, the "Found New Hardware Wizard" starts up. Select168"Install from a list or specific location (Advanced)", then on the169next screen select "Include this location in the search" and enter the170path or browse to the folder containing the "linux-cdc-acm.inf" file.171Windows will complain that the Gadget Serial driver has not passed172Windows Logo testing, but select "Continue anyway" and finish the173driver installation.174 175On Windows XP, in the "Device Manager" (under "Control Panel",176"System", "Hardware") expand the "Ports (COM & LPT)" entry and you177should see "Gadget Serial" listed as the driver for one of the COM178ports.179 180To uninstall the Windows XP driver for "Gadget Serial", right click181on the "Gadget Serial" entry in the "Device Manager" and select182"Uninstall".183 184 185Installing the Linux Host ACM Driver186------------------------------------187To use the Linux ACM driver you must configure the Linux host side188kernel for "Support for Host-side USB" and for "USB Modem (CDC ACM)189support".190 191Once the gadget serial driver is loaded and the USB device connected192to the Linux host with a USB cable, the host system should recognize193the gadget serial device. For example, the command::194 195 cat /sys/kernel/debug/usb/devices196 197should show something like this:::198 199 T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 5 Spd=480 MxCh= 0200 D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1201 P: Vendor=0525 ProdID=a4a7 Rev= 2.01202 S: Manufacturer=Linux 2.6.8.1 with net2280203 S: Product=Gadget Serial204 S: SerialNumber=0205 C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr= 2mA206 I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm207 E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=32ms208 I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm209 E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms210 E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms211 212If the host side Linux system is configured properly, the ACM driver213should be loaded automatically. The command "lsmod" should show the214"acm" module is loaded.215 216 217Installing the Linux Host Generic USB Serial Driver218---------------------------------------------------219To use the Linux generic USB serial driver you must configure the220Linux host side kernel for "Support for Host-side USB", for "USB221Serial Converter support", and for the "USB Generic Serial Driver".222 223Once the gadget serial driver is loaded and the USB device connected224to the Linux host with a USB cable, the host system should recognize225the gadget serial device. For example, the command::226 227 cat /sys/kernel/debug/usb/devices228 229should show something like this:::230 231 T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 6 Spd=480 MxCh= 0232 D: Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1233 P: Vendor=0525 ProdID=a4a6 Rev= 2.01234 S: Manufacturer=Linux 2.6.8.1 with net2280235 S: Product=Gadget Serial236 S: SerialNumber=0237 C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 2mA238 I: If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial239 E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms240 E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms241 242You must load the usbserial driver and explicitly set its parameters243to configure it to recognize the gadget serial device, like this::244 245 echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id246 247The legacy way is to use module parameters::248 249 modprobe usbserial vendor=0x0525 product=0xA4A6250 251If everything is working, usbserial will print a message in the252system log saying something like "Gadget Serial converter now253attached to ttyUSB0".254 255 256Testing with Minicom or HyperTerminal257-------------------------------------258Once the gadget serial driver and the host driver are both installed,259and a USB cable connects the gadget device to the host, you should260be able to communicate over USB between the gadget and host systems.261You can use minicom or HyperTerminal to try this out.262 263On the gadget side run "minicom -s" to configure a new minicom264session. Under "Serial port setup" set "/dev/ttygserial" as the265"Serial Device". Set baud rate, data bits, parity, and stop bits,266to 9600, 8, none, and 1--these settings mostly do not matter.267Under "Modem and dialing" erase all the modem and dialing strings.268 269On a Linux host running the ACM driver, configure minicom similarly270but use "/dev/ttyACM0" as the "Serial Device". (If you have other271ACM devices connected, change the device name appropriately.)272 273On a Linux host running the USB generic serial driver, configure274minicom similarly, but use "/dev/ttyUSB0" as the "Serial Device".275(If you have other USB serial devices connected, change the device276name appropriately.)277 278On a Windows host configure a new HyperTerminal session to use the279COM port assigned to Gadget Serial. The "Port Settings" will be280set automatically when HyperTerminal connects to the gadget serial281device, so you can leave them set to the default values--these282settings mostly do not matter.283 284With minicom configured and running on the gadget side and with285minicom or HyperTerminal configured and running on the host side,286you should be able to send data back and forth between the gadget287side and host side systems. Anything you type on the terminal288window on the gadget side should appear in the terminal window on289the host side and vice versa.290