Linux USB DWC3 Host/Peripheral Driver


WARNING

We could not get USB 3.0 to work with the USB Micro-B to A adapter that came with the ZCU102. It only worked with a direct cable from our hard drive enclosure to the Micro-B connector on the eval board without requiring an adaptor. With the adaptor in place it always fell back to USB 2.0.

Configuration
CONFIG_USB_DWC3=y
CONFIG_USB_DWC3_DUAL_ROLE=y
CONFIG_USB_LIBCOMPOSITE=m
CONFIG_USB_F_MASS_STORAGE=m
CONFIG_USB_CONFIGFS=m
CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_SUPPORT=y
CONFIG_USB_COMMON=y
CONFIG_USB_ARCH_HAS_HCD=y
CONFIG_USB=y
CONFIG_USB_XHCI_HCD=y
CONFIG_USB_XHCI_PLATFORM=y

Devicetree

        usb@0 {
            #address-cells = <0x2>;
            #size-cells = <0x1>;
            status = "okay";
            compatible = "xlnx,zynqmp-dwc3";
            clock-names = "bus_clk" "ref_clk";
            clocks = <&clk125>, <&clk125>;
            ranges;
 
            dwc3@fe200000 {
                compatible = "snps,dwc3";
                reg = <0x0 0xfe200000 0x40000>;
                interrupts = <0x0 0x41 0x4>;
                dr_mode = "host";
            };
        };

Testing Device mode

ZCU102 Board Setup

Jumper settings

J7
OFF
J110
1-2
J113
1-2

Connect USB cable to the connector (J96) on board(this is Mass Storage Device connector)
Other end of the cable will be connected to Host PC to detect the Mass Storage Device

Linux

Create a temporary storage area, that acts as Pen Drive
zynq> dd if=/dev/zero of=/tmp/my_file bs=256 count=1048576
Insert the Mass Storage Device modules
zynqMP> insmod /lib/modules/'uname -r'/kernel/fs/configfs.ko
zynqMP> insmod /lib/modules/'uname -r'/kernel/drivers/usb/gadget/libcomposite.ko
zynq> insmod /lib/modules/'uname -r'/kernel/drivers/usb/gadget/functions/usb_f_mass_storage.ko
zynq> insmod /lib/modules/'uname -r'/kernel/drivers/usb/gadget/legacy/g_mass_storage.ko file=/tmp/my_file removable=1

Host PC detects our device as pen drive and prompts for formatting it. Format it and copy any files to it and disconect cable from PC and reconnect.
You should see drive with files you copied earlier.

Testing Host mode

ZCU102 Board Setup

Jumper settings

J7
ON
J110
2-3
J113
1-2

Connect a Pendrive to the connector (J96) on board

Linux

Linux running on our subsystem detects the pen drive connected and the terminal shows the device recognition messages (example: sda: sda1).

If the device only comes up as a USB 2.0 device then check your cable, see the warning at the top of the page.

Interoperability Testing:

USB 2.0

Host Mode

  1. Pendrive
  2. Low speed Mouse and Keyboard

Device Mode

  1. Mass storage gadget
  2. Ethernet gadget with iperf

USB 3.0


Host Mode

  1. Pendrive(SanDisk Ultra Fit [16G])
  2. Samsung 850 Evo 500GB using Delock USB3.0 enclosure
  3. Low speed Mouse and Keyboard

Device Mode

  1. Mass storage gadget
  2. Ethernet gadget with iperf