Table of Contents

Edge-2L USB gadget

Introduction

This document mainly introduces the usage of USB gadget.

From version 1.7.5, USB gadget is enabled by default, no need any setup, you can just skip the overlay and service setup.

System Configuration

Upgrade System

Follow Upgrade System to upgrade the system to latest version.

Enable USB Gadget Service

You can follow the command below to enable the USB Gadget service.

sudo systemctl enable usb-gadget-khadas.service

Reboot to effect.

sync
sudo reboot
2022/07/06 02:12 · nick

Usage of ADB

ADB (Android Debug Bridge) is enabled by default. You can access the device directly via ADB:

$ adb kill-server
$ adb devices

Expected output:

* daemon not running; starting now at tcp:5037
* daemon started successfully
 
List of devices attached
12036c819990    device

To obtain a shell on the device:

$ adb shell

You should see a prompt like: root@Khadas:/#

Enable other USB functions

You can dynamically switch USB gadget functions by writing the desired mode to the file /tmp/.usb_config and restarting the 'usbdevice' service.

echo usb_rndis_en > /tmp/.usb_config
sudo usbdevice restart
echo usb_acm_en > /tmp/.usb_config
sudo usbdevice restart
echo usb_uac_en > /tmp/.usb_config
sudo usbdevice restart
echo usb_uvc_en > /tmp/.usb_config
sudo usbdevice restart

After enabling UVC, start the UVC gadget application:

uvc-gadget rockchip/functions/uvc.0 -d /dev/videoX
Note: Replace X with the actual video device node number (e.g. /dev/video0).
echo usb_ums_en > /tmp/.usb_config
sudo mkdir -p /userdata/
dd if=/dev/zero of=/userdata/ums_shared.img bs=1M count=1024

UMS mode requires an empty disk image file (ums_shared.img in the example above, 1GB size). This file will be presented to the host system as a removable storage drive.

RNDIS setup IP address

After enabling the RNDIS function, you need to configure the IP address manually on both the device and the host PC.

Such as set the IP address for the usb0 interface (e.g., to 192.168.35.100):

sudo ifconfig usb0 192.168.35.100 up

On the host PC, configure the corresponding USB network interface with an IP address on the same subnet (e.g., 192.168.35.110).

Test the connection form the device to the host:

ping -I usb0 192.168.35.110