Blame Documentation/usb/gadget_serial.txt

Packit 7b02f3
Packit 7b02f3
                 Linux Gadget Serial Driver v2.0
Packit 7b02f3
                           11/20/2004
Packit 7b02f3
                  (updated 8-May-2008 for v2.3)
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
License and Disclaimer
Packit 7b02f3
----------------------
Packit 7b02f3
This program is free software; you can redistribute it and/or
Packit 7b02f3
modify it under the terms of the GNU General Public License as
Packit 7b02f3
published by the Free Software Foundation; either version 2 of
Packit 7b02f3
the License, or (at your option) any later version.
Packit 7b02f3
Packit 7b02f3
This program is distributed in the hope that it will be useful,
Packit 7b02f3
but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7b02f3
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 7b02f3
GNU General Public License for more details.
Packit 7b02f3
Packit 7b02f3
You should have received a copy of the GNU General Public
Packit 7b02f3
License along with this program; if not, write to the Free
Packit 7b02f3
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
Packit 7b02f3
MA 02111-1307 USA.
Packit 7b02f3
Packit 7b02f3
This document and the gadget serial driver itself are
Packit 7b02f3
Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com).
Packit 7b02f3
Packit 7b02f3
If you have questions, problems, or suggestions for this driver
Packit 7b02f3
please contact Al Borchers at alborchers@steinerpoint.com.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Prerequisites
Packit 7b02f3
-------------
Packit 7b02f3
Versions of the gadget serial driver are available for the
Packit 7b02f3
2.4 Linux kernels, but this document assumes you are using
Packit 7b02f3
version 2.3 or later of the gadget serial driver in a 2.6
Packit 7b02f3
Linux kernel.
Packit 7b02f3
Packit 7b02f3
This document assumes that you are familiar with Linux and
Packit 7b02f3
Windows and know how to configure and build Linux kernels, run
Packit 7b02f3
standard utilities, use minicom and HyperTerminal, and work with
Packit 7b02f3
USB and serial devices.  It also assumes you configure the Linux
Packit 7b02f3
gadget and usb drivers as modules.
Packit 7b02f3
Packit 7b02f3
With version 2.3 of the driver, major and minor device nodes are
Packit 7b02f3
no longer statically defined.  Your Linux based system should mount
Packit 7b02f3
sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the
Packit 7b02f3
/dev nodes matching the sysfs /sys/class/tty files.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Overview
Packit 7b02f3
--------
Packit 7b02f3
The gadget serial driver is a Linux USB gadget driver, a USB device
Packit 7b02f3
side driver.  It runs on a Linux system that has USB device side
Packit 7b02f3
hardware; for example, a PDA, an embedded Linux system, or a PC
Packit 7b02f3
with a USB development card.
Packit 7b02f3
Packit 7b02f3
The gadget serial driver talks over USB to either a CDC ACM driver
Packit 7b02f3
or a generic USB serial driver running on a host PC.
Packit 7b02f3
Packit 7b02f3
   Host
Packit 7b02f3
   --------------------------------------
Packit 7b02f3
  | Host-Side   CDC ACM       USB Host   |
Packit 7b02f3
  | Operating |   or        | Controller |   USB
Packit 7b02f3
  | System    | Generic USB | Driver     |--------
Packit 7b02f3
  | (Linux or | Serial      | and        |        |
Packit 7b02f3
  | Windows)    Driver        USB Stack  |        |
Packit 7b02f3
   --------------------------------------         |
Packit 7b02f3
                                                  |
Packit 7b02f3
                                                  |
Packit 7b02f3
                                                  |
Packit 7b02f3
   Gadget                                         |
Packit 7b02f3
   --------------------------------------         |
Packit 7b02f3
  | Gadget                   USB Periph. |        |
Packit 7b02f3
  | Device-Side |  Gadget  | Controller  |        |
Packit 7b02f3
  | Linux       |  Serial  | Driver      |--------
Packit 7b02f3
  | Operating   |  Driver  | and         |
Packit 7b02f3
  | System                   USB Stack   |
