Building Linux usb device drivers with 2021.1

The guide below shows you how to build USB drivers & boot the board and then run some example configurations (Host, Device, OTG mode of PS USB controller ) on Versal platform.
The steps below use PetaLinux and assume you have some knowledge of using PetaLinux.

Table of Contents

Introduction

  • The USB controller can be configured as host, device, or on-the-go (OTG).

  • The core is compliant to USB 2.0 specification and supports high, full, and low-speed modes in all configurations.

  • In host mode, the USB controller is compliant with the Intel XHCI specification. In device mode, it supports up to 12 end points.

  • The universal low peripheral interface (ULPI) is used to connect the controller to an external PHY operating up to 480 Mb/s.

  • Versal supports only USB 2.0 protocol.

  • Provided below test cases are proven on vck190-es1 board with 2021.1 release.

 

ZynqMP Vs Versal USB controller support

Peripheral

Zynq UltraScale+ MPSOC

Versal ACAP

USB 3.0 (host, device, dual-role device)

2 controllers

N/A

Usb 2.0 (host, device, on-the-go)

2 controllers

1 controller

Hardware Setup

Boards:  VCK190-ES1 Board

Host Machine: Linux Machine with USB ports (OR) Windows Machine

Software Setup

Linux Kernel image with xHCI Host enabled (static) and Mass Storage Gadget created as static or dynamic

  • Boot image for initial FSBL sequence

  • Device tree with DWC USB DWC3_DUAL mode enabled

Petalinux build steps

1 2 3 4 5 source <PATH TO PETALINUX INSTALLATION>/petalinux-v2021.1-final/settings.sh petalinux-create -t project -s <PATH to BSP>/xilinx-vck190-es1-v2021.1-final.bsp petalinux-config petalinux-build petalinux-package --boot --plm --psmfw --u-boot --dtb

Host Mode

USB HOST mode Jumper settings

Note: Need to short the J300 Jumper  for Host Mode

Jumper 1-2   –---  short (The shield for the USB 2.0 type-A connector (J308) can be tied to GND by a jumper on header J300 pins 1-2 (default))

Kernel Configuration

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y

Device Tree

Edit the following file and make the following changes.

“<path to petalinux project >/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi"

After the build is finished, we should see below device tree changes in system.dts file once after converting system.dtb to sytem.dts using  " dtc -I dtb -O dts -o system.dts system.dtb" command.

Note: dtc command by default not available on host side , please install using the “sudo apt-get install device-tree-compiler” command.

Test Procedure

Connect the USB 3.0/2.0 pendrive to USB 2.0 capable board and see it getting detected in /dev/sd<x>.

Logs

Once Linux boots the below highlighted prints should be visible when we connected the mass storage device

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 root@xilinx-vck190-es1-2021.1 :~#root@xilinx-vck190-es1-2021.1 :~# [ 40.344230] usb 1-1: new high-speed USB device number 2 using xhci-hcd [ 40.497113] usb 1-1: New USB device found, idVendor=8564, idProduct=1000, bcdDevice=11.00 [ 40.505293] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 40.512428] usb 1-1: Product: Mass Storage Device [ 40.517134] usb 1-1: Manufacturer: JetFlash [ 40.521315] usb 1-1: SerialNumber: 152RHUF276CIFPSR [ 40.526966] usb-storage 1-1:1.0: USB Mass Storage device detected [ 40.533570] scsi host0: usb-storage 1-1:1.0 [ 41.949684] scsi 0:0:0:0: Direct-Access JetFlash Transcend 32GB 1100 PQ: 0 ANSI: 6 [ 41.960284] sd 0:0:0:0: [sda] 59725824 512-byte logical blocks: (30.6 GB/28.5 GiB) [ 41.968608] sd 0:0:0:0: [sda] Write Protect is off [ 41.973581] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [ 41.984408] sda: sda1 [ 41.987825] sd 0:0:0:0: [sda] Attached SCSI removable disk [ 42.146068] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Peripheral Mode

USB  jumper settings for Peripheral mode

Note: Need to open the J300 Jumper  for device mode.

Jumper 1-2   –---  Open (The shield for the USB 2.0 type-A connector (J308) can be disconncted/floating from GND by removing the jumper on header J300 pins 1-2 (default))

Note: This same peripheral mode Jumpers can be used for all the Gadgets .

Kernel configurations

This document only explains the USB 2.0 peripheral mode configurations for MASS STORAGE gadget
    Device Drivers --->[*] USB support ---> <*> USB Gadget Support --->  

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y

Device Tree

Edit the following file and make the following changes.

"<path to petalinux project >/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi"

Steps to test peripheral mode

Please use the below settings for configuring USB as MASS STORAGE profile in device mode:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 dd if=/dev/zero of=/tmp/mydev count=500 bs=1M mount -t configfs none /sys/kernel/config cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB echo "0x100" > bcdDevice echo "0x03FD" > idVendor echo "0x0501" > idProduct cat max_speed echo "high-speed" > max_speed mkdir functions/mass_storage.ms0 mkdir configs/c1.1 echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file echo 1 > functions/mass_storage.ms0/lun.0/removable ln -s functions/mass_storage.ms0/ configs/c1.1/ echo "fe200000.dwc3" > UDC


