USB
The Universal Serial Bus (USB) can be utilized for many functions on the phyFLEX-Libra AM62Px, including external media. The phyFLEX-Libra 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 phyFLEX-Libra AM62Px.
The USB0 interface is brought out as a USB-C connector that supports both host and device mode (USB role switching). The USB1 interface is connected to a 4-port USB hub (U21), which provides the dual USB Type-A connector X16 and also connects to the M.2 Key-E slot and the AV connector.
Interface |
Connector |
Mode |
Speed |
|---|---|---|---|
USB0 |
X18 (USB-C) |
Dual-role (host/device) |
USB 2.0 High-Speed |
USB1 |
X16 (dual USB Type-A, via hub U21) |
Host |
USB 2.0 High-Speed |
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.
[ 175.065883] usb 1-1.4: new high-speed USB device number 3 using xhci-hcd
[ 175.161972] usb-storage 1-1.4:1.0: USB Mass Storage device detected
[ 175.168845] scsi host0: usb-storage 1-1.4:1.0
[ 176.175455] scsi 0:0:0:0: Direct-Access USB SanDisk 3.2Gen1 1.00 PQ: 0 ANSI: 6
[ 176.193718] sd 0:0:0:0: [sda] 120164352 512-byte logical blocks: (61.5 GB/57.3 GiB)
[ 176.202728] sd 0:0:0:0: [sda] Write Protect is off
[ 176.207576] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[ 176.208005] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 176.276826] sda: sda1
[ 176.279972] sd 0:0:0:0: [sda] Attached SCSI removable disk
Verify the available USB devices.
am62pxx-phyflex-libra-rdk-1:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0451:8242 Texas Instruments, Inc.
Bus 001 Device 003: ID 0781:55a9 SanDisk Corp. SanDisk 3.2Gen1
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.
am62pxx-phyflex-libra-rdk-1:~# lsusb -v
The speed of the USB device can be determined with either the
lsusb -vfrom above or by reading the device’s “speed”
am62pxx-phyflex-libra-rdk-1:~# cat /sys/bus/usb/devices/1-1.4/speed
480
Replace 1-1.4 with the device path from the kernel output shown when the drive was inserted (usb 1-1.4: new high-speed USB device).
Note
USB 2.0 High-Speed has transmission speeds up to 480Mbit/s.
Using a USB Storage Device
Find the Device Name
The kernel output shown when the drive was inserted names it (
sdain the example above). You can also list the block devices:am62pxx-phyflex-libra-rdk-1:~# ls /dev/sd* /dev/sda /dev/sda1
Note
sdais the whole drive andsda1is the first partition on it. A drive formatted without a partition table only showssda.Create a mount point for the drive:
am62pxx-phyflex-libra-rdk-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/sdainstead if the drive has no partition table:am62pxx-phyflex-libra-rdk-1:~# mount /dev/sda1 /mnt/usb
List the files on the drive:
am62pxx-phyflex-libra-rdk-1:~# ls /mnt/usb
Copy a file to the drive:
am62pxx-phyflex-libra-rdk-1:~# echo "Hello from the phyFLEX-Libra AM62Px" > hello.txt am62pxx-phyflex-libra-rdk-1:~# cp hello.txt /mnt/usb/
Copy a file from the drive back to the board:
am62pxx-phyflex-libra-rdk-1:~# cp /mnt/usb/hello.txt ~/hello-from-usb.txt am62pxx-phyflex-libra-rdk-1:~# cat ~/hello-from-usb.txt Hello from the phyFLEX-Libra 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:
am62pxx-phyflex-libra-rdk-1:~# mkfs.vfat /dev/sda
Mount the drive:
am62pxx-phyflex-libra-rdk-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/sdaor/dev/sda1):am62pxx-phyflex-libra-rdk-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 am62pxx-phyflex-libra-rdk-1:~# cp test.file /mnt/usb/ am62pxx-phyflex-libra-rdk-1:~# umount /mnt/usb am62pxx-phyflex-libra-rdk-1:~# mount /dev/sda /mnt/usb
Copy the file back from the drive and compare the checksums:
am62pxx-phyflex-libra-rdk-1:~# cp /mnt/usb/test.file readback-usb.file am62pxx-phyflex-libra-rdk-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.
am62pxx-phyflex-libra-rdk-1:~# umount /mnt/usb