1 1
percu

usb gadget mode on Orange Pi one

Recommended Posts

Hello!

I try to turn on usb gadget mode on my OPi. For example g_ethernet, or g_midi. Read many posts, but still don't understand what I should do. Is it possible to turn on gadget mode without compiling my own armbian? Also, I had found on this forum info that legacy roms already have OTG support from the box. Is it true?

May be somebody knows tutorials of how to turn on usb gadget mode?

Share this post


Link to post
Share on other sites
13 hours ago, percu said:

example g_ethernet, or g_midi

g_ethernet or g_midi is legacy USB gadget. You should use the USB gadget framework, it is much more flexible. It can run multiple functions simultaneously and be reconfigured at run time.

13 hours ago, percu said:

Is it possible to turn on gadget mode without compiling my own armbian?

To use the USB gadget framework it is usually not necessary to recreate the entire distribution. The only precondition is that the kernel build has created the required components. If your kernel provides /usr/lib/modules/*/kernel/drivers/usb/gadget/libcomposite.ko and /usr/lib/modules/*/kernel/drivers/usb/gadget/functions/*, you are ready to go. The only missing part is proper configuration. First you need a proper devicetree setup for the hardware support. (your prefered editor and DTC to compile the DTB). Second the USB gadget framework configuration (your prefered editor and your usual file system tools).

13 hours ago, percu said:

have OTG support from the box

I doubt that this will be the case, gadget features are much too different and there are probably no generic ones that suit someone's needs. At least vendor and device IDs have to be chosen properly.

Share this post


Link to post
Share on other sites

Thank you for replying!

 

In the armbian-config -> hardware I turned on usbhost0. After rebooting, and command "modprobe g_ether", now I can see my OPi as usb COM device in windows. 

But when I try:

sudo modprobe g_midi

I get error:

modprobe: FATAL: Module g_midi not found in directory /lib/modules/4.19.57-sunxi

Where I can get this module?

Here I had read, that I need to reconfigure kernel.  Think that I need to use make menuconfig command in the kernel build directory. Right? But I don't have source code in /usr/src. May be it is in the other dir?

 

4 hours ago, usual user said:

First you need a proper devicetree setup

I can't find any info about midi device tree configurations. May be devicetree setup have some rules to configure it?

4 hours ago, usual user said:

Second the USB gadget framework configuration (your prefered editor and your usual file system tools).

Does USB gadget framework included in the Armbian? Or where I can find it?

 

Sorry for my questions, I'm really stupid in linux.

 

Share this post


Link to post
Share on other sites
2 hours ago, percu said:

Think that I need to use make menuconfig command in the kernel build directory. Right? But I don't have source code in /usr/src. May be it is in the other dir?


In embedded world we compile on the desktop even its also possible  native. Recommended way:
https://docs.armbian.com/Developer-Guide_Build-Preparation/

Do what you have to do, copy resulting kernel to the board (image and dtb), install (dpkg -i *.deb) and reboot. Remember to push changes to Armbian, so that the next upgrade will contain your work otherwise you will need to repeat this over and over again on each regular kernel upgrade ...

Share this post


Link to post
Share on other sites
3 hours ago, percu said:

command "modprobe g_ether", now I can see my OPi as usb COM device

I doubt it. To expose a serial port, you probably used g_serial.

3 hours ago, percu said:

I can't find any info about midi device tree configurations. May be devicetree setup have some rules to configure it?

No, devicetree configures only the USB OTG IP for device mode. As your serial port setup is working, your devicetree is already properly set up.

3 hours ago, percu said:

Does USB gadget framework included in the Armbian?

Since it's been years since I was tinkering with the USB gadget framework, I looked at the kernel of balbes150's "Single Armbian image for RK + AML + AW" (the only one I had easily available). I learned that the legacy drivers are gone for good nowadays. There are only wraper modules to expose the legacy gadget configuration interfaces that use the gadget framework as backend.

Unfortunately he is only building the wraper modules and left out the configfs components to configure the gadget framework via userspace. I don't know how your kernel is configured, so it may be different for you. As the same configuration parameters have to be determined for legacy and configfs configuration I prefer to use configfs.

E.g. this shell script sets up a gadget with a printer interface, an ethernet interface and a storage device simultaneously:

Spoiler

#!/bin/bash
CONFIGFS=/sys/kernel/config/
G1=${CONFIGFS}usb_gadget/acme

#---------------------------------------------------------------------------------------------------

mkdir ${G1}
printf "0xEF" > ${G1}/bDeviceClass
printf "0x01" > ${G1}/bDeviceProtocol
printf "0x02" > ${G1}/bDeviceSubClass
printf "0x0100" > ${G1}/bcdDevice
printf "0x0200" > ${G1}/bcdUSB
printf "0x0001" > ${G1}/idProduct
printf "0x0555" > ${G1}/idVendor

mkdir ${G1}/strings/0x409
printf "ACME AG" > ${G1}/strings/0x409/manufacturer
printf "ACME-BOX" > ${G1}/strings/0x409/product
printf "02010001" > ${G1}/strings/0x409/serialnumber

#---------------------------------------------------------------------------------------------------

mkdir ${G1}/configs/acme-box.1

mkdir ${G1}/configs/acme-box.1/strings/0x409
printf "ACME-BOX Interfaces" > ${G1}/configs/acme-box.1/strings/0x409/configuration

#---------------------------------------------------------------------------------------------------

FN=rndis
mkdir ${G1}/functions/${FN}.usb0
printf "00:2d:55:FF:0F:FD" > ${G1}/functions/${FN}.usb0/dev_addr
printf "00:2d:55:FF:0F:FE" > ${G1}/functions/${FN}.usb0/host_addr

ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1

#---------------------------------------------------------------------------------------------------

FN=mass_storage
mkdir ${G1}/functions/${FN}.usb0
# printf "1" > ${G1}/functions/${FN}.usb0/lun.0/cdrom
# printf "1" > ${G1}/functions/${FN}.usb0/lun.0/nofua
printf "1" > ${G1}/functions/${FN}.usb0/lun.0/removable
printf "1" > ${G1}/functions/${FN}.usb0/lun.0/ro
printf "ACME-BOX" > ${G1}/functions/${FN}.usb0/lun.0/inquiry_string
printf "/run/acme/mass_storage.img" > ${G1}/functions/${FN}.usb0/lun.0/file

ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1

#---------------------------------------------------------------------------------------------------

FN=printer
mkdir ${G1}/functions/${FN}.usb0
printf "MFG:Acme;MDL:ACME-BOX;CLS:PRINTER;CMD:PDF,PCL;" > ${G1}/functions/${FN}.usb0/pnp_string

ln -s ${G1}/functions/${FN}.usb0 ${G1}/configs/acme-box.1

#---------------------------------------------------------------------------------------------------

printf "ci_hdrc.0" > ${G1}/UDC

ifconfig usb0 10.0.0.1 netmask 255.255.255.0

 

This can't be done with legacy, there you have only one function at a time and the configuration is applied at module load.

Share this post


Link to post
Share on other sites

Sooo, it works now! Big thanks to Igor and usual user!

What I do:

1) Reconfigure kernel, turn on midi gadget support(https://linux-sunxi.org/USB_Gadget/MIDI) and compile it. (https://docs.armbian.com/Developer-Guide_Build-Preparation/)

2) Turn on usbhost0 in System -> Hardware section using armbian-config.

3) Install new kernel on my Pi ( sudo dpkg -i linux-image-current-sunxi_20.08.0-trunk_armhf.deb)

4) sudo modeprobe g_midi

Profit!

 

Now I can see my midi device in device manager in Win10. It appears with name "MIDI function". 

So one more question: how I can change this name? Or do I need to do somthing before compiling kernel?

Share this post


Link to post
Share on other sites
3 hours ago, percu said:

So one more question: how I can change this name?

As you have chosen the legacy g_midi configuration interface, you have to do configuration while module-load.

"modinfo g_midi" will tell all available configurable parameters.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
1 1