Testing the mass storage functionality by connecting the board to windows host using the below steps:

  1. Connect the cable from board to windows host machine

  2. Format the mass storage device that got detected in windows

  3. The windows screen shot when we the device gets detected should be as below

  1. The board will be detected as mass storage drive with size 256 MB

5 .Copy some files into the mass storage drive , remove the cable and connect it again. We should be able to see the files that we copied into the drive.

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 root@xilinx-vck190-es1-2021_1:~# root@xilinx-vck190-es1-2021_1:~# dd if=/dev/zero of=/tmp/mydev count=500 bs=1M -t configfs none /sys/kernel/config cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB echo "0x100" > bcdDevice echo "0x03FD" > idVendor echo "0x0501" > idProduct cat max_speed echo "high-speed" > max_speed mkdir functions/mass_storage.ms0 mkdir configs/c1.1 echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file echo 1 > functions/mass_storage.ms0/lun.0/removable ln -s functions/mass500+0 records in 500+0 records out _storagroot@xilinx-vck190-es1-2021_1:~# mount -t configfs none /sys/kernel/config fmount: mounting none on /sys/kernel/config failed: Device or resource busy igs/c1.1/ root@xilinx-vck190-es1-2021_1:~# cd /sys/kernel/config/usb_gadget root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# mkdir g1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# cd g1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "64" > bMaxPacketSize0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x200" > bcdUSB root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x100" > bcdDevice root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x03FD" > idVendor root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x0501" > idProduct root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# cat max_speed super-speed root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "high-speed" > max_speed root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir functions/mass_storage.ms0 [ 108.770916] Mass Storage Function, version: 2009/09/11 [ 108.776065] LUN: removable file: (no medium) root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir configs/c1.1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo 1 > functions/mass_storage.ms0/lun.0/removable root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ln -s functions/mass_storage.ms0/ configs/c1.1/ root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "fe200000.dwc3" > UDC root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# [ 109.920065] configfs-gadget gadget: high-speed config #1: c1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1#

If we connect the cable from board to Linux host machine then below are the logs:

Linux Host side logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [ 1889.513389] usb 1-4.4: new full-speed USB device number 7 using xhci_hcd [ 1889.529905] usb 1-4.4: No LPM exit latency info found. Power management will be impacted. [ 1889.530091] usb 1-4.4: not running at top speed; connect to a high speed hub [ 1889.530459] usb 1-4.4: New USB device found, idVendor=03fd, idProduct=0501 [ 1889.530506] usb 1-4.4: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 1889.531755] usb-storage 1-4.4:1.0: USB Mass Storage device detected [ 1889.532018] scsi4 : usb-storage 1-4.4:1.0 [ 1890.529854] scsi 4:0:0:0: Direct-Access Linux File-Stor Gadget 0510 PQ: 0 ANSI: 2 [ 1890.530478] sd 4:0:0:0: Attached scsi generic sg0 type 0 [ 1890.531491] sd 4:0:0:0: [sda] 1024000 512-byte logical blocks: (524 MB/500 MiB) [ 1890.531821] sd 4:0:0:0: [sda] Write Protect is off [ 1890.531845] sd 4:0:0:0: [sda] Mode Sense: 0f 00 00 00 [ 1890.532184] sd 4:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [ 1890.549664] sda: unknown partition table [ 1890.551541] sd 4:0:0:0: [sda] Attached SCSI removable disk

 

OTG Mode

USB  jumper settings for OTG mode

Kernel Configurations

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y

Device Tree

Edit the following file and make the following changes.

 "<path to petalinux project >/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi"

Steps to test OTG

When the Linux kernel boots up, give the below commands:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 dd if=/dev/zero of=/tmp/mydev count=500 bs=1M mount -t configfs none /sys/kernel/config cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB echo "0x100" > bcdDevice echo "0x03FD" > idVendor echo "0x0501" > idProduct cat max_speed echo "high-speed" > max_speed mkdir functions/mass_storage.ms0 mkdir configs/c1.1 echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file echo 1 > functions/mass_storage.ms0/lun.0/removable ln -s functions/mass_storage.ms0/ configs/c1.1/ echo "fe200000.dwc3" > UD

Peripheral Mode

  • Connect board to any Host PC via USB Std-A-Male to Micro-B-Male cable.

  • It should be detected as a Mass Storage Device

  • Do some data transfers

Host Mode

  • Connect any pen-drive with the board via USB Micro-A-Male to Std-A-Female type connector

  • Check that the pen-drive is detected properly

  • Do some data transfers.

Note : Both Host and Peripheral mode should work without resetting/rebooting the board.

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:~# root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:~# dd if=/dev/zero of=/tmp/mydev count=500 bs=1M -t configfs none /sys/kernel/config cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB echo "0x100" > bcdDevice echo "0x03FD" > idVendor echo "0x0501" > idProduct cat max_speed echo "high-speed" > max_speed mkdir functions/mass_storage.ms0 mkdir configs/c1.1 echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file echo 1 > functions/mass_storage.ms0/lun.0/removable ln -s functions/mass_storage.ms0/ configs/500+0 records in 500+0 records out c1.1/ ecroot@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:~# mount -t configfs none /sys/kernel/config .mount: mounting none on /sys/kernel/config failed: Device or resource busy dwc3" > UDCroot@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:~# cd /sys/kernel/config/usb_gadget root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget# mkdir g1 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget# cd g1 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "64" > bMaxPacketSize0 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x200" > bcdUSB root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x100" > bcdDevice root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x03FD" > idVendor root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x0501" > idProduct root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# cat max_speed super-speed root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "high-speed" > max_speed root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir functions/mass_storage.ms0 [ 488.648805] Mass Storage Function, version: 2009/09/11 [ 488.653966] LUN: removable file: (no medium) root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir configs/c1.1 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo 1 > functions/mass_storage.ms0/lun.0/removable root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ln -s functions/mass_storage.ms0/ configs/c1.1/ root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "fe200000.dwc3" > UDC root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:/sys/kernel/config/usb_gadget/g1# [ 939.938153] configfs-gadget gadget: high-speed config #1: c1

