gadget_serial.txt 13 KB

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