USB Testing

Device Modes

Host Mode

The development board acts as a USB host, responsible for powering connected slave devices and controlling data transmission.


Device/Peripheral Mode

The device operates as a slave device (controlled by the host) and cannot connect to other USB devices.


OTG Mode (On-The-Go)

The device can dynamically switch between Host Mode and Device Mode without a fixed role.

Device Tree Modification

Modify the device tree file according to the following project path:

image-20250714173454991

Add the following content to this file:

Kernel Configuration for USB as Virtual Serial Port

References:

1.https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842272/Zynq+Linux+USB+Device+Driver

2.https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841624/Zynq-7000+AP+SoC+USB+CDC+Device+Class+Design+Example+Techtip

Use the command:

In the character interface that pops up, enable the following content: The driver can be compiled into the kernel or compiled as a kernel module to be dynamically loaded after system startup. It is recommended to compile it as a kernel module.

Recompilation

Use the command

Copy the recompiled kernel and device tree to the SD card. Power on and load the system, then manually load the kernel modules in the console or telnet:

You will see the /dev/ttyGS0 device:

image-20250715104809779

If you don't want to manually load the kernel modules every time you power on, you can write these commands into a startup script to automatically load it after power-on.

Testing USB

As Host

Prepare a USB drive in advance (must be FAT32 format), and create several documents on it using a computer, such as creating two documents named a.txt and b.txt.

Short-circuit JP2 and JP3 on the development board with jumper caps. After powering on and starting up, insert the USB drive into the OTG corresponding Type-C interface (a Type-C to Type-A female adapter is required). The following prompt information will be seen on the console serial port:

image-20250715105713572

Next, enter the command to view the USB drive mounting and memory usage:

image-20250715110308923

You can see the mount point is located at "/run/media/sda1". According to the USB drive position shown in the image above, enter cd /run/media/sda1 to access the USB drive.

Next, you can enter "ls" to view the contents of the USB drive:

image-20250715143127796

You can see there are two files, a.txt and b.txt, in the folder. You can also directly modify the contents of the USB drive.

OTG Mode

Since we enabled USB CDC during kernel configuration, when connected to a computer via a USB cable, this USB will be virtualized as a serial port.

After normal power-on and system startup, first load the kernel modules corresponding to the virtual serial port mentioned earlier. Then connect the development board to the computer using a USB cable with Type-C connectors on both ends. You will see two serial ports in the serial debugging assistant, where COM11 is the virtual serial port created by the USB OTG interface, and COM12 is the console serial port of the Zynq Linux system.

image-20250715113039885

The virtual serial port corresponds to /dev/ttyGS0 on the Zynq.

9c36b01f-3723-4361-ad8c-843a5e21fa39

The received data will be displayed on the computer's serial terminal:

c188e68c-74a3-4567-9c0f-ba140de34798

Note: In the terminal, sending and receiving serial data both use '\n' as the termination condition. That is, sent data will append '\n', and received data must echo upon receiving '\n'.

97e8b7b0-39f2-4343-a71e-3851c899638e