Remove the USB cable connected between host and target board & connect the USB flash storage drive(pendrive) & check is it properly detected or not.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 root@xilinx-vc-p-a2197-00-reva-x-prc-04-reva-es1-2021_1:~#When the Linux kernel boots up, give the below command usb 1-1: new high-speed USB device number 2 using xhci-hcd usb 1-1: New USB device found, idVendor=8564, idProduct=1000, bcdDevice=11.00 usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 1-1: Product: Mass Storage Device usb 1-1: Manufacturer: JetFlash usb 1-1: SerialNumber: 152RHUF276CIFPSR usb-storage 1-1:1.0: USB Mass Storage device detected scsi host0: usb-storage 1-1:1.0 scsi 0:0:0:0: Direct-Access JetFlash Transcend 32GB 1100 PQ: 0 ANSI: 6 sd 0:0:0:0: [sda] 59725824 512-byte logical blocks: (30.6 GB/28.5 GiB) sd 0:0:0:0: [sda] Write Protect is off sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA sda: sda1 sd 0:0:0:0: [sda] Attached SCSI removable disk

Host machine side logs

1 2 3 4 5 6 7 8 9 10 11 12 13 [69588.590462] usb 1-1: new high-speed USB device number 6 using xhci_hcd [69588.607166] usb 1-1: New USB device found, idVendor=03fd, idProduct=0501 [69588.607187] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [69588.614259] usb-storage 1-1:1.0: USB Mass Storage device detected [69588.614940] scsi3 : usb-storage 1-1:1.0 [69589.615213] scsi 3:0:0:0: Direct-Access Linux File-Stor Gadget 0504 PQ: 0 ANSI: 2 [69589.616623] sd 3:0:0:0: Attached scsi generic sg1 type 0 [69589.619729] sd 3:0:0:0: [sdb] 1024000 512-byte logical blocks: (524 MB/500 MiB) [69589.620070] sd 3:0:0:0: [sdb] Write Protect is off [69589.620083] sd 3:0:0:0: [sdb] Mode Sense: 0f 00 00 00 [69589.620350] sd 3:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [69589.626470] sdb: unknown partition table [69589.627554] sd 3:0:0:0: [sdb] Attached SCSI removable disk

Ethernet Gadget

Kernel Configurations

  Device Drivers --->[*] USB support ---> <*> USB Gadget Support --->  

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y


Device Tree

Edit the following file and make the following changes.

 "<path to petalinux project >/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi"

Steps to test Ethernet Gadget

Please use the below settings for configuring USB as ETHERNET gadget profile in device mode:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 mount -t configfs none /sys/kernel/config cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB echo "0x100" > bcdDevice echo "0x03FD" > idVendor echo "0x0502" > idProduct mkdir configs/c1.1 mkdir functions/rndis.rn0 ln -s functions/rndis.rn0/ configs/c1.1/ echo "fe200000.dwc3" > UDC ifconfig usb0 10.10.70.1 ifconfig usb0 up

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 root@xilinx-vck190-es1-2021_1:~# mount -t configfs none /sys/kernel/config ymount: mounting none on /sys/kernel/config failed: Device or resource busy s/kerneroot@xilinx-vck190-es1-2021_1:~# root@xilinx-vck190-es1-2021_1:~# cd /sys/kernel/config/usb_gadget root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# mkdir g1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# cd g1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "64" > bMaxPacketSize0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x200" > bcdUSB root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x100" > bcdDevice root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x03FD" > idVendor root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# echo "0x0502" > idProduct root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir configs/c1.1 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# mkdir functions/rndis.rn0 [ 63.419085] using random self ethernet address unc[ 63.423548] using random host ethernet address tions/rnroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ln -s functions/rndis.rn0/ configs/c1.1/ "root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2001_1:/sys/kernel/config/usb_gadget/g1# echo "fe200000.dwc3" > UDC [ 63.534643] usb0: HOST MAC 42:e9:cb:bc:66:92 [ 63.538953] usb0: MAC f2:17:36:0e:f5:5d fig usb0root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ifconfig usb0 10.10.70.1 iroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ifconfig usb0 up[ 63.873315] configfs-gadget gadget: high-speed config #1: c1 [ 63.879248] IPv6: ADDRCONF(NETDEV_CHANGE): usb0: link becomes ready root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1#

