[Solved] OTG support

StereoPi hardware discussion
Post Reply
stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

[Solved] OTG support

Post by stereomaton » Tue May 21, 2019 12:47 pm

I post in hardware section because, as a BSP issue, it is more related to hardware than user software.

Context:
Ethernet access is not always convenient, but yet networking is useful.
Hence, I often use USB-net to connect to my boards.
Firsts tries on stereopi are failures.

Question:
As schematics seems not to be available yet (not even in pdf read-only format), is the hardware able to deal with OTG drivers ?
Would I need to do some change to support it ?
If relevant, I use the CM3Lite module.

2019-05-25 Solved:
I managed to make USB-net work with a complete software solution (explained in this thread).
However there are some trade-off to be aware of (again, highlighted in the thread)
Last edited by stereomaton on Sat May 25, 2019 3:22 pm, edited 1 time in total.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: OTG support

Post by stereomaton » Tue May 21, 2019 12:59 pm

Here some observations.

Concerning software, using the shipped distro, the kernel emits a warning (around) every second:

Code: Select all

WARN::dwc_otg_hcd_hub_control:3746: DWC OTG HCD - Unknown hub control request type or invalid typeReq: c033h wIndex: 0h wValue: 0h
As it is a warning, I tried to load modules anyway:

Code: Select all

modprobe dwc2
modprobe g_ether
The modules are loaded:

Code: Select all

# lsmod 
Module                  Size  Used by
g_ether                16384  0
usb_f_rndis            28672  1 g_ether
u_ether                24576  2 g_ether,usb_f_rndis
libcomposite           53248  2 g_ether,usb_f_rndis
dwc2                  143360  0
udc_core               49152  4 dwc2,u_ether,usb_f_rndis,libcomposite
cfg80211              573440  0
rfkill                 28672  2 cfg80211
i2c_bcm2835            16384  0
fixed                  16384  0
uio_pdrv_genirq        16384  0
uio                    20480  1 uio_pdrv_genirq
i2c_dev                16384  0
ip_tables              24576  0
x_tables               32768  1 ip_tables
ipv6                  425984  30
But no interface is created and dmesg shows an error:

Code: Select all

udc-core: couldn't find an available UDC - added [g_ether] to list of pending drivers
I am not familiar enough with raspberry-pi way to do OTG gadget (and moreover the stereopi way), and I did not have done it for a while on other boards so I might have forgotten something here. Any idea ?
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

User avatar
Realizator
Site Admin
Posts: 299
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: OTG support

Post by Realizator » Wed May 22, 2019 6:54 am

Stereomaton, we'll release PDF versions of our schematics in the nearest days.
The main idea is when you connect StereoPi by micro USB to your computer, system disconnects LAN9513 chip, and expose Compute Module's USB directly to micro USB pins. In this mode you can use it in client mode, like with Pi Zero or Pi A/A+ models.
Eugene a.k.a. Realizator

User avatar
Realizator
Site Admin
Posts: 299
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: OTG support

Post by Realizator » Wed May 22, 2019 2:10 pm

Stereomaton, now you can find our schematics here in our Wiki.
Eugene a.k.a. Realizator

stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: OTG support

Post by stereomaton » Wed May 22, 2019 9:56 pm

Thanks very much for the schematics!

I saw the small image extraction on the wiki, but at the time, I did not catch it. With the whole schematics, it is easier to understand.
The schematics also allowed me to understand that the USB-slave jumper is not related to OTG (and totally useless in my case as there is no emmc on my raspberri-pi module) and that I can safely plug both micro-usb and external power on white connector at the same time.

Unfortunately, I am away from my stereopi for several days, so I will not be able to test it soon.
However, I suspect that there is something wrong in the software as the error message suggests a missing driver (or driver configuration). If it does not work directly (as I suspect), I will give a look at the device tree for a missing driver or driver option.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

User avatar
Realizator
Site Admin
Posts: 299
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: OTG support

Post by Realizator » Thu May 23, 2019 9:38 am

stereomaton wrote:
Wed May 22, 2019 9:56 pm
I saw the small image extraction on the wiki, but at the time, I did not catch it.
Sorry, could you please clarify this notice? :-)
stereomaton wrote:
Wed May 22, 2019 9:56 pm
With the whole schematics, it is easier to understand.
The schematics also allowed me to understand that the USB-slave jumper is not related to OTG (and totally useless in my case as there is no emmc on my raspberri-pi module) and that I can safely plug both micro-usb and external power on white connector at the same time.
Yes, you can safely plug both micro USB and power, bat in this case power from power connector will be ignored (VD4 part of the schematics). We do it to avoid direct connection of two power sources (micro USB and external power).
stereomaton wrote:
Wed May 22, 2019 9:56 pm
Unfortunately, I am away from my stereopi for several days, so I will not be able to test it soon.
However, I suspect that there is something wrong in the software as the error message suggests a missing driver (or driver configuration). If it does not work directly (as I suspect), I will give a look at the device tree for a missing driver or driver option.
We did not run specific tests on OTG, but I think all manuals for using it on Pi Zero or Pi A/A+ (like this one) should work.
Eugene a.k.a. Realizator

stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: OTG support

Post by stereomaton » Thu May 23, 2019 10:36 am

Realizator wrote:
Thu May 23, 2019 9:38 am
stereomaton wrote:
Wed May 22, 2019 9:56 pm
I saw the small image extraction on the wiki, but at the time, I did not catch it.
Sorry, could you please clarify this notice? :-)
Retrospectively, I think I was tired, because I did not even read the bottom text which I usually do.
I was confused to not know where the top right wires go, but actually it is without importance.
Realizator wrote:
Thu May 23, 2019 9:38 am
Yes, you can safely plug both micro USB and power, bat in this case power from power connector will be ignored (VD4 part of the schematics). We do it to avoid direct connection of two power sources (micro USB and external power).
I would rather say that no power will be drawn from the micro-USB connector if the external power has equal or higher voltage (and switch is on). Quite the opposite.
stereomaton wrote:
Wed May 22, 2019 9:56 pm
We did not run specific tests on OTG, but I think all manuals for using it on Pi Zero or Pi A/A+ (like this one) should work.
The link you provide talk about a device-tree overlay (which modifies the OTG driver configuration), so I suspect it to be a good candidate. I will try whenever possible.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

User avatar
Realizator
Site Admin
Posts: 299
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: OTG support

Post by Realizator » Thu May 23, 2019 10:46 am

stereomaton wrote:
Thu May 23, 2019 10:36 am
Realizator wrote:
Thu May 23, 2019 9:38 am
Yes, you can safely plug both micro USB and power, bat in this case power from power connector will be ignored (VD4 part of the schematics). We do it to avoid direct connection of two power sources (micro USB and external power).
I would rather say that no power will be drawn from the micro-USB connector if the external power has equal or higher voltage (and switch is on). Quite the opposite.
Yep, I may be wrong with isolating USB or external power source. Need to look at this again, as this feature was originally implemented at the end of 2015, in our first generation of StereoPi. Here is how this generation looks like:

Image
Eugene a.k.a. Realizator

stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: OTG support

Post by stereomaton » Sat May 25, 2019 1:27 pm

Not so many time to spent on it, but I tried this:
  1. Add dtoverlay=dwc2 in /boot/config.txt
  2. Add modules-load=dwc2,g_ether at the end of /boot/cmdline.txt command line
Now the kernel does not complain anymore and an usb0 interface is created.

Also added this in (newly created) /etc/network/interfaces.d/usb0

Code: Select all

auto usb0
allow-hotplug usb0
iface usb0 inet static
       address 192.168.42.1
       netmask 255.255.255.0
       network 192.168.42.0
       broadcast 192.168.42.255
so that network interface is statically configured at startup, which is OK.

However, the usb-net device is not detected by my host computer. Need more investigation.
The kernel notifies ethernet/lan disconnect so the usb-switching circuitry seems to do its job at least.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

stereomaton
Posts: 94
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: OTG support

Post by stereomaton » Sat May 25, 2019 3:16 pm

Found!

First, according to https://lb.raspberrypi.org/forums/viewt ... 7#p1107702, we need to have USB_OTG logical 1 to be in device mode. Stereopi has a pull-down on this pin which makes the USB port to be a host (makes sense for LAN/USB). Fortunately, thanks to this resistor, man could potentially easily change the value with a bit of soldering. However, the so called implantation document, describing where are placed components on the board, would make it easier...

Can you publish it ?

Searching further, I found here https://github.com/raspberrypi/firmware ... ays/README that we can override the behavior by software regardless of the hardware pin, by adding dtoverlay=dwc2,dr_mode=peripheral instead of the aforementioned dtoverlay=dwc2 in /boot/config.txt
And this works!

However, if you do the same for your board, beware that now the usb port is forced in device mode. This implies that LAN9513 (i.e. USB ports and Ethernet) will not work anymore (unless you change the config.txt back) even when the micro USB is unplugged. The ideal way would be that SEL_USB_SW controls the USB_OTG signal, but as the polarity is reversed, it is not a straightforward hack to do.

Also notice that in order to use the usb-net link, you also need either to set a fixed IP (e.g. 192.168.42.2) on your host PC with proper routes for its usb interface, or install a properly configured DHCP server on the stereopi to deliver automatic network configuration to the PC.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi Standard Edition + CM3Lite module

Post Reply