gadget_serial.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ===============================
  2. Linux Gadget Serial Driver v2.0
  3. ===============================
  4. 11/20/2004
  5. (updated 8-May-2008 for v2.3)
  6. License and Disclaimer
  7. ----------------------
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation; either version 2 of
  11. the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public
  17. License along with this program; if not, write to the Free
  18. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. MA 02111-1307 USA.
  20. This document and the gadget serial driver itself are
  21. Copyright (C) 2004 by Al Borchers ([email protected]).
  22. If you have questions, problems, or suggestions for this driver
  23. please contact Al Borchers at [email protected].
  24. Prerequisites
  25. -------------
  26. Versions of the gadget serial driver are available for the
  27. 2.4 Linux kernels, but this document assumes you are using
  28. version 2.3 or later of the gadget serial driver in a 2.6
  29. Linux kernel.
  30. This document assumes that you are familiar with Linux and
  31. Windows and know how to configure and build Linux kernels, run
  32. standard utilities, use minicom and HyperTerminal, and work with
  33. USB and serial devices. It also assumes you configure the Linux
  34. gadget and usb drivers as modules.
  35. With version 2.3 of the driver, major and minor device nodes are
  36. no longer statically defined. Your Linux based system should mount
  37. sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the
  38. /dev nodes matching the sysfs /sys/class/tty files.
  39. Overview
  40. --------
  41. The gadget serial driver is a Linux USB gadget driver, a USB device
  42. side driver. It runs on a Linux system that has USB device side
  43. hardware; for example, a PDA, an embedded Linux system, or a PC
  44. with a USB development card.
  45. The gadget serial driver talks over USB to either a CDC ACM driver
  46. or a generic USB serial driver running on a host PC::
  47. Host
  48. --------------------------------------
  49. | Host-Side CDC ACM USB Host |
  50. | Operating | or | Controller | USB
  51. | System | Generic USB | Driver |--------
  52. | (Linux or | Serial | and | |
  53. | Windows) Driver USB Stack | |
  54. -------------------------------------- |
  55. |
  56. |
  57. |
  58. Gadget |
  59. -------------------------------------- |
  60. | Gadget USB Periph. | |
  61. | Device-Side | Gadget | Controller | |
  62. | Linux | Serial | Driver |--------
  63. | Operating | Driver | and |
  64. | System USB Stack |
  65. --------------------------------------
  66. On the device-side Linux system, the gadget serial driver looks
  67. like a serial device.
  68. On the host-side system, the gadget serial device looks like a
  69. CDC ACM compliant class device or a simple vendor specific device
  70. with bulk in and bulk out endpoints, and it is treated similarly
  71. to other serial devices.
  72. The host side driver can potentially be any ACM compliant driver
  73. or any driver that can talk to a device with a simple bulk in/out
  74. interface. Gadget serial has been tested with the Linux ACM driver,
  75. the Windows usbser.sys ACM driver, and the Linux USB generic serial
  76. driver.
  77. With the gadget serial driver and the host side ACM or generic
  78. serial driver running, you should be able to communicate between
  79. the host and the gadget side systems as if they were connected by a
  80. serial cable.
  81. The gadget serial driver only provides simple unreliable data
  82. communication. It does not yet handle flow control or many other
  83. features of normal serial devices.
  84. Installing the Gadget Serial Driver
  85. -----------------------------------
  86. To use the gadget serial driver you must configure the Linux gadget
  87. side kernel for "Support for USB Gadgets", for a "USB Peripheral
  88. Controller" (for example, net2280), and for the "Serial Gadget"
  89. driver. All this are listed under "USB Gadget Support" when
  90. configuring the kernel. Then rebuild and install the kernel or
  91. modules.
  92. Then you must load the gadget serial driver. To load it as an
  93. ACM device (recommended for interoperability), do this::
  94. modprobe g_serial
  95. To load it as a vendor specific bulk in/out device, do this::
  96. modprobe g_serial use_acm=0
  97. This will also automatically load the underlying gadget peripheral
  98. controller driver. This must be done each time you reboot the gadget
  99. side Linux system. You can add this to the start up scripts, if
  100. desired.
  101. Your system should use mdev (from busybox) or udev to make the
  102. device nodes. After this gadget driver has been set up you should
  103. then see a /dev/ttyGS0 node::
  104. # ls -l /dev/ttyGS0 | cat
  105. crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0
  106. #
  107. Note that the major number (253, above) is system-specific. If
  108. you need to create /dev nodes by hand, the right numbers to use
  109. will be in the /sys/class/tty/ttyGS0/dev file.
  110. When you link this gadget driver early, perhaps even statically,
  111. you may want to set up an /etc/inittab entry to run "getty" on it.
  112. The /dev/ttyGS0 line should work like most any other serial port.
  113. If gadget serial is loaded as an ACM device you will want to use
  114. either the Windows or Linux ACM driver on the host side. If gadget
  115. serial is loaded as a bulk in/out device, you will want to use the
  116. Linux generic serial driver on the host side. Follow the appropriate
  117. instructions below to install the host side driver.
  118. Installing the Windows Host ACM Driver
  119. --------------------------------------
  120. To use the Windows ACM driver you must have the "linux-cdc-acm.inf"
  121. file (provided along this document) which supports all recent versions
  122. of Windows.
  123. When the gadget serial driver is loaded and the USB device connected
  124. to the Windows host with a USB cable, Windows should recognize the
  125. gadget serial device and ask for a driver. Tell Windows to find the
  126. driver in the folder that contains the "linux-cdc-acm.inf" file.
  127. For example, on Windows XP, when the gadget serial device is first
  128. plugged in, the "Found New Hardware Wizard" starts up. Select
  129. "Install from a list or specific location (Advanced)", then on the
  130. next screen select "Include this location in the search" and enter the
  131. path or browse to the folder containing the "linux-cdc-acm.inf" file.
  132. Windows will complain that the Gadget Serial driver has not passed
  133. Windows Logo testing, but select "Continue anyway" and finish the
  134. driver installation.
  135. On Windows XP, in the "Device Manager" (under "Control Panel",
  136. "System", "Hardware") expand the "Ports (COM & LPT)" entry and you
  137. should see "Gadget Serial" listed as the driver for one of the COM
  138. ports.
  139. To uninstall the Windows XP driver for "Gadget Serial", right click
  140. on the "Gadget Serial" entry in the "Device Manager" and select
  141. "Uninstall".
  142. Installing the Linux Host ACM Driver
  143. ------------------------------------
  144. To use the Linux ACM driver you must configure the Linux host side
  145. kernel for "Support for Host-side USB" and for "USB Modem (CDC ACM)
  146. support".
  147. Once the gadget serial driver is loaded and the USB device connected
  148. to the Linux host with a USB cable, the host system should recognize
  149. the gadget serial device. For example, the command::
  150. cat /sys/kernel/debug/usb/devices
  151. should show something like this:::
  152. T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 5 Spd=480 MxCh= 0
  153. D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
  154. P: Vendor=0525 ProdID=a4a7 Rev= 2.01
  155. S: Manufacturer=Linux 2.6.8.1 with net2280
  156. S: Product=Gadget Serial
  157. S: SerialNumber=0
  158. C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr= 2mA
  159. I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm
  160. E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=32ms
  161. I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm
  162. E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  163. E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  164. If the host side Linux system is configured properly, the ACM driver
  165. should be loaded automatically. The command "lsmod" should show the
  166. "acm" module is loaded.
  167. Installing the Linux Host Generic USB Serial Driver
  168. ---------------------------------------------------
  169. To use the Linux generic USB serial driver you must configure the
  170. Linux host side kernel for "Support for Host-side USB", for "USB
  171. Serial Converter support", and for the "USB Generic Serial Driver".
  172. Once the gadget serial driver is loaded and the USB device connected
  173. to the Linux host with a USB cable, the host system should recognize
  174. the gadget serial device. For example, the command::
  175. cat /sys/kernel/debug/usb/devices
  176. should show something like this:::
  177. T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 6 Spd=480 MxCh= 0
  178. D: Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
  179. P: Vendor=0525 ProdID=a4a6 Rev= 2.01
  180. S: Manufacturer=Linux 2.6.8.1 with net2280
  181. S: Product=Gadget Serial
  182. S: SerialNumber=0
  183. C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 2mA
  184. I: If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial
  185. E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  186. E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  187. You must load the usbserial driver and explicitly set its parameters
  188. to configure it to recognize the gadget serial device, like this::
  189. echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id
  190. The legacy way is to use module parameters::
  191. modprobe usbserial vendor=0x0525 product=0xA4A6
  192. If everything is working, usbserial will print a message in the
  193. system log saying something like "Gadget Serial converter now
  194. attached to ttyUSB0".
  195. Testing with Minicom or HyperTerminal
  196. -------------------------------------
  197. Once the gadget serial driver and the host driver are both installed,
  198. and a USB cable connects the gadget device to the host, you should
  199. be able to communicate over USB between the gadget and host systems.
  200. You can use minicom or HyperTerminal to try this out.
  201. On the gadget side run "minicom -s" to configure a new minicom
  202. session. Under "Serial port setup" set "/dev/ttygserial" as the
  203. "Serial Device". Set baud rate, data bits, parity, and stop bits,
  204. to 9600, 8, none, and 1--these settings mostly do not matter.
  205. Under "Modem and dialing" erase all the modem and dialing strings.
  206. On a Linux host running the ACM driver, configure minicom similarly
  207. but use "/dev/ttyACM0" as the "Serial Device". (If you have other
  208. ACM devices connected, change the device name appropriately.)
  209. On a Linux host running the USB generic serial driver, configure
  210. minicom similarly, but use "/dev/ttyUSB0" as the "Serial Device".
  211. (If you have other USB serial devices connected, change the device
  212. name appropriately.)
  213. On a Windows host configure a new HyperTerminal session to use the
  214. COM port assigned to Gadget Serial. The "Port Settings" will be
  215. set automatically when HyperTerminal connects to the gadget serial
  216. device, so you can leave them set to the default values--these
  217. settings mostly do not matter.
  218. With minicom configured and running on the gadget side and with
  219. minicom or HyperTerminal configured and running on the host side,
  220. you should be able to send data back and forth between the gadget
  221. side and host side systems. Anything you type on the terminal
  222. window on the gadget side should appear in the terminal window on
  223. the host side and vice versa.