Note: After running the "ifconfig -a" , we should be able to see the usb0 interface with ipaddress 10.10.70.1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ifconfig -a can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 NOARP MTU:16 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:6 eth0 Link encap:Ethernet HWaddr 22:65:5D:75:A8:E9 inet addr:10.10.71.1 Bcast:10.10.71.255 Mask:255.255.255.0 inet6 addr: fe80::2065:5dff:fe75:a8e9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:22 errors:0 dropped:0 overruns:0 frame:0 TX packets:28 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3369 (3.2 KiB) TX bytes:4243 (4.1 KiB) Interrupt:16 eth1 Link encap:Ethernet HWaddr 32:51:3E:27:EA:4E BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:17 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) sit0 Link encap:IPv6-in-IPv4 NOARP MTU:1480 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) usb0 Link encap:Ethernet HWaddr F2:17:36:0E:F5:5D inet addr:10.10.70.1 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::f017:36ff:fe0e:f55d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Ping to server(host ip) root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g1# ping 10.10.x.x PING 10.10.x.x (10.10.x.x): 56 data bytes 64 bytes from 10.10.x.x: seq=0 ttl=64 time=0.377 ms 64 bytes from 10.10.x.x: seq=1 ttl=64 time=0.384 ms 64 bytes from 10.10.x.x: seq=2 ttl=64 time=0.298 ms 64 bytes from 10.10.x.x: seq=3 ttl=64 time=0.258 ms 64 bytes from 10.10.x.x: seq=4 ttl=64 time=0.253 ms 64 bytes from 10.10.x.x: seq=5 ttl=64 time=0.337 ms 64 bytes from 10.10.x.x: seq=6 ttl=64 time=0.235 ms 64 bytes from 10.10.x.x: seq=7 ttl=64 time=0.299 ms ^C --- 10.10.x.x ping statistics --- 8 packets transmitted, 8 packets received, 0% packet loss round-trip min/avg/max = 0.235/0.305/0.384 ms

Host machine side logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [ 4332.320170] usb 1-4.4: new full-speed USB device number 8 using xhci_hcd [ 4332.336696] usb 1-4.4: No LPM exit latency info found. Power management will be impacted. [ 4332.336905] usb 1-4.4: not running at top speed; connect to a high speed hub [ 4332.337383] usb 1-4.4: New USB device found, idVendor=03fd, idProduct=0502 [ 4332.337402] usb 1-4.4: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 4332.424417] cfg80211: Calling CRDA to update world regulatory domain [ 4332.441458] usbcore: registered new interface driver cdc_ether [ 4332.450650] rndis_host 1-4.4:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-4.4, RNDIS device, ae:6f:08:6e:e9:56 [ 4332.450699] usbcore: registered new interface driver rndis_host [ 4332.479897] usbcore: registered new interface driver rndis_wlan [ 4332.506501] cfg80211: World regulatory domain updated: [ 4332.506508] cfg80211: (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp) [ 4332.506512] cfg80211: (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm) [ 4332.506514] cfg80211: (2457000 KHz - 2482000 KHz @ 40000 KHz), (300 mBi, 2000 mBm) ping 10.10.70.1 PING 10.10.70.1 (10.10.70.1) 56(84) bytes of data. 64 bytes from 10.10.70.1: icmp_seq=1 ttl=64 time=0.152 ms 64 bytes from 10.10.70.1: icmp_seq=2 ttl=64 time=0.131 ms 64 bytes from 10.10.70.1: icmp_seq=3 ttl=64 time=0.115 ms 64 bytes from 10.10.70.1: icmp_seq=4 ttl=64 time=0.143 ms 64 bytes from 10.10.70.1: icmp_seq=5 ttl=64 time=0.150 ms 64 bytes from 10.10.70.1: icmp_seq=6 ttl=64 time=0.122 ms 64 bytes from 10.10.70.1: icmp_seq=7 ttl=64 time=0.097 ms 64 bytes from 10.10.70.1: icmp_seq=8 ttl=64 time=0.152 ms ^C

Composite gadget

Kernel configurations

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_F_ACM=y CONFIG_USB_F_SS_LB=y CONFIG_USB_U_SERIAL=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_ECM=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_ACM=y CONFIG_USB_CONFIGFS_ECM=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_LB_SS=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_U_SERIAL_CONSOLE=y

Device Tree 

Edit the following file and make the following changes.

<path to petalinux project >/project-spec/meta-user/recipe-bsp/device-tree/system-user.dtsi

Steps to test Composite Gadget