Packit 7b02f3
   --------------------------------------
Packit 7b02f3
Packit 7b02f3
On the device-side Linux system, the gadget serial driver looks
Packit 7b02f3
like a serial device.
Packit 7b02f3
Packit 7b02f3
On the host-side system, the gadget serial device looks like a
Packit 7b02f3
CDC ACM compliant class device or a simple vendor specific device
Packit 7b02f3
with bulk in and bulk out endpoints, and it is treated similarly
Packit 7b02f3
to other serial devices.
Packit 7b02f3
Packit 7b02f3
The host side driver can potentially be any ACM compliant driver
Packit 7b02f3
or any driver that can talk to a device with a simple bulk in/out
Packit 7b02f3
interface.  Gadget serial has been tested with the Linux ACM driver,
Packit 7b02f3
the Windows usbser.sys ACM driver, and the Linux USB generic serial
Packit 7b02f3
driver.
Packit 7b02f3
Packit 7b02f3
With the gadget serial driver and the host side ACM or generic
Packit 7b02f3
serial driver running, you should be able to communicate between
Packit 7b02f3
the host and the gadget side systems as if they were connected by a
Packit 7b02f3
serial cable.
Packit 7b02f3
Packit 7b02f3
The gadget serial driver only provides simple unreliable data
Packit 7b02f3
communication.  It does not yet handle flow control or many other
Packit 7b02f3
features of normal serial devices.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Installing the Gadget Serial Driver
Packit 7b02f3
-----------------------------------
Packit 7b02f3
To use the gadget serial driver you must configure the Linux gadget
Packit 7b02f3
side kernel for "Support for USB Gadgets", for a "USB Peripheral
Packit 7b02f3
Controller" (for example, net2280), and for the "Serial Gadget"
Packit 7b02f3
driver.  All this are listed under "USB Gadget Support" when
Packit 7b02f3
configuring the kernel.  Then rebuild and install the kernel or
Packit 7b02f3
modules.
Packit 7b02f3
Packit 7b02f3
Then you must load the gadget serial driver.  To load it as an
Packit 7b02f3
ACM device (recommended for interoperability), do this:
Packit 7b02f3
Packit 7b02f3
  modprobe g_serial
Packit 7b02f3
Packit 7b02f3
To load it as a vendor specific bulk in/out device, do this:
Packit 7b02f3
Packit 7b02f3
  modprobe g_serial use_acm=0
Packit 7b02f3
Packit 7b02f3
This will also automatically load the underlying gadget peripheral
Packit 7b02f3
controller driver.  This must be done each time you reboot the gadget
Packit 7b02f3
side Linux system.  You can add this to the start up scripts, if
Packit 7b02f3
desired.
Packit 7b02f3
Packit 7b02f3
Your system should use mdev (from busybox) or udev to make the
Packit 7b02f3
device nodes.  After this gadget driver has been set up you should
Packit 7b02f3
then see a /dev/ttyGS0 node:
Packit 7b02f3
Packit 7b02f3
  # ls -l /dev/ttyGS0 | cat
Packit 7b02f3
  crw-rw----    1 root     root     253,   0 May  8 14:10 /dev/ttyGS0
Packit 7b02f3
  #
