Difference between revisions of "USB Gadget"

From ArmadeusWiki
Jump to: navigation, search
(Introduction)
m (Hardware/software specifics for the APF27dev board (Under Construction))
Line 8: Line 8:
 
* mass storage device
 
* mass storage device
  
=== Hardware/software specifics for the APF27dev board (Under Construction) ===
+
=== Hardware/software specifics for the APF27dev board ===
 
At first, an USB A male / A male cable has to be used like this one: http://fr.farnell.com/pro-signal/psg90024/lead-usb-2-0-am-am-2m-black/dp/1494745
 
At first, an USB A male / A male cable has to be used like this one: http://fr.farnell.com/pro-signal/psg90024/lead-usb-2-0-am-am-2m-black/dp/1494745
 +
 +
Do not use USB cable with integrated ferrite bead!
  
 
The APF27dev board is equiped with two USB host ports. Only the high speed Host port (top connector) can be configured as an USB Device.
 
The APF27dev board is equiped with two USB host ports. Only the high speed Host port (top connector) can be configured as an USB Device.

Revision as of 15:53, 22 September 2010

Instructions to use the USB device (or OTG) port of your Armadeus board to communicate with your PC; ie see your board from your PC like an USB device.

Introduction

You can connect your APF board to your PC using its USB Device port(APF9328dev) or a modified USB host port (APF27dev) and it can be "enumerated" as most common USB devices (depending on the type of communication you want to use):

  • serial device
  • net device
  • mass storage device

Hardware/software specifics for the APF27dev board

At first, an USB A male / A male cable has to be used like this one: http://fr.farnell.com/pro-signal/psg90024/lead-usb-2-0-am-am-2m-black/dp/1494745

Do not use USB cable with integrated ferrite bead!

The APF27dev board is equiped with two USB host ports. Only the high speed Host port (top connector) can be configured as an USB Device.

In order to activate the device mode, a new parameter has to be added to the U-Boot console variable:

BIOS> setenv console console=ttySMX0,115200 otg_mode=device
BIOS> saveenv
BIOS> boot

Your port will now work as an USB device

Warning Warning: DO NOT CONNECT TWO HOST PORTS TOGETHER AND TAKE CARE TO USE THE RIGHT USB PORT ON THE APF27DEV !!


Installation

  • The drivers are now installed by default (since armadeus-3.0)
  • you should have following modules in your kernel source tree:
drivers/usb/gadget/gadgetfs.ko        For test
drivers/usb/gadget/g_ether.ko         Ethernet emulation on USB
drivers/usb/gadget/g_file_storage.ko  Mass storage
drivers/usb/gadget/g_serial.ko        Serial emulation on USB
drivers/usb/gadget/g_zero.ko          For test

Usage

To emulate a mass storage device:

  • create or get a "backing storage file" (for example)
  • copy this file (uncompressed) in the /tmp directory of your board (here my Host PC has 192.168.0.20 as IP @):
 # tftp -g -r backing_file.gz -l /tmp/backing_file.gz 192.168.0.20
 # gunzip /tmp/backing_file.gz
  • load g_file_storage module:
 # modprobe g_file_storage file=/tmp/backing_file
 g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
 g_file_storage gadget: Number of LUNs=1
 g_file_storage gadget-lun0: ro=0, file: /tmp/backing_file
  • connect target's USB cable to your PC and,

On your Linux Host:

  • If you have a recent Linux distribution, your device should be automatically mounted. Otherwise:
    • as root, launch dmesg and find the /dev/sdaX device assigned to your board:
... usb 1-1.4: new full speed USB device using uhci_hcd and address 7
... usb 1-1.4: configuration #1 chosen from 1 choice
... scsi1 : SCSI emulation for USB Mass Storage devices
...    Vendor: Linux     Model: File-Stor Gadget  Rev: 0314
...    Type:   Direct-Access                      ANSI SCSI revision: 02
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
...  sda: Write Protect is off
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
...  sda: Write Protect is off
...   sda: sda1
...  sd 1:0:0:0: Attached scsi disk sda
...  sd 1:0:0:0: Attached scsi generic sg0 type 0
    • then mount the device and enjoy file sharing:
 $ sudo mount /dev/sda1 /mnt/tmp
 $ cd /mnt/tmp
 $ showimage /mnt/tmp/test.jpg

To emulate a serial link

  • On your Host PC:
 $ sudo modprobe usbserial vendor=0x0525 product=0xA4A6

or you can automate it by modifying /etc/modprobe.d/options file (Tested on *Ubuntu):

 $ sudo vim /etc/modprobe.d/options
  ...
  options usbserial vendor=0x0525 product=0xA4A6
  • on your APF:
 # mknod /dev/ttygserial c 127 0   (if not already existing)
 # modprobe g_serial
 gs_bind: Gadget Serial v2.2 bound
 gs_module_init: Gadget Serial v2.2 loaded
  • then connect the USB cable between your PC and your APF and you should see on your Host:
 $ tail -f /var/log/messages
 Nov 27 22:53:50 ...  usb 1-1.4: new full speed USB device using uhci_hcd and address 7
 Nov 27 22:53:50 ...  usb 1-1.4: configuration #1 chosen from 1 choice
 Nov 27 22:53:50 ...  usbserial_generic 1-1.4:1.0: generic converter detected
 Nov 27 22:53:50 ...  usb 1-1.4: generic converter now attached to ttyUSB0
  • you should now be able to send/receive data through /dev/ttyUSB0 (PC) and /dev/ttygserial (APF):
 [armadeus]$ echo "COUCOU" > /dev/ttyUSB0
 # cat /dev/ttygserial
 COUCOUC

To emulate an Ethernet link

  • On your Target:
 # modprobe g_ether
 ether gadget: using random self ethernet address
 ether gadget: using random host ethernet address
 usb0: Ethernet Gadget, version: May Day 2005
 usb0: using imx_udc, OUT ep2out-bulk IN ep1in-bulk STATUS ep4in-int
 usb0: MAC be:df:31:95:16:e0
 usb0: HOST MAC 3e:86:1e:94:eb:84
 usb0: RNDIS ready
  • On your PC:
 $ sudo modprobe cdc_ether
  • If someone knows how to go further.... :-)

Links