When the Linux kernel boots up, give the below commands:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 insmod udc-xilinx.ko mount -t configfs none /sys/kernel/config  cd /sys/kernel/config/usb_gadget/ mkdir g && cd g echo 0x1d6b > idVendor  # Linux Foundation echo 0x0104 > idProduct # Multifunction Composite Gadget echo 0x0100 > bcdDevice # v1.0.0 echo 0x0200 > bcdUSB    # USB 2.0 mkdir -p strings/0x409 echo "xxxxxxxxxxxx" > strings/0x409/serialnumber echo "xilinx"        > strings/0x409/manufacturer echo "versal"   > strings/0x409/product mkdir -p functions/acm.usb0    # serial mkdir -p functions/ecm.usb0  # network mkdir -p functions/rndis.usb0  # network mkdir -p functions/mass_storage.ms0 # mass storage dd if=/dev/zero of=/tmp/mydev count=256 bs=1M echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file  echo 1 > functions/mass_storage.ms0/lun.0/removable    mkdir -p configs/c.1 echo 250 > configs/c.1/MaxPower echo 0xE0 > configs/c.1/bmAttributes ln -s functions/rndis.usb0 configs/c.1/ ln -s functions/mass_storage.ms0/ configs/c.1/ #ln -s functions/ecm.usb0 configs/c.1/ ln -s functions/acm.usb0   configs/c.1/ ls /sys/class/udc/ > UDC

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 root@xilinx-vck190-es1-2021_1:~# mount -t configfs none /sys/kernel/config /mount: mounting none on /sys/kernel/config failed: Device or resource busy kernel/croot@xilinx-vck190-es1-2021_1:~# root@xilinx-vck190-es1-2021_1:~# cd /sys/kernel/config/usb_gadget/ root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# mkdir g && cd g root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 0x1d6b > idVendor root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 0x0104 > idProduct # Multifunction Composite Gadget root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 0x0100 > bcdDevice # v1.0.0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 0x0200 > bcdUSB # USB 2.0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p strings/0x409 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo "xxxxxxxxxxxx" > strings/0x409/serialnumber root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo "xilinx" > strings/0x409/manufacturer root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo "versal" > strings/0x409/product root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p functions/acm.usb0 # serial -proot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p functions/ecm.usb0 # network p mkdir: can't create directory 'functions/ecm.usb0': No such file or directory functionsroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p functions/rndis.usb0 # network [ 103.054675] using random self ethernet address [ 103.059147] using random host ethernet address root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p functions/mass_storage.ms0 # mass storage d[ 141.238768] Mass Storage Function, version: 2009/09/11 [ 141.243939] LUN: removable file: (no medium) ev/zero of=/root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# dd if=/dev/zero of=/tmp/mydev count=256 bs=1M tmp/mydev > functions/mass_storage.ms0/lun.0/file echo 1 > functions/mass_storage.ms0/lun.0/removable mkdir -p configs/c.1 echo 250 > configs/c.1/MaxPower echo 0xE0 > configs/c.1/bmAttributes ln -s functions/rndis.256+0 records in 256+0 records out usb0 coroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo /tmp/mydev > functions/mass_storage.ms0/lun.0/file root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 1 > functions/mass_storage.ms0/lun.0/removable root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# mkdir -p configs/c.1 figs/c.root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 250 > configs/c.1/MaxPower root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# echo 0xE0 > configs/c.1/bmAttributes root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ln -s functions/rndis.usb0 configs/c.1/ root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ln -s functions/mass_storage.ms0/ configs/c.1/ root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ln -s functions/acm.usb0 configs/c.1/ s/class/root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ls /sys/class/udc/ > UDC [ 155.915282] usb0: HOST MAC 76:5d:c3:e3:7a:e1 [ 155.919616] usb0: MAC f2:26:48:7a:ab:ed root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# [ 156.331433] configfs-gadget gadget: high-speed config #1: c root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ifconfig -a can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 NOARP MTU:16 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:6 eth0 Link encap:Ethernet HWaddr CE:49:EC:C8:49:B3 inet addr:10.10.71.2 Bcast:10.10.71.255 Mask:255.255.255.0 inet6 addr: fe80::cc49:ecff:fec8:49b3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:49 errors:0 dropped:0 overruns:0 frame:0 TX packets:57 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6105 (5.9 KiB) TX bytes:9135 (8.9 KiB) Interrupt:16 eth1 Link encap:Ethernet HWaddr C6:86:53:97:D6:F2 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:17 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) sit0 Link encap:IPv6-in-IPv4 NOARP MTU:1480 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) usb0 Link encap:Ethernet HWaddr F2:26:48:7A:AB:ED BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ifconfig usb0 10.10.70.1 up root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# ping 10.10.71.101 PING 10.10.71.101 (10.10.71.101): 56 data bytes 64 bytes from 10.10.71.101: seq=0 ttl=64 time=0.389 ms 64 bytes from 10.10.71.101: seq=1 ttl=64 time=0.305 ms 64 bytes from 10.10.71.101: seq=2 ttl=64 time=0.343 ms 64 bytes from 10.10.71.101: seq=3 ttl=64 time=0.290 ms 64 bytes from 10.10.71.101: seq=4 ttl=64 time=0.351 ms ^C --- 10.10.71.101 ping statistics --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max = 0.290/0.335/0.389 ms root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/g#


Host machine side logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [ 1755.910088] usb 1-3.3: new high-speed USB device number 9 using xhci_hcd [ 1755.927165] usb 1-3.3: New USB device found, idVendor=1d6b, idProduct=0104 [ 1755.927186] usb 1-3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 1755.927201] usb 1-3.3: Product: versal [ 1755.927214] usb 1-3.3: Manufacturer: xilinx [ 1755.927279] usb 1-3.3: SerialNumber: xxxxxxxxxxxx [ 1755.936451] rndis_host 1-3.3:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-3.3, RNDIS device, 76:5d:c3:e3:7a:e1 [ 1755.937461] usb-storage 1-3.3:1.2: USB Mass Storage device detected [ 1755.937882] scsi4 : usb-storage 1-3.3:1.2 [ 1755.972414] cdc_acm 1-3.3:1.3: This device cannot do calls on its own. It is not a modem. [ 1755.972553] cdc_acm 1-3.3:1.3: ttyACM0: USB ACM device [ 1755.972852] usbcore: registered new interface driver cdc_acm [ 1755.972856] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters [ 1756.938574] scsi 4:0:0:0: Direct-Access Linux File-Stor Gadget 0504 PQ: 0 ANSI: 2 [ 1756.940140] sd 4:0:0:0: Attached scsi generic sg1 type 0 [ 1756.941633] sd 4:0:0:0: [sdb] 524288 512-byte logical blocks: (268 MB/256 MiB) [ 1756.942523] sd 4:0:0:0: [sdb] Write Protect is off [ 1756.942546] sd 4:0:0:0: [sdb] Mode Sense: 0f 00 00 00 [ 1756.942851] sd 4:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [ 1756.948682] sdb: unknown partition table [ 1756.949962] sd 4:0:0:0: [sdb] Attached SCSI removable disk

