USB

The Universal Serial Bus (USB) can be utilized for many functions on the development kit, including external media. The phyCORE-AM64x System-on-Module (SOM) provides one USB 3.1 Gen 1 Dual-Role Device (DRD) Subsystem (USB0) which can be utilized as a USB 2.0 port with OTG functionality or as a USB 3.1 port with USB 3.1 Gen 1 and xHCI 1.1 specification. The full pinout of the USB 3.1 controller includes the signaling for both USB 3.1 and USB 2.0. This means that USB0 can be used as either a USB 3.1 port or a USB 2.0 port.

This guide will show you how to use the USB Host capabilities featured on the phyCORE-AM64x development kit. To learn more information about the phyCORE-AM64x USB interface, please see section 7.8 in the Hardware Manual.

The USB0 interface uses a USB HUB to split the bus to 4x locations.

USB0 Split by USB Hub

Type

Qty

Header Location

Speed

Bus

USB A Double Stacked

2

X13

3.1

002

Mini PCIe

1

X31

2.0

001

Pin Header

1

X27 (Pin 21, 22, 37, 39)

2.0

001

phyCORE-AM64x USB Connections on the Front phyCORE-AM64x miniPCIe Connector Location

Warning

The USB super speed signals are muxed between the miniPCIe interface and the USB HUB. Enabling miniPCIe (done via device tree overlay) will disable USB3.0 speeds at the stacked type-A USB connector but USB2.0 speeds will still be available.

Requirements

Verifying USB Interface

  • With the phyCORE-AM64x development kit booted into Linux, see that there are 4 USB devices. There should be 2 devices on each bus.

    Target (Linux)
    lsusb
    
    Expected Output
    root@phyboard-electra-am64xx-1:device# lsusb
    Bus 002 Device 002: ID 0451:8240
    Bus 002 Device 001: ID 1d6b:0003
    Bus 001 Device 002: ID 0451:8242
    Bus 001 Device 001: ID 1d6b:0002
    
  • Insert a USB3.0 storage device into the bottom connector on X13. You should see something like the following on the serial console:

    Expected Output
    root@phyboard-electra-am64xx-1:device# [ 2359.689614] usb 2-1.2: new SuperSpeed Gen 1 USB device number 3 using xhci-hcd
      [ 2359.714497] usb 2-1.2: New USB device found, idVendor=0781, idProduct=5591, bcdDevice= 1.00
      [ 2359.722872] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
      [ 2359.730201] usb 2-1.2: Product:  SanDisk 3.2Gen1
      [ 2359.734861] usb 2-1.2: Manufacturer:  USB
      [ 2359.738886] usb 2-1.2: SerialNumber: 0401a83fbd697e437712b826697973aaaf57d1c75e9691ad879dfe7934b8a81bea020000000000000000000037ac13c5ff935d18915581076e2cc649
      [ 2359.781446] usb-storage 2-1.2:1.0: USB Mass Storage device detected
      [ 2359.788793] scsi host0: usb-storage 2-1.2:1.0
      [ 2359.795673] usbcore: registered new interface driver usb-storage
      [ 2360.802478] scsi 0:0:0:0: Direct-Access      USB      SanDisk 3.2Gen1 1.00 PQ: 0 ANSI: 6
      [ 2360.811765] sd 0:0:0:0: [sda] 30031872 512-byte logical blocks: (15.4 GB/14.3 GiB)
      [ 2360.820424] sd 0:0:0:0: [sda] Write Protect is off
      [ 2360.831340] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
      [ 2360.862799]  sda:
      [ 2360.870177] sd 0:0:0:0: [sda] Attached SCSI removable disk
    
  • Re-run the ‘lsusb’ command and verify that the USB drive connected to bus 002.

    Target (Linux)
     lsusb
    
    Expected Output
    root@phyboard-electra-am64xx-1:device# lsusb
    Bus 002 Device 003: ID 0781:5591
    Bus 002 Device 002: ID 0451:8240
    Bus 002 Device 001: ID 1d6b:0003
    Bus 001 Device 002: ID 0451:8242
    Bus 001 Device 001: ID 1d6b:0002
    
  • To list more information about the USB device and buses on the development kit use the following command.

    This command will output a good chunk of information. This guide will only show a snippet of the expected output for the USB drive that was just connected.

    Target (Linux)
    lsusb -v
    
    Expected Output for Example USB Drive
    Bus 002 Device 003: ID 0781:5591
    Device Descriptor:
    bLength                18
    bDescriptorType         1
    bcdUSB               3.00
    bDeviceClass            0
    bDeviceSubClass         0
    bDeviceProtocol         0
    bMaxPacketSize0         9
    idVendor           0x0781
    idProduct          0x5591
    bcdDevice            1.00
    iManufacturer           1  USB
    iProduct                2  SanDisk 3.2Gen1
    iSerial                 3 0401a83fbd697e437712b826697973aaaf57d1c75e9691ad879dfe7934b8a81bea020000000000000000000037ac13c5ff935d18915581076e2cc649
    bNumConfigurations      1
    Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x002c
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    
      ..continues..
    
  • The speed of the USB device can be determined with either the lsusb -v from above or by reading the device’s “speed”

    Target (Linux)
    cat /sys/bus/usb/devices/2-1/speed
    
    Expected Output
    root@phyboard-electra-am64xx-1:~# cat /sys/bus/usb/devices/2-1/speed
    5000
    

    Note

    USB3.0 has transmission speeds up to 5000 Mbit/s, also known as “super speed”. USB2.0 has transmission speeds up to 480Mbit/s, also known as “full speed”.

