USB

The Universal Serial Bus (USB) can be utilized for many functions on the phyBOARD-Lynx AM62Px, including external media. The phyBOARD-Lynx AM62Px provides multiple USB connectors, as detailed in USB Locations. This guide will show you how to use the USB Host capabilities featured on the phyBOARD-Lynx AM62Px. To learn more information about the phyCORE-AM62Px USB interface, please see section 7.6 in the Hardware Manual.

The USB0 interface is brought out as a USB-C connector (X8). The USB1 interface connects to a TUSB4041I USB 2.0 hub (U37), which splits the bus to the double stacked USB-A connector (X11) and the M.2 Key E connector (X20).

USB Locations

Type

Qty

Header Location

Controller

Speed

USB-A Double Stacked

2

X11

USB1, hub ports 1 (lower) and 2 (upper)

USB 2.0 High-Speed

M.2 Key E

1

X20

USB1, hub port 3

USB 2.0 High-Speed

USB-C

1

X8

USB0

USB 2.0 High-Speed

The USB-C port role is selected with jumper JP11:

USB-C Port Role (JP11)

JP11

Port Role

Open (default)

Dual-Role Port (DRP)

1+2

Downstream Facing Port (DFP, host)

2+3

Upstream Facing Port (UFP, device)

phyCORE-AM62Px USB

Requirements

  • USB Storage Device

Verifying USB Interface

  • Boot into Linux and Insert a USB Storage Device into one of the USB ports.

  • Upon insertion, kernel output should appear.

  • Verify the available USB devices.

In this example a USB storage device is inserted in both the lower and upper USB-A ports of X11.

phyboard-lynx-am62pxx-1:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
Bus 001 Device 003: ID 0781:5591 SanDisk Corp. Ultra Flair
Bus 001 Device 004: ID 0781:5591 SanDisk Corp. Ultra Flair
  • 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.

    phyboard-lynx-am62pxx-1:~# lsusb -v
    
  • The speed of the USB device can be determined with either the lsusb -v from above or by reading the device’s “speed”

phyboard-lynx-am62pxx-1:~# lsusb -t
/:  Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci-hcd/1p, 480M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 001: Dev 003, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        |__ Port 002: Dev 004, If 0, Class=Mass Storage, Driver=usb-storage, 480M

Hub port 1 is the lower and hub port 2 the upper USB-A port of X11.

Note

USB2.0 has transmission speeds up to 480Mbit/s, also known as “high speed”.

Using a USB Storage Device

Find the Device Name

  • The kernel output shown when the drive was inserted names it (sda in the example above). You can also list the block devices:

    phyboard-lynx-am62pxx-1:~# ls /dev/sd*
    /dev/sda  /dev/sda1
    

    Note

    sda is the whole drive and sda1 is the first partition on it. A drive formatted without a partition table only shows sda.

  • Create a mount point for the drive:

    phyboard-lynx-am62pxx-1:~# mkdir -p /mnt/usb
    

Continue with the section that matches your drive: Accessing Files on a USB Drive with Data to work with the files already on it, or Formatting a New USB Drive to start with an empty drive.

Accessing Files on a USB Drive with Data

  • Mount the partition that holds the data. Use /dev/sda instead if the drive has no partition table:

    phyboard-lynx-am62pxx-1:~# mount /dev/sda1 /mnt/usb
    
  • List the files on the drive:

    phyboard-lynx-am62pxx-1:~# ls /mnt/usb
    
  • Copy a file to the drive:

    phyboard-lynx-am62pxx-1:~# echo "Hello from the phyBOARD-Lynx AM62Px" > hello.txt
    phyboard-lynx-am62pxx-1:~# cp hello.txt /mnt/usb/
    
  • Copy a file from the drive back to the board:

    phyboard-lynx-am62pxx-1:~# cp /mnt/usb/hello.txt ~/hello-from-usb.txt
    phyboard-lynx-am62pxx-1:~# cat ~/hello-from-usb.txt
    Hello from the phyBOARD-Lynx AM62Px
    

Formatting a New USB Drive

Warning

Formatting erases all data on the drive. Make sure you selected the right device name, and that the drive is not mounted.

  • Format the whole drive with a FAT file system:

    phyboard-lynx-am62pxx-1:~# mkfs.vfat /dev/sda
    
  • Mount the drive:

    phyboard-lynx-am62pxx-1:~# mount /dev/sda /mnt/usb
    
  • The drive is now empty and ready to use. To check that data is written to and read back from the drive correctly, continue with Verifying Data Transfer.

Verifying Data Transfer

This test writes a file with random content to the drive and reads it back. Unmounting and mounting the drive in between ensures the file is read from the drive and not from memory.

  • Generate a random 10 MB file and copy it to the drive. Use the device name you mounted above (/dev/sda or /dev/sda1):

    phyboard-lynx-am62pxx-1:~# dd if=/dev/urandom of=test.file count=10 bs=1M
    10+0 records in
    10+0 records out
    10485760 bytes (10 MB, 10 MiB) copied, 0.161874 s, 64.8 MB/s
    phyboard-lynx-am62pxx-1:~# cp test.file /mnt/usb/
    phyboard-lynx-am62pxx-1:~# umount /mnt/usb
    phyboard-lynx-am62pxx-1:~# mount /dev/sda /mnt/usb
    
  • Copy the file back from the drive and compare the checksums:

    phyboard-lynx-am62pxx-1:~# cp /mnt/usb/test.file readback-usb.file
    phyboard-lynx-am62pxx-1:~# md5sum test.file readback-usb.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  test.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  readback-usb.file
    

    Both checksums must match.

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. umount writes all pending data to the drive before it returns.

phyboard-lynx-am62pxx-1:~# umount /mnt/usb