gadget_serial.txt 12 KB

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