Mounting USB Stroage Devices

  • Verify that a device directory was established for the USB drive.

    1. Run the following command to confirm the USB device name.

      Target (Linux)
      ls /dev/sd*
      
      Expected Output
      root@phyboard-electra-am64xx-1:~# ls /dev/sd*
      /dev/sda
      
    2. Remove the USB drive.

    3. Re-run the ‘ls /dev/sd’ command to confirm the device name.

      Expected Output
       root@phyboard-electra-am64xx-1:~# [ 4048.519498] usb 2-1.2: USB disconnect, device number 3
       root@phyboard-electra-am64xx-1:~# ls /dev/sd*
       ls: /dev/sd*: No such file or directory
      
    4. Re-insert the USB drive to the bottom connector of X13.

    Note

    In this example the device name for the USB drive is “sda”.

  • Make a directory for mounting the USB device.

    Target (Linux)
     mkdir ~/usb_sda
    
  • Mount the USB device to the directory.

    Target (Linux)
    mount /dev/sda ~/usb_sda/
    
  • See what media is on the USB drive.

    Target (Linux)
     ls ~/usb_sda/
    

Write to the USB Host Device

  • Generate a random 10 MB file to test transferring data from the storage device.

    Target (Linux)
    dd if=/dev/urandom of=test.file count=10 bs=1M
    
    Expected Output
    root@phyboard-electra-am64xx-1:~# dd if=/dev/urandom of=test.file count=10 bs=1M
    10+0 records in
    10+0 records out
    
  • Copy the file to your storage device.

Target (Linux)
cp test.file ~/usb_sda/ && sync

Read from the USB Host Device

  • Copy the test file we previously created during the write process back to the host:

    Target (Linux)
    cp ~/usb_sda/test.file readback-usb.file && sync
    
  • We can double check that the file was successfully copied to and from the USB device by checking the md5sum of the file:

    Target (Linux)
    md5sum test.file readback-usb.file
    
    Expected Output
    root@phyboard-electra-am64xx-1:~# md5sum test.file readback-usb.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  test.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  readback-usb.file
    

Unmounting the Drive

Warning

Make sure the drive is unmounted prior to physically disconnecting the device. Failure to do so may result in loss of data and corruption of files

Target (Linux)
umount ~/usb_sda/