22. USB¶
Video introduction to this chapter:

“26-LubanCat USB-OTG function switching”
https://www.bilibili.com/video/BV1Cs4y1e7Bc
The following table shows the usb of LubanCat-RK series boards
Board name |
USB3.0 |
USB2.0 |
USB2.0-OTG |
---|---|---|---|
LubanCat-Zero Series |
None |
Type-C x 1 |
Type-C x 1 |
LubanCat-1 |
Type-A x 1 |
Type-A x 3 |
Type-C x 1 |
LubanCat-1N |
Type-A x 1 |
Type-A x 1 |
Type-C x 1 |
LubanCat-2 |
Type-A x 1 |
Type-A x 2 |
Type-C x 1 |
22.1. USB-OTG function switching¶
The usb device distinguishes between master and slave, where host is the master device and device is the slave device. USB-otg can perform master-slave switching.
A slave device, such as a USB flash drive, can only be controlled, and cannot actively control other USB devices. The usb interface of the computer is used as the master device, which can control the slave device.
With hardware switching circuit: LubanCat 2 LubanCat 2N.
LubanCat 0/1 series is not equipped with an automatic switching circuit, because the usb port and power interface of the LubanCat 0/1 series are multiplexed. When using the power supply, it does not have the usb function. When powered by a computer, it is used as a device by default.
22.1.1. LubanCat 2 series manual switching¶
1 2 3 4 5 6 7 8 | #Force host mode host
echo host > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
#Force device mode slave
echo peripheral > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
#Force otg mode Automatic switching based on hardware recognition
echo otg > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
|
22.1.2. LubanCat 0/1 series manual switching¶
1 2 3 4 5 6 7 | #Force host mode host
echo host > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
#Force device mode slave
echo peripheral > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
or
echo otg > /sys/devices/platform/fe8a0000.usb2-phy/otg_mode
|
22.1.3. LubanCat 0/1 series otg uses host mode prompt¶
LubanCat 0/1 series, if LubanCat 0 wants to be used as the host device, it can be switched manually. But generally speaking, slave devices do not have power supply, such as mouse, keyboard, and U disk, all of which require power supply from the master device. We need to solve the power supply problem of LubanCat.
There are two power supply options:
Use the power supply pin of LubanCat’s 40PIN header to supply power to LubanCat. (Only supports LubanCat 0/1 series)
While using the type-c interface for power supply, you can also connect the usb from the device to the LubanCat. The specific implementation method is as follows
Use an adapter board with an independent power supply or a magic-modified usb cable, and use an external power supply to power both the LubanCat and the usb slave device at the same time (the magic-modified device is risky, please consider it carefully).
Use usbhub to connect LubanCat, and then supply power to usbhub. The usbhub is a slave device (some usbhubs may not support this function).
22.2. USB-OTG configuration function (usb gadget)¶
22.2.1. Configuration files and parameters¶
/etc/init.d/.usb_config Default configuration file, called when the system starts.
/tmp/.usb_config is the copy file of the default configuration file. After the system starts, the priority is higher than the default configuration file, and it will fail after restarting.
/usr/bin/usbdevice service configuration script, use call
/usr/bin/usbdevice {start|stop|restart}
22.2.2. Function configuration¶
Configurable features
usb_adb_en - ADB test
usb_rndis_en - RNDIS USB analog Ethernet
usb_acm_en - ACM USB virtual serial port
usb_ums_en - UMS virtual storage device
usb_uac1_en - UAC virtual sound card
usb_uac2_en - UAC virtual sound card
22.2.3. ADB test¶
1 2 3 4 5 | #Configuration function
echo usb_adb_en > /etc/init.d/.usb_config
#Apply functions (use the command below or restart)
/usr/bin/usbdevice restart
|
22.2.4. RNDIS USBAnalog Ethernet¶
22.2.4.1. Temporary configuration (function disappears after restart)¶
1 2 3 4 5 | #Configuration function
echo usb_rndis_en > /tmp/.usb_config
#Apply functions
/usr/bin/usbdevice restart
|
22.2.4.2. permanent configuration¶
1 2 3 4 5 | #Configuration function
echo usb_rndis_en > /etc/init.d/.usb_config
#Apply functions (use the command below or restart)
/usr/bin/usbdevice restart
|
22.2.5. ACM USBvirtual serial port¶
After enabling ACM, you can see the /dev/ttyGS0 device on the Device, and the /dev/ttyACM0 device on the PC
22.2.5.1. Temporary configuration (function disappears after restart)¶
1 2 3 4 5 | #configuration function
echo usb_acm_en > /tmp/.usb_config
#Apply functions
/usr/bin/usbdevice restart
|
22.2.5.2. Permanent configuration¶
1 2 3 4 5 | #Configuration function
echo usb_acm_en > /etc/init.d/.usb_config
#Apply functions (use the command below or restart)
/usr/bin/usbdevice restart
|
22.2.6. UMS virtual storage device¶
Mount a partition or an img image in the file system of the board to the PC.
It is recommended to use the img image to mount, and use the following configuration to automatically generate the img file.
1 2 3 4 5 6 7 8 9 | echo usb_ums_en > /tmp/.usb_config
# Configure the mirror file address to mount
echo "ums_block=/ums_shared.img" >> /tmp/.usb_config
# Set the image file size, in MB
echo "ums_block_size=8" >> /tmp/.usb_config
# Set the file system format to fat
echo "ums_block_type=fat" >> /tmp/.usb_config
# Set to automatically mount to the /mnt/ums directory after disconnecting UMS
echo "ums_block_auto_mount=on" >> /tmp/.usb_config
|
22.2.6.1. Permanent configuration¶
1 2 3 4 5 6 7 8 9 | #Configuration function
echo usb_ums_en > /etc/init.d/.usb_config
echo "ums_block=/ums_shared.img" >> /etc/init.d/.usb_config
echo "ums_block_size=8" >> /etc/init.d/.usb_config
echo "ums_block_type=fat" >> /etc/init.d/.usb_config
echo "ums_block_auto_mount=on" >> /etc/init.d/.usb_config
#Apply functions (use the command below or restart)
/usr/bin/usbdevice restart
|
22.2.7. UAC virtual sound card¶
UAC sends the host device through the USB virtual standard PCM interface to realize the audio transmission function between the device and the host.
- UAC is divided into UAC1 and UAC2, UAC2 and UAC1 have the following differences:
UAC2 has a higher bandwidth than UAC1 (the implementation of each platform is slightly different, the actual measurement shall prevail) Windows 7 and some Windows 10 systems do not support UAC2 by default, and need to manually install the driver, but all support UAC1
22.2.7.1. Temporary configuration (function disappears after restart)¶
1 2 3 4 5 6 7 8 | #Configuration function
echo usb_uac1_en > /tmp/.usb_config
#Or
echo usb_uac2_en > /tmp/.usb_config
#Application function
/usr/bin/usbdevice restart
|
22.2.7.2. Permanent configuration¶
1 2 3 4 5 6 7 8 | #Configuration function
echo usb_uac1_en > /etc/init.d/.usb_config
#Or
echo usb_uac2_en > /etc/init.d/.usb_config
#Apply functions (use the command below or restart)
/usr/bin/usbdevice restart
|
22.3. USB speed test¶
Board name |
Write speed |
Read speed |
---|---|---|
LubanCat-Zero Series |
32.45MB/s |
35.8MB/s |
LubanCat-1 |
33.3MB/s |
36.3MB/s |
LubanCat-1N |
MB/s |
MB/s |
LubanCat-2 |
33MB/s |
36.5MB/s |
Board name |
Write speed |
Read speed |
---|---|---|
LubanCat-1 |
170MB/s |
380MB/s |
LubanCat-1N |
MB/s |
MB/s |
LubanCat-2 |
138.5MB/s |
387MB/s |