HID Gadget

Kernel configurations

Device Drivers --->[*] USB support ---> <*> USB Gadget Support --->  

By enabling the above we need to see the below mentioned Kconfig parameter enabled

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y


Device Tree

Edit the following file and make the following changes.

"<path to petalinux project >/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi"

Steps to test HID Gadget

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 mount -t configfs none /sys/kernel/config/ echo ""Creating HID..."" cd /sys/kernel/config/usb_gadget/ mkdir -p gadget cd gadget echo 0x0525 > idVendor echo 0xa4ac > idProduct echo 0x00 > bDeviceClass echo 0x00 > bDeviceSubClass echo 0x00 > bDeviceProtocol bmAttributes mkdir -p strings/0x409 echo ""0000000001"" > strings/0x409/serialnumber echo ""manufacturer"" > strings/0x409/manufacturer echo ""HID Gadget"" > strings/0x409/product mkdir -p functions/hid.usb0 echo 1 > functions/hid.usb0/protocol echo 1 > functions/hid.usb0/subclass echo 8 > functions/hid.usb0/report_length echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc mkdir -p configs/c.1/strings/0x409 echo ""Conf 1"" > configs/c.1/strings/0x409/configuration echo 0x00 > configs/c.1/MaxPower echo 0xC0 > configs/c.1/bmAttributes ln -s functions/hid.usb0 configs/c.1/ ls /sys/class/udc > UDC //Key Press echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\x06\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\x07\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\x08\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\x04\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\x00\0\x05\0\0\0\0\0"" > /dev/hidg0 echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 root@xilinx-vck190-es1-2021_1:~# mount -t configfs none /sys/kernel/config/ "mount: mounting none on /sys/kernel/config/ failed: Device or resource busy "Crearoot@xilinx-vck190-es1-2021_1:~# echo ""Creating HID..."" Creating HID... kernel/croot@xilinx-vck190-es1-2021_1:~# cd /sys/kernel/config/usb_gadget/ root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# mkdir -p gadget root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget# cd gadget root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0x0525 > idVendor root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0xa4ac > idProduct root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0x00 > bDeviceClass x00 > bDeroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0x00 > bDeviceSubClass root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0x00 > bDeviceProtocol root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# bmAttributes -sh: bmAttributes: command not found p stringsroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# mkdir -p strings/0x409 "root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo ""0000000001"" > strings/0x409/serialnumber root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo ""manufacturer"" > strings/0x409/manufacturer root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo ""HID Gadget"" > strings/0x409/product root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# mkdir -p functions/hid.usb0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 1 > functions/hid.usb0/protocol root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 1 > functions/hid.usb0/subclass root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 8 > functions/hid.usb0/report_length root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# mkdir -p configs/c.1/strings/0x409 oroot@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo ""Conf 1"" > configs/c.1/strings/0x409/configuration root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0x00 > configs/c.1/MaxPower root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo 0xC0 > configs/c.1/bmAttributes root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# ln -s functions/hid.usb0 configs/c.1/ /root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# ls /sys/class/udc > UDC root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# [ 92.584761] configfs-gadget gadget: high-speed config #1: c root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\x06\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\x07\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\x08\0\0\0\0\0"" > /dev/hidg0 ne ""\0\0root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 e ""\0\0root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\x04\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\x00\0\x05\0\0\0\0\0"" > /dev/hidg0 ne root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# echo -ne ""\0\0\0\0\0\0\0\0"" > /dev/hidg0 root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# root@xilinx-vck190-es1-2021_1:/sys/kernel/config/usb_gadget/gadget# cat /dev/hidg0 root@xilinx-vck190-es1-2021_1:~# ./hid_gadget_test /dev/hidg0 keyboard keyboard options: --hold --left-ctrl --right-ctrl --left-shift --right-shift --left-alt --right-alt --left-meta --right-meta keyboard values: [a-z] or --return --esc --bckspc --tab --spacebar --caps-lock --f1 --f2 --f3 --f4 --f5 --f6 --f7 --f8 --f9 --f10 --f11 --f12 --insert --home --pageup --del --end --pagedown --right --left --down --kp-enter --up --num-lock

Host machine side logs

