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

« Previous Version 3 Next »

This article provides how to allow the USB2.0/USB3.0 device controller act as a serial port device on SP7350 platforms.

Table of Contents

Serial Device

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 support > USB Gadget Support > USB Peripheral Controller. Select <*> for “Sunplus USB 2.0 Device Controller“.

image-20240617-063128.png

  1. Select submenus for USB 3.0 controller : Device Drivers > USB support > USB support >. Select <*> for “DesignWare USB3 DRD Core Support“ and select “Dual Role mode“ for “Deware USB3 DRD Core Support“.

image-20240617-063459.png

  1. Select submenus for USB Gadget configfs : Device Drivers > USB support > USB support > USB Gadget Support. Select <M> for “USB Gadget functions configurable through configfs“. Select [*] for “Generic serial bulk in/out”, “Abstract Control Model (CDC ACM)“ or “Object Exchange Model (CDC OBEX)“.

image-20240617-063816.png

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

ConfigFS

Configure serial gadget through configfs saved as a file named setup_serial.

#!/bin/sh

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_SERIAL=$FUNCTION_PATH/u_serial.ko

insmod $COMPOSITE
insmod $U_SERIAL

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

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

# USB2.0 configurations
cd /sys/kernel/config/usb_gadget

# create gadget folder
mkdir g1
cd g1

# setup gadget 1
echo 64 > bMaxPacketSize0
echo 0x200 > bcdUSB

# composite class
echo 0x02 > bDeviceClass

mkdir -p configs/c.1
mkdir -p configs/c.1/strings/0x409
echo "USB2.0 Serial Console" > configs/c.1/strings/0x409/configuration

mkdir strings/0x409
echo "1234" > strings/0x409/serialnumber
echo "Sunplus" > strings/0x409/manufacturer
echo "SP7350" > strings/0x409/product

mkdir functions/acm.gs0
ln -s functions/acm.gs0 configs/c.1

# bind UDC
echo "f8102800.usb" > UDC

# USB3.0 configurations
cd /sys/kernel/config/usb_gadget

# create gadget folder
mkdir g2
cd g2

# setup gadget 2
echo 64 > bMaxPacketSize0
echo 0x300 > bcdUSB

# composite class
echo 0x02 > bDeviceClass

mkdir -p configs/c.1
mkdir -p configs/c.1/strings/0x409
echo "USB3.0 Serial Console" > configs/c.1/strings/0x409/configuration

mkdir strings/0x409
echo "5678" > strings/0x409/serialnumber
echo "Sunplus" > strings/0x409/manufacturer
echo "SP7350" > strings/0x409/product

mkdir functions/acm.gs1
ln -s functions/acm.gs1 configs/c.1

# bind UDC
echo "f80a1000.dwc3" > UDC

Test Configuartions

Use sh setup_serial command to configure USB 2.0 and USB3.0 device controllers as serial gadgets.

# sh setup_serial

ttyGS0 and ttyGS1 in /dev are represented for USB2.0 serial gadget and USB3.0 one.

image-20240617-090041.png

In Device Manager of Windows PC, “USB Serial Device (COM17)“ (USB2.0 serial gadget) and “USB Serial Device (COM18)“ (USB3.0 serial gadget) will show up in “Ports (COM & LPT)”.

image-20240617-081510.png

Serial Device Test

Use the communication tool of Putty for the test with a Windows PC.

TX Test for USB2.0 Serial Gadget

  1. Use the following command to transfer characters of “SP7350 USB2.0 Serial Gadget TX Test“ to COM17 through ttyGS0 (USB2.0 serial gadget).

# echo "SP7350 USB2.0 Serial Gadget TX Test" > /dev/ttyGS0

  1. The characters will be received by COM17 open in Putty.

image-20240617-102212.png

TX Test for USB3.0 Serial Gadget

  1. Use the following command to transfer characters of “SP7350 USB3.0 Serial Gadget TX Test“ to COM18 through ttyGS1 (USB3.0 serial gadget).

# echo "SP7350 USB3.0 Serial Gadget TX Test" > /dev/ttyGS1

  1. The characters will be received by COM18 open in Putty.

image-20240617-102624.png

RX Test for USB2.0 Serial Gadget

  1. Use the following command to receive characters transferred from COM17 through ttyGS0 (USB2.0 serial gadget).

# cat /dev/ttyGS0

  1. Input the characters of “SP7350 USB2.0 Serial Gadget RX Test" in Putty with COM17 and press “Enter”. The characters will be received by COM4 (console) open in Putty.

image-20240617-103204.png

RX Test for USB3.0 Serial Gadget

  1. Use the following command to receive characters transferred from COM18 through ttyGS1 (USB3.0 serial gadget).

# cat /dev/ttyGS1

  1. Input the characters of “SP7350 USB3.0 Serial Gadget RX Test" in Putty with COM18 and press “Enter”. The characters will be received by COM4 (console) open in Putty.

image-20240617-104630.png

Serial Gadget Console

For console support, it is more convenient to use precomposed configurations (build-in) instead of configfs. Take USB2.0 Serial Gadget for example.

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 support > USB Gadget Support > USB Peripheral Controller. Select <*> for “Sunplus USB 2.0 Device Controller“.

image-20240617-063128.png

  1. Select submenus for precomposed configurations : Device Drivers > USB support > USB support > USB Gadget Support > USB Gadget precomposed configurations. Select <*> for “Serial Gadget (with CDC ACM and CDC OBEX support)”.

image-20240618-031321.png

  1. Select submenus for precomposed configurations : Device Drivers > USB support > USB support > USB Gadget Support. Select [*] for “Serial gadget console support“.

image-20240618-081747.png

Test Configurations

  1. Add an entry in linux/rootfs/initramfs/disk/etc/inittab to set the terminal to connect to ttyGS0.

image-20240618-061550.png

  1. Add “ttyGS0” in linux/rootfs/initramfs/disk/etc/securetty

image-20240618-061903.png

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

Serial Gadget Console Test

  1. After updating the image to a SP7350 platform and booting the system, kernel messages during boot are shown in COM4 of Putty which is the default console set in uboot.

image-20240618-062937.pngimage-20240618-064213.png

  1. After connecting the SP7350 platform to the Windows PC with an USB OTG cable, “login[144]: root login on 'ttyGS0'“ will show up in COM4 of Putty. There is an USB serial device appearing in Device Manager.

image-20240618-063037.pngimage-20240618-064048.png

  1. Open Putty with COM8 and it can receive text input from the user.

image-20240618-065837.png

  • No labels