USB Configuration
Configure Kernel Menu for USB
-
Under the root directory of freelight-u-sdk, run the following command to enter the kernel menu configuration GUI.
make linux-menuconfig -
Enter the Device Drivers menu.
-
Enter the USB Support menu.
-
In the USB Support menu, select the support for host-side USB, PCI based USB host interface and xHCI HCD USB 3.0 support options.
-
In the USB Support menu, select all the options that start with Cadence USB.
-
To enable the function of USB attached disks, in the USB Support menu, select the USB Mass Storage support and the USB Attached SCSI options.
-
To enable the function of USB device, select the USB Gadget Support option and enter the menu.
In the USB Gadget Support menu, select your target function.
For example, to enable the configfs, functionfs, and mass storage, select the
USB gadget functions configurable through configfs, Mass storage and Function filesystem (FunctionFS) options respectively.-
Save your change and exit the kernel configuration dialog.
Board-level Configuration: Configure USB Pins
The following two code snippets work together to set up the GPIO pin that turns USB power on when the board acts as a USB host.
Code snippet 1: Sets up GPIO25 as the USB VBUS power enable pin
usb_pins: usb-pins {
drive-vbus-pin {
sf,pins = <PAD_GPIO25>; // Use physical pin GPIO25
sf,pinmux = <PAD_GPIO25_FUNC_SEL 0>; // Set to USB power-control function
sf,pin-ioconfig = <IO(GPIO_IE(1))>; // Input enabled (safe default)
sf,pin-gpio-dout = <GPO_USB0_DRIVE_VBUS_IO>; // Connect to USB power enable
sf,pin-gpio-doen = <OEN_LOW>; // Set as OUTPUT (to turn power on/off)
};
};
&usbdrd30 {
pinctrl-names = "default";
pinctrl-0 = <&usb_pins>; // USE the GPIO25 pin setup above
dr_mode = "host"; // Set USB to HOST mode
status = "disabled"; // USB is OFF by default
};Build Gadgets
Gadgets refer to USB devices with a USB device controller embedded. Gadgets can be connected to PC, mass storage devices, and UAC devices, depending on their configurations.
-
Enable the USB Gadget Support in the kernel menu. See Configure Kernel Menu for USB.
-
Use the
configfsframework to build the gadget function.-
Run the following commands to build gadgets and write gadget PID, VID, and sequence number.
mkdir /sys/kernel/config/usb_gadget/g1 echo "VID" > /sys/kernel/config/usb_gadget/g1/idVendor echo "PID" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "manufacturer" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer echo "product" > /sys/kernel/config/usb_gadget/g1/strings/0x409/productTable 1. Examples Action Command Configure the gadget as a mass storage device mount -t configfs none /sys/kernel/config mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1d6b " > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0001" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 mkdir /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 echo /dev/a.bin > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/fileConfigure the gadget as an ADB mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1d6b" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0002" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "20181111" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber echo "starfive" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturerConfigure the gadget as both a mass storage device and an ADB mkdir /sys/kernel/config/usb_gadget/g1 echo "0x1d6b" > /sys/kernel/config/usb_gadget/g1/idVendor echo "0x0003" > /sys/kernel/config/usb_gadget/g1/idProduct mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 echo "20181111" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber echo "stafive" > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer -
Run the following commands to build gadget relevant configuration.
mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 echo 0xc0 > /sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes echo 500 > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 -
Run the following command to build gadget functions.
where,mkdir /sys/kernel/config/usb_gadget/g1/functions/<name>.<instance name>- name:Name of the function
- instance name: Instance name of the function
-
Run the following commands to build connections between the function and its configuration.
ln -s /sys/kernel/config/usb_gadget/g1/functions/<name>.<instance name> /sys/kernel/config/ usb_gadget/g1/configs/c.1Table 2. Examples Action Command Configure the gadget as a mass storage device ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/ usb_gadget/g1/configs/c.1/Configure the gadget as an ADB ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb/ /sys/kernel/config/usb_gadget/g1/ configs/c.1/ffs.adbConfigure the gadget as both a mass storage device and an ADB ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb/ /sys/kernel/config/usb_gadget/g1/ configs/c.1/ffs.adb ln -s /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/ /sys/kernel/config/ usb_gadget/g1/configs/c.1/mass_storage.usb0 -
Enable the gadget.
echo <udc name> > UDC
-