This guide describes how to enable USB 2.0 / USB 3.0 ncm ethernet gadget on SP7350 platforms. The ethernet gadget includes CDC NCM, CDC ECM, CDC ECM subset, RNDIS and EEM.
Table of Contents
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Kernel Setup
Enter the kernel configuration by running the following command in the top directory of project.
...
Select submenus for USB 2.0 controller : Device Drivers > USB support > USB Gadget Support > USB Peripheral Controller. Select <*> for “Sunplus USB 2.0 Device Controller“.
...
Select submenus for USB OTG Transceive driver : Device Drivers > USB support > USB Physical Layer drivers. Select <*> for “Sunplus USB OTG Transceive driver“.
...
Select submenus for USB 3.0 controller : Device Drivers > USB support. Select <*> for “DesignWare USB3 DRD Core Support“ and select “Dual Role mode“ for “Deware USB3 DRD Core Support“.
...
Select submenus for USB OTG Transceive driver : Device Drivers > USB support > USB Physical Layer drivers. Select <*> for “Sunplus USB OTG Transceive driver“.
...
Select submenus for USB Gadget configfs : Device Drivers > USB support > USB Gadget Support. Select <M> for “USB Gadget functions configurable through configfs“ and [*] for “Mass storage“.
...
“Network Control Model (CDC NCM)“, “Ethernet Control Model (ECM)“, “Ethernet Control Model (ECM) subset“, “RNDIS“ and “Ethernet Emulation Model (EEM)“.
...
Execute the make command to build the Linux image.
ConfigFS
...
Configure the ncm ethernet gadget through configfs saved as a file named setup_eth. It configures both USB 2.0 and USB 3.0 as ncm ethernet gadgets by default.
Code Block |
---|
#!/bin/sh # NCM, ECM, ECM_SUBSET, RNDIS, EEM or OFF USB2=NCM USB3=NCM # IP address configuration if [ $USB2 != OFF ] then USB2_NCM_EN=onDEV_IP=192.168.10.20 fi if [ $USB3 != OFF ] then USB3_NCMDEV_EN=onIP=192.168.20.20 fi KERNEL_PATH=/lib/modules/`uname -r`/kernel GADGET_PATH=$KERNEL_PATH/drivers/usb/gadget FUNCTION_PATH=$GADGET_PATH/function COMPOSITE=$GADGET_PATH/libcomposite.ko U_ETHER=$FUNCTION_PATH/u_ether.ko U_NCM=$FUNCTION_PATH/usb_f_ncm.ko U_ECM=$FUNCTION_PATH/usb_f_ecm.ko U_ECM_SUBSET=$FUNCTION_PATH/usb_f_ecm_subset.ko U_RNDIS=$FUNCTION_PATH/usb_f_rndis.ko U_EEM=$FUNCTION_PATH/usb_f_eem.ko insmod $COMPOSITE insmod $U_ETHER if [ $USB2 = NCM ] || [ $USB3 = NCM ] then insmod $U_NCM elif [ $USB2 = ECM ] || [ $USB3 = ECM ] then insmod $U_ECM elif [ $USB2 = ECM_SUBSET ] || [ $USB3 = ECM_SUBSET ] then insmod $U_ECM_SUBSET elif [ $USB2 = RNDIS ] || [ $USB3 = RNDIS ] then insmod $U_RNDIS elif [ $USB2 = EEM ] || [ $USB3 = EEM ] then insmod $U_EEM fi # disable USB2 debug message if [ $USB2 != OFF ] then echo 0 > /sys/module/sunplus_udc/parameters/dmsg fi mkdir -p /sys/kernel/config mount -t configfs none /sys/kernel/config if [ $USB2_NCM_EN != onOFF ] then UDC_NAME="f8102800.usb" DEV_IP=192.168.10.20 # create gadget folder cd /sys/kernel/config/usb_gadget mkdir g1 cd g1 echo 64 > bMaxPacketSize0 echo 0x200 > bcdUSB echo 0x100 > bcdDevice echo 0x0525 > idVendor echo 0xa4a1 > idProduct if [ $USB2 = NCM ] then echo 0x02 > bDeviceClass echo 0x0d > bDeviceSubClass echo 0x0 > bDeviceProtocol elif [ $USB2 = ECM ] then echo 0x02 > bDeviceClass echo 0x06 > bDeviceSubClass # composite class echo 0x0 > bDeviceProtocol elif [ $USB2 = ECM_SUBSET ] then echo 0xEF0x02 > bDeviceClass echo 0x06 > bDeviceSubClass echo # subclass0x0 > bDeviceProtocol elif [ $USB2 = RNDIS ] then echo 0xEF > bDeviceClass echo 0x04 > bDeviceSubClass echo 0x01 > bDeviceProtocol elif [ $USB2 = EEM ] then echo 0x2 > bDeviceClass echo 0x0c > bDeviceSubClass echo 0x07 > bDeviceProtocol fi mkdir -p configs/c1.1 mkdir -p configs/c1.1/strings/0x409 echo "ethe" > configs/c1.1/strings/0x409/configuration mkdir strings/0x409 echo "1234" > strings/0x409/serialnumber echo "Sunplus" > strings/0x409/manufacturer if [ $USB2 = NCM ] then echo "SP7350 USB2.0 NCM Ethernet Gadget" > strings/0x409/product mkdir functions/ncm.usb0 ln -s functions/ncm.usb0 configs/c1.1 elif [ $USB2 = ECM ] then echo "SP7350 USB2.0 ECM Ethernet Gadget" > strings/0x409/product mkdir functions/ecm.0 ln -s functions/ecm.0 configs/c1.1 elif [ $USB2 = ECM_SUBSET ] then echo "SP7350 USB2.0 ECM_SUBSET Ethernet Gadget" > strings/0x409/product mkdir functions/ecm.0 ln -s functions/ecm.0 configs/c1.1 elif [ $USB2 = RNDIS ] then echo "SP7350 USB2.0 RNDIS Ethernet Gadget" > strings/0x409/product mkdir functions/rndis.rn0 ln -s functions/rndis.rn0 configs/c1.1 elif [ $USB2 = EEM ] then echo "SP7350 USB2.0 EEM Ethernet Gadget" > strings/0x409/product mkdir functions/eem.0 ln -s functions/eem.0 configs/c1.1 fi # bind UDC echo $UDC_NAME > UDC # set ip ifconfig lo up ifconfig usb0 ${USB2_DEV_IP} netmask 255.255.255.0 up fi if [ $USB3_NCM_EN != onOFF ] then UDC_NAME="f80a1000.dwc3" DEV_IP=192.168.20.20 # create gadget folder cd /sys/kernel/config/usb_gadget if [ $USB2_NCM_EN != onOFF ] then mkdir g2 cd g2 else mkdir g1 cd g1 fi echo 64 > bMaxPacketSize0 echo 0x300 > bcdUSB echo 0x100 > bcdDevice echo 0x0525 > idVendor echo 0xa4a1 > idProduct if [ # composite class$USB2 = NCM ] then echo 0x02 > bDeviceClass echo 0x0d > bDeviceSubClass echo 0x0 > bDeviceProtocol elif [ $USB2 = ECM ] then echo 0x02 > bDeviceClass echo 0x06 > bDeviceSubClass echo 0x0 > bDeviceProtocol elif [ $USB2 = ECM_SUBSET ] then echo 0xEF0x02 > bDeviceClass # subclass echo 0x06 > bDeviceSubClass echo 0x0 > bDeviceProtocol elif [ $USB2 = RNDIS ] then echo 0xEF > bDeviceClass echo 0x04 > bDeviceSubClass echo 0x01 > bDeviceProtocol elif [ $USB2 = EEM ] then echo 0x02 > bDeviceClass echo 0x0c > bDeviceSubClass echo 0x07 > bDeviceProtocol fi mkdir -p configs/c1.1 mkdir -p configs/c1.1/strings/0x409 echo "ethe" > configs/c1.1/strings/0x409/configuration mkdir strings/0x409 echo "5678" > strings/0x409/serialnumber echo "Sunplus" > strings/0x409/manufacturer if [ $USB3 = NCM ] then echo "SP7350 USB3.0 NCM Ethernet Gadget" > strings/0x409/product mkdir functions/ncm.usb0 ln -s functions/ncm.usb0 configs/c1.1 elif [ $USB3 = ECM ] then echo "SP7350 USB3.0 ECM Ethernet Gadget" > strings/0x409/product mkdir functions/ecm.0 ln -s functions/ecm.0 configs/c1.1 elif [ $USB3 = ECM_SUBSET ] then echo "SP7350 USB3.0 ECM_SUBSET Ethernet Gadget" > strings/0x409/product mkdir functions/ecm.0 ln -s functions/ecm.0 configs/c1.1 elif [ $USB3 = RNDIS ] then echo "SP7350 USB3.0 RNDIS Ethernet Gadget" > strings/0x409/product mkdir functions/rndis.rn0 ln -s functions/rndis.rn0 configs/c1.1 elif [ $USB3 = EEM ] then echo "SP7350 USB3.0 EEM Ethernet Gadget" > strings/0x409/product mkdir functions/eem.0 ln -s functions/eem.0 configs/c1.1 fi # bind UDC echo $UDC_NAME > UDC # set ip if [ $USB2_NCM_EN != onOFF ] then ifconfig usb1 ${USB3_DEV_IP} netmask 255.255.255.0 up else ifconfig lo up ifconfig usb0 ${USB3_DEV_IP} netmask 255.255.255.0 up fi fi |
Implementation
After updating the image to the SP7350 platform and booting the system, use sh setup_ncm eth command to configure USB 2.0 and USB 3.0 as ncm (default) ethernet gadgets and connect them to the windows PC through USB cables. “SP7350 USB2.0 NCM Ethernet Gadget“ and “SP7350 USB3.0 NCM Ethernet Gadget“ will show up in “Other devices” of Device Manager.
...
After installing the ncm driver for “SP7350 USB2.0 NCM Ethernet Gadget“ and “SP7350 USB3.0 NCM Ethernet Gadget“, “UsbNcm Host Device #2“ Device“ and “UsbNcm Host Device #3“#2“ will show up in “Network adapters“.
...