Packit 7b02f3
Packit 7b02f3
Note that the major number (253, above) is system-specific.  If
Packit 7b02f3
you need to create /dev nodes by hand, the right numbers to use
Packit 7b02f3
will be in the /sys/class/tty/ttyGS0/dev file.
Packit 7b02f3
Packit 7b02f3
When you link this gadget driver early, perhaps even statically,
Packit 7b02f3
you may want to set up an /etc/inittab entry to run "getty" on it.
Packit 7b02f3
The /dev/ttyGS0 line should work like most any other serial port.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
If gadget serial is loaded as an ACM device you will want to use
Packit 7b02f3
either the Windows or Linux ACM driver on the host side.  If gadget
Packit 7b02f3
serial is loaded as a bulk in/out device, you will want to use the
Packit 7b02f3
Linux generic serial driver on the host side.  Follow the appropriate
Packit 7b02f3
instructions below to install the host side driver.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Installing the Windows Host ACM Driver
Packit 7b02f3
--------------------------------------
Packit 7b02f3
To use the Windows ACM driver you must have the "linux-cdc-acm.inf"
Packit 7b02f3
file (provided along this document) which supports all recent versions
Packit 7b02f3
of Windows.
Packit 7b02f3
Packit 7b02f3
When the gadget serial driver is loaded and the USB device connected
Packit 7b02f3
to the Windows host with a USB cable, Windows should recognize the
Packit 7b02f3
gadget serial device and ask for a driver.  Tell Windows to find the
Packit 7b02f3
driver in the folder that contains the "linux-cdc-acm.inf" file.
Packit 7b02f3
Packit 7b02f3
For example, on Windows XP, when the gadget serial device is first
Packit 7b02f3
plugged in, the "Found New Hardware Wizard" starts up.  Select
Packit 7b02f3
"Install from a list or specific location (Advanced)", then on the
Packit 7b02f3
next screen select "Include this location in the search" and enter the
Packit 7b02f3
path or browse to the folder containing the "linux-cdc-acm.inf" file.
Packit 7b02f3
Windows will complain that the Gadget Serial driver has not passed
Packit 7b02f3
Windows Logo testing, but select "Continue anyway" and finish the
Packit 7b02f3
driver installation.
Packit 7b02f3
Packit 7b02f3
On Windows XP, in the "Device Manager" (under "Control Panel",
Packit 7b02f3
"System", "Hardware") expand the "Ports (COM & LPT)" entry and you
Packit 7b02f3
should see "Gadget Serial" listed as the driver for one of the COM
Packit 7b02f3
ports.
Packit 7b02f3
Packit 7b02f3
To uninstall the Windows XP driver for "Gadget Serial", right click
Packit 7b02f3
on the "Gadget Serial" entry in the "Device Manager" and select
Packit 7b02f3
"Uninstall".
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Installing the Linux Host ACM Driver
Packit 7b02f3
------------------------------------
Packit 7b02f3
To use the Linux ACM driver you must configure the Linux host side
Packit 7b02f3
kernel for "Support for Host-side USB" and for "USB Modem (CDC ACM)
Packit 7b02f3
support".
Packit 7b02f3
Packit 7b02f3
Once the gadget serial driver is loaded and the USB device connected
Packit 7b02f3
to the Linux host with a USB cable, the host system should recognize
Packit 7b02f3
the gadget serial device.  For example, the command
Packit 7b02f3
Packit 7b02f3
  cat /sys/kernel/debug/usb/devices
Packit 7b02f3
Packit 7b02f3
should show something like this:
Packit 7b02f3
Packit 7b02f3
T:  Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  5 Spd=480 MxCh= 0
Packit 7b02f3
D:  Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
Packit 7b02f3
P:  Vendor=0525 ProdID=a4a7 Rev= 2.01
Packit 7b02f3
S:  Manufacturer=Linux 2.6.8.1 with net2280
Packit 7b02f3
S:  Product=Gadget Serial
Packit 7b02f3
S:  SerialNumber=0
Packit 7b02f3
C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr=  2mA
Packit 7b02f3
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm
Packit 7b02f3
E:  Ad=83(I) Atr=03(Int.) MxPS=   8 Ivl=32ms
Packit 7b02f3
I:  If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm
Packit 7b02f3
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Packit 7b02f3
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Packit 7b02f3
Packit 7b02f3
If the host side Linux system is configured properly, the ACM driver
Packit 7b02f3
should be loaded automatically.  The command "lsmod" should show the
Packit 7b02f3
"acm" module is loaded.
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Installing the Linux Host Generic USB Serial Driver
Packit 7b02f3
---------------------------------------------------
Packit 7b02f3
To use the Linux generic USB serial driver you must configure the
Packit 7b02f3
Linux host side kernel for "Support for Host-side USB", for "USB
Packit 7b02f3
Serial Converter support", and for the "USB Generic Serial Driver".
Packit 7b02f3
Packit 7b02f3
Once the gadget serial driver is loaded and the USB device connected
Packit 7b02f3
to the Linux host with a USB cable, the host system should recognize
Packit 7b02f3
the gadget serial device.  For example, the command
Packit 7b02f3
Packit 7b02f3
  cat /sys/kernel/debug/usb/devices
