Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This guide describes how to enable USB 2.0 / USB 3.0 ncm ethernet gadget on SP7350 platforms.

...

Table of Contents
minLevel1
maxLevel6
outlinefalse
styledefault
typelist
printabletrue

Kernel Setup

Enter the kernel configuration by running the following command in the top directory of project.

...

  1. Execute the make command to build the Linux image.

ConfigFS (CDC NCM)

Configure the ncm ethernet gadget through configfs saved as a file named setup_ncm.

Code Block
#!/bin/sh

USB2_NCM_EN=on
USB3_NCM_EN=on

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

insmod $COMPOSITE
insmod $U_ETHER
insmod $U_NCM

# disable debug message
echo 0 > /sys/module/sunplus_udc/parameters/dmsg

mkdir -p /sys/kernel/config
mount -t configfs none /sys/kernel/config

if [ $USB2_NCM_EN = on ]
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

        # composite class
        echo 0xEF > bDeviceClass

        # subclass
        echo 0x04 > bDeviceSubClass
        echo 0x01 > bDeviceProtocol

        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
        echo "SP7350 USB2.0 NCM Ethernet Gadget" > strings/0x409/product

        mkdir functions/ncm.usb0
        ln -s functions/ncm.usb0 configs/c1.1

        # bind UDC
        echo $UDC_NAME > UDC

        # set ip
        ifconfig lo up
        ifconfig usb0 ${DEV_IP} netmask 255.255.255.0 up
fi

if [ $USB3_NCM_EN = on ]
then
        UDC_NAME="f80a1000.dwc3"
        DEV_IP=192.168.20.20

        # create gadget folder
        cd /sys/kernel/config/usb_gadget

        if [ $USB2_NCM_EN = on ]
        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

        # composite class
        echo 0xEF > bDeviceClass

        # subclass
        echo 0x04 > bDeviceSubClass
        echo 0x01 > bDeviceProtocol

        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
        echo "SP7350 USB3.0 NCM Ethernet Gadget" > strings/0x409/product

        mkdir functions/ncm.usb0
        ln -s functions/ncm.usb0 configs/c1.1

        # bind UDC
        echo $UDC_NAME > UDC

        # set ip
        if [ $USB2_NCM_EN = on ]
        then
                ifconfig usb1 ${DEV_IP} netmask 255.255.255.0 up
        else
                ifconfig lo up
                ifconfig usb0 ${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 command to configure USB 2.0 and USB 3.0 as ncm 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.

...