1 2 3 4 5 6 7 8 9 10 11 12 [ 9546.774629] usb 1-4.4: new full-speed USB device number 10 using xhci_hcd [ 9546.791245] usb 1-4.4: No LPM exit latency info found. Power management will be impacted. [ 9546.791450] usb 1-4.4: not running at top speed; connect to a high speed hub [ 9546.792709] usb 1-4.4: New USB device found, idVendor=0525, idProduct=a4ac [ 9546.792730] usb 1-4.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 9546.792745] usb 1-4.4: Product: HID Gadget [ 9546.792758] usb 1-4.4: Manufacturer: manufacturer [ 9546.792771] usb 1-4.4: SerialNumber: 0000000001 [ 9546.793303] usb 1-4.4: ep 0x81 - rounding interval to 64 microframes, ep desc says 80 microframes [ 9546.793330] usb 1-4.4: ep 0x1 - rounding interval to 64 microframes, ep desc says 80 microframes [ 9546.797116] input: manufacturer HID Gadget as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.4/1-4.4:1.0/input/input12 [ 9546.797697] hid-generic 0003:0525:A4AC.0002: input,hidraw0: USB HID v1.01 Keyboard [manufacturer HID Gadget] on usb-0000:00:14.0-4.4/input0

Audio Gadget

Kernel configurations

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 CONFIG_USB_DWC3 = y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_DUAL_ROLE=y CONFIG_USB_DWC3_OF_SIMPLE=y # USB HID support CONFIG_USB_HID=y # CONFIG_HID_PID is not set # CONFIG_USB_HIDDEV is not set CONFIG_USB_OHCI_LITTLE_ENDIAN=y CONFIG_USB_SUPPORT=y CONFIG_USB_COMMON=y CONFIG_USB_ARCH_HAS_HCD=y CONFIG_USB=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y # Miscellaneous USB options CONFIG_USB_DEFAULT_PERSIST=y CONFIG_USB_OTG=y CONFIG_USB_OTG_FSM=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y # USB Physical Layer drivers CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_USB_LIBCOMPOSITE=y CONFIG_USB_U_ETHER=y CONFIG_USB_F_RNDIS=y CONFIG_USB_F_MASS_STORAGE=y CONFIG_USB_F_FS=y CONFIG_USB_F_UVC=y CONFIG_USB_F_HID=y CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_HID=y CONFIG_USB_CONFIGFS_F_UVC=y CONFIG_USB_CONFIGFS_F_UAC1=y CONFIG_USB_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FS=y CONFIG_USB_GADGET_VBUS_DRAW=2 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2 CONFIG_U_SERIAL_CONSOLE=y

 

For reference Attaching complete kernel config file: kernel_config.txt

Device Tree 

Edit the following file and make the following changes.

<path to petalinux project >/project-spec/meta-user/recipe-bsp/device-tree/system-user.dtsi

Steps to test Audio Gadget

When the Linux kernel boots up, give the below commands:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 CONFIGFS_BASE_PATH="/sys/kernel/config" CONFIGFS_GADGET_PATH=${CONFIGFS_BASE_PATH}"/usb_gadget/g1" GADGET_SERIAL_NUMBER="Xilinx_1234567890" GADGET_MANUFACTURER="Xilinx" GADGET_PRODUCT="Xilinx - HID Audio" GADGET_IDVENDOR=0x0101 GADGET_IDPRODUCT=0x1d6b GADGET_CONFIG_DESCRIPTION="Config 1: BB HID Keyboard" mount none ${CONFIGFS_BASE_PATH} -t configfs mkdir -p ${CONFIGFS_GADGET_PATH} echo ${GADGET_IDVENDOR} > ${CONFIGFS_GADGET_PATH}/idVendor echo ${GADGET_IDPRODUCT} > ${CONFIGFS_GADGET_PATH}/idProduct echo 0xef  > ${CONFIGFS_GADGET_PATH}/bDeviceClass echo 0x02  > ${CONFIGFS_GADGET_PATH}/bDeviceSubClass echo 0x01  > ${CONFIGFS_GADGET_PATH}/bDeviceProtocol mkdir -p ${CONFIGFS_GADGET_PATH}/configs/c.1/ mkdir -p ${CONFIGFS_GADGET_PATH}/functions/uac1.0/ mkdir -p ${CONFIGFS_GADGET_PATH}/strings/0x409 mkdir -p ${CONFIGFS_GADGET_PATH}/configs/c.1/strings/0x409 echo ${GADGET_CONFIG_DESCRIPTION} > ${CONFIGFS_GADGET_PATH}/configs/c.1/strings/0x409/configuration echo 250 > ${CONFIGFS_GADGET_PATH}/configs/c.1/MaxPower echo 0xA0 > ${CONFIGFS_GADGET_PATH}/configs/c.1/MaxPower echo ${GADGET_SERIAL_NUMBER} > ${CONFIGFS_GADGET_PATH}/strings/0x409/serialnumber echo ${GADGET_MANUFACTURER} > ${CONFIGFS_GADGET_PATH}/strings/0x409/manufacturer echo ${GADGET_PRODUCT} > ${CONFIGFS_GADGET_PATH}/strings/0x409/product #ln -s ${CONFIGFS_GADGET_PATH}/functions/mass_storage.ms0/ ${CONFIGFS_GADGET_PATH}/configs/c.1/ ln -s ${CONFIGFS_GADGET_PATH}/functions/uac1.0 ${CONFIGFS_GADGET_PATH}/configs/c.1/ ls /sys/class/udc > ${CONFIGFS_GADGET_PATH}/UDC aplay -v -D hw:0,0 -f S16_LE -r 48000 -c 2 <path to audio file>/audio.wav    or Open VLC player & play the audio by changing its interface audio device.