Packit 7b02f3
Packit 7b02f3
should show something like this:
Packit 7b02f3
Packit 7b02f3
T:  Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#=  6 Spd=480 MxCh= 0
Packit 7b02f3
D:  Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
Packit 7b02f3
P:  Vendor=0525 ProdID=a4a6 Rev= 2.01
Packit 7b02f3
S:  Manufacturer=Linux 2.6.8.1 with net2280
Packit 7b02f3
S:  Product=Gadget Serial
Packit 7b02f3
S:  SerialNumber=0
Packit 7b02f3
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=  2mA
Packit 7b02f3
I:  If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial
Packit 7b02f3
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Packit 7b02f3
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Packit 7b02f3
Packit 7b02f3
You must load the usbserial driver and explicitly set its parameters
Packit 7b02f3
to configure it to recognize the gadget serial device, like this:
Packit 7b02f3
Packit 7b02f3
  echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id
Packit 7b02f3
Packit 7b02f3
The legacy way is to use module parameters:
Packit 7b02f3
Packit 7b02f3
  modprobe usbserial vendor=0x0525 product=0xA4A6
Packit 7b02f3
Packit 7b02f3
If everything is working, usbserial will print a message in the
Packit 7b02f3
system log saying something like "Gadget Serial converter now
Packit 7b02f3
attached to ttyUSB0".
Packit 7b02f3
Packit 7b02f3
Packit 7b02f3
Testing with Minicom or HyperTerminal
Packit 7b02f3
-------------------------------------
Packit 7b02f3
Once the gadget serial driver and the host driver are both installed,
Packit 7b02f3
and a USB cable connects the gadget device to the host, you should
Packit 7b02f3
be able to communicate over USB between the gadget and host systems.
Packit 7b02f3
You can use minicom or HyperTerminal to try this out.
Packit 7b02f3
Packit 7b02f3
On the gadget side run "minicom -s" to configure a new minicom
Packit 7b02f3
session.  Under "Serial port setup" set "/dev/ttygserial" as the
Packit 7b02f3
"Serial Device".  Set baud rate, data bits, parity, and stop bits,
Packit 7b02f3
to 9600, 8, none, and 1--these settings mostly do not matter.
Packit 7b02f3
Under "Modem and dialing" erase all the modem and dialing strings.
Packit 7b02f3
Packit 7b02f3
On a Linux host running the ACM driver, configure minicom similarly
Packit 7b02f3
but use "/dev/ttyACM0" as the "Serial Device".  (If you have other
Packit 7b02f3
ACM devices connected, change the device name appropriately.)
Packit 7b02f3
Packit 7b02f3
On a Linux host running the USB generic serial driver, configure
Packit 7b02f3
minicom similarly, but use "/dev/ttyUSB0" as the "Serial Device".
Packit 7b02f3
(If you have other USB serial devices connected, change the device
Packit 7b02f3
name appropriately.)
Packit 7b02f3
Packit 7b02f3
On a Windows host configure a new HyperTerminal session to use the
Packit 7b02f3
COM port assigned to Gadget Serial.  The "Port Settings" will be
Packit 7b02f3
set automatically when HyperTerminal connects to the gadget serial
Packit 7b02f3
device, so you can leave them set to the default values--these
Packit 7b02f3
settings mostly do not matter.
Packit 7b02f3
Packit 7b02f3
With minicom configured and running on the gadget side and with
Packit 7b02f3
minicom or HyperTerminal configured and running on the host side,
Packit 7b02f3
you should be able to send data back and forth between the gadget
Packit 7b02f3
side and host side systems.  Anything you type on the terminal
Packit 7b02f3
window on the gadget side should appear in the terminal window on
Packit 7b02f3
the host side and vice versa.