Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

Table of Contents

Kernel Setup

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

# make kconfig

  1. 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“.

image-20240708-071800.png

  1. 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“.

image-20240703-083817.png

  1. Select submenus for USB OTG Transceive driver : Device Drivers > USB support > USB Physical Layer drivers. Select <*> for “Sunplus USB OTG Transceive driver“.

image-20240703-101840.png

  1. 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“.

image-20240708-023906.png

  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.

#!/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.

image-20240709-022028.pngimage-20240709-024017.pngimage-20240709-021148.png

According to Microsoft official website, the ncm driver needs to be installed manually if the OS version is neither Windows 11 nor Windows Server 2022.

https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/supported-usb-class

image-20240709-022647.png

After installing the ncm driver for “SP7350 USB2.0 NCM Ethernet Gadget“ and “SP7350 USB3.0 NCM Ethernet Gadget“, “UsbNcm Host Device #2“ and “UsbNcm Host Device #3“ will show up in “Network adapters“.

image-20240709-031530.png

  • No labels