Logs

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 root@xilinx-vck190-es1-2021_1:~# CONFIGFS_BASE_PATH="/sys/kernel/config" root@xilinx-vck190-es1-2021_1:~# root@xilinx-vck190-es1-2021_1:~# CONFIGFS_GADGET_PATH=${CONFIGFS_BASE_PATH}"/usb_gadget/g1" root@xilinx-vck190-es1-2021_1:~# GADGET_SERIAL_NUMBER="Xilinx_1234567890" root@xilinx-vck190-es1-2021_1:~# GADGET_MANUFACTURER="Xilinx" root@xilinx-vck190-es1-2021_1:~# GADGET_PRODUCT="Xilinx - HID Audio" root@xilinx-vck190-es1-2021_1:~# GADGET_IDVENDOR=0x0101 root@xilinx-vck190-es1-2021_1:~# GADGET_IDPRODUCT=0x1d6b root@xilinx-vck190-es1-2021_1:~# GADGET_CONFIG_DESCRIPTION="Config 1: BB HID Keyboard" root@xilinx-vck190-es1-2021_1:~# mount none ${CONFIGFS_BASE_PATH} -t configfs pmount: mounting none on /sys/kernel/config failed: Device or resource busy ${CONFIGFroot@xilinx-vck190-es1-2021_1:~# root@xilinx-vck190-es1-2021_1:~# mkdir -p ${CONFIGFS_GADGET_PATH} root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_IDVENDOR} > ${CONFIGFS_GADGET_PATH}/idVendor root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_IDPRODUCT} > ${CONFIGFS_GADGET_PATH}/idProduct root@xilinx-vck190-es1-2021_1:~# echo 0xef > ${CONFIGFS_GADGET_PATH}/bDeviceClass root@xilinx-vck190-es1-2021_1:~# echo 0x02 > ${CONFIGFS_GADGET_PATH}/bDeviceSubClass root@xilinx-vck190-es1-2021_1:~# echo 0x01 > ${CONFIGFS_GADGET_PATH}/bDeviceProtocol root@xilinx-vck190-es1-2021_1:~# mkdir -p ${CONFIGFS_GADGET_PATH}/configs/c.1/ root@xilinx-vck190-es1-2021_1:~# mkdir -p ${CONFIGFS_GADGET_PATH}/functions/uac1.0/ root@xilinx-vck190-es1-2021_1:~# mkdir -p ${CONFIGFS_GADGET_PATH}/strings/0x409 root@xilinx-vck190-es1-2021_1:~# mkdir -p ${CONFIGFS_GADGET_PATH}/configs/c.1/strings/0x409 root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_CONFIG_DESCRIPTION} > ${CONFIGFS_GADGET_PATH}/configs/c.1/strings/0x409/configuration root@xilinx-vck190-es1-2021_1:~# echo 250 > ${CONFIGFS_GADGET_PATH}/configs/c.1/MaxPower root@xilinx-vck190-es1-2021_1:~# echo 0xA0 > ${CONFIGFS_GADGET_PATH}/configs/c.1/MaxPower root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_SERIAL_NUMBER} > ${CONFIGFS_GADGET_PATH}/strings/0x409/serialnumber root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_MANUFACTURER} > ${CONFIGFS_GADGET_PATH}/strings/0x409/manufacturer root@xilinx-vck190-es1-2021_1:~# echo ${GADGET_PRODUCT} > ${CONFIGFS_GADGET_PATH}/strings/0x409/product root@xilinx-vck190-es1-2021_1:~# #ln -s ${CONFIGFS_GADGET_PATH}/functions/mass_storage.ms0/ ${CONFIGFS_GADGET_PATH}/configs/c.1/ root@xilinx-vck190-es1-2021_1:~# ln -s ${CONFIGFS_GADGET_PATH}/functions/uac1.0 ${CONFIGFS_GADGET_PATH}/configs/c.1/ root@xilinx-vck190-es1-2021_1:~# ls /sys/class/udc > ${CONFIGFS_GADGET_PATH}/UDC root@xilinx-vck190-es1-2021_1:~# [ 55.981478] configfs-gadget gadget: high-speed config #1: c root@xilinx-vck190-es1-2021_1:~# aplay -v -D hw:0,0 -f S16_LE -r 48000 -c 2 audio_test.wav Playing WAVE 'audio_test.wav' : Signed 16 bit Little Endian, Rate 64000 Hz, Stereo Warning: rate is not accurate (requested = 64000Hz, got = 48000Hz) please, try the plug plugin Hardware PCM card 0 'UAC1_Gadget' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 16384 period_size : 1024 period_time : 21333 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 1024 period_event : 0 start_threshold : 16384 stop_threshold : 16384 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 appl_ptr : 0 hw_ptr : 0

Host side machine logs

1 2 3 4 5 6 7 [28962.568558] usb 1-3.3: new high-speed USB device number 27 using xhci_hcd [28962.585670] usb 1-3.3: New USB device found, idVendor=0101, idProduct=1d6b [28962.585691] usb 1-3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [28962.585706] usb 1-3.3: Product: XilinxTest - HID Audio [28962.585720] usb 1-3.3: Manufacturer: Xilinx [28962.585734] usb 1-3.3: SerialNumber: Xilinx_1234567890 [28962.653843] usbcore: registered new interface driver snd-usb-audio

References

Zynq Ultrascale MPSOC Linux USB device driver