Difference between revisions of "EMAC OE USB Gadget Connections"

From wiki.emacinc.com
Jump to: navigation, search
m (added section heading for login terminal)
(added testing for network connection)
Line 23: Line 23:
  
 
The host system will most likely automatically detect and load the appropriate drivers. If this does not occur, verify that the usbnet driver is installed and loaded on a Linux distribution. See the [http://msdn.microsoft.com/en-us/library/windows/hardware/gg463293.aspx Microsoft RNDIS driver documentation] for more information on configuring this driver for Windows hosts.
 
The host system will most likely automatically detect and load the appropriate drivers. If this does not occur, verify that the usbnet driver is installed and loaded on a Linux distribution. See the [http://msdn.microsoft.com/en-us/library/windows/hardware/gg463293.aspx Microsoft RNDIS driver documentation] for more information on configuring this driver for Windows hosts.
 +
 +
=== Testing the Network Connection ===
 +
Use the <code>ping</code> command to test that the connection sends and receives packets correctly. Once this has been verified, you should be able to use any network service to transfer data between the two systems.
  
 
== USB Gadget Serial ==
 
== USB Gadget Serial ==

Revision as of 07:45, 28 March 2013

Systems that have a USB device port can be connected to a PC or other system through a USB host port. A USB cable will need to be connected between the USB device port on the board and a USB host port on the other system. This page covers the process of establishing a connection using the gadget Ethernet driver and several of the available USB gadget function drivers. More information regarding the USB Gadget drivers for Linux can be found at the Linux USB Project.

USB Gadget Ethernet

The USB Gadget Ethernet driver allows a device to enumerate and communicate as an Ethernet device over the USB link. On the host system, this requires the usbnet driver for a Linux system or the RNDIS driver for Windows hosts.

To establish a connection, first create an entry in the /etc/network/interfaces file on the device system for the usb0 interface. An example of this configuration is shown below. Note that in almost all circumstances you will want to use a different subnetwork for the USB Ethernet link than what is used for the LAN connection on either the host or device system.

allow-hotplug usb0
iface usb0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
    gateway 192.168.0.1

Also, add a configuration for the device connection on the host. The configuration will vary depending on the host operating system and flavor. The IP address of the host should be set to the value used for the gateway setting on the device (192.168.0.1 using the example above). An example configuration for a system that uses the /etc/network/interfaces networking configuration is shown below.

allow-hotplug usb0
iface usb0 inet static
    address 192.168.0.1
    netmask 255.255.255.0
    gateway 192.168.0.1

Once the configuration is finished and the host and device systems are connected via a USB cable, load the gadget Ethernet driver on the device with the following command.

root@emac-oe:~# modprobe g_ether

After loading the driver, ifconfig should show an entry for the usb0 interface. Depending on the configuration, you may need to run ifup usb0 to configure the device.

The host system will most likely automatically detect and load the appropriate drivers. If this does not occur, verify that the usbnet driver is installed and loaded on a Linux distribution. See the Microsoft RNDIS driver documentation for more information on configuring this driver for Windows hosts.

Testing the Network Connection

Use the ping command to test that the connection sends and receives packets correctly. Once this has been verified, you should be able to use any network service to transfer data between the two systems.

USB Gadget Serial

The USB Gadget Serial driver can be used to emulate a serial port over a USB cable. This can be a useful method for getting serial access to the target machine from a system that does not have a serial port or when there is no spare serial port on the target system to utilize for access. Note that there is limited support for using the USB gadget serial device as a console for accessing the bootloader on most systems, so a hardware serial console is generally required for development.

Device-side Configuration

Serial device connections between the target board and host utilize the g_serial driver. This allows for data transfer using the standard serial programming API and existing serial terminal applications. Several parameters may be passed to the g_serial module, as seen in the modinfo listing below:

root@emac-oe:~# modinfo g_serial
filename:       /lib/modules/2.6.28/kernel/drivers/usb/gadget/g_serial.ko
license:        GPL
author:         David Brownell
author:         Al Borchers
description:    Gadget Serial v2.4
license:        GPL
author:         Felipe Balbi
depends:        at91_udc
vermagic:       2.6.28 preempt mod_unload ARMv5
parm:           idVendor:USB Vendor ID (ushort)
parm:           idProduct:USB Product ID (ushort)
parm:           bcdDevice:USB Device version (BCD) (ushort)
parm:           iManufacturer:USB Manufacturer string (charp)
parm:           iProduct:USB Product string (charp)
parm:           iSerialNumber:SerialNumber string (charp)
parm:           use_acm:Use CDC ACM, default=yes (bool)
parm:           use_obex:Use CDC OBEX, default=no (bool)
parm:           n_ports:number of ports to create, default=1 (uint)

In most cases, the default settings will be acceptable and the driver may be loaded using the following command:

root@emac-oe:~# modprobe g_serial

After loading the module, connect a USB cable between the device port and the host machine. Once connected, dmesg should indicate that the connection was detected and associated with g_serial.

Host-side Configuration

The host can be running a variety of environments including Linux, Windows, or any other system with a driver implementing the CDC ACM class. This section covers the basic configuration a Linux host; see the Documentation/usb/gadget_serial.txt file in the Linux kernel source for your target board for detailed information on how to configure both Linux and Windows hosts.

On a Linux PC, the lsusb command or contents of the /proc/bus/usb/devices file should indicate that the device is connected and show the vendor and product ID used by the device. On some Linux distributions, a window may be displayed notifying you that it has detected a USB serial connection. If this occurs, you can skip forward to the Testing the Connection section. Otherwise, you will need to register and attach the device.

Registering and Attaching to the Device

To enable serial communication over the USB cable, the usbserial driver can be registered and associated to the device. In this example, the vendor ID for the device is 0x0525 and the product ID is 0xA4A6. These IDs may vary depending on the device. Use the output of the lsusb command to determine the correct IDs.

Once you have determined the vendor and product ID, load the usbserial driver, passing these values as options as seen in the example below:

developer@emac-ldc:~# sudo modprobe usbserial vendor=0x0525 product=0xA4A6

Once this has been loaded the kernel messages should indicate that the driver has been associated correctly and that the USB serial device node has been created (usually this will be /dev/ttyUSB0). See the listing below for example dmesg output.

developer@emac-ldc:~# sudo dmesg | tail
[1462941.986961] usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1462941.986961] usb 4-2: Product: Gadget Serial
[1462941.986961] usb 4-2: Manufacturer: Linux 2.6.25 with at91_udc
[1462941.986961] usb 4-2: SerialNumber: 0
[1463015.408126] usbcore: registered new interface driver usbserial
[1463015.408147] drivers/usb/serial/usb-serial.c: USB Serial support registered for generic
[1463015.408174] usbserial_generic 4-2:1.0: generic converter detected
[1463015.408229] usb 4-2: generic converter now attached to ttyUSB0
[1463015.408241] usbcore: registered new interface driver usbserial_generic
[1463015.408243] drivers/usb/serial/usb-serial.c: USB Serial Driver core

Testing the Connection

To test the USB serial interface, use a standard terminal application such as minicom. The microcom application on the EMAC OE system can be used for the target board interface. The device on the Linux PC will be named /dev/ttyUSB0 (assuming that this is the only USB serial device connected); the device on the target system will be /dev/ttyGS0.

root@emac-oe:~# microcom -s 115200 /dev/ttyGS0
.... 
developer@emac-ldc:~$ minicom -s

Login Terminal

It is possible to add a login terminal on the USB gadget serial device.