ThrudTheBarbarian
Posts: 17
Joined: Fri Jul 11, 2014 4:15 pm

Using the pi4's usb-c port as a host

Sun Nov 03, 2019 9:50 pm

So I'm hoping to have the Pi-4 as an embedded unit inside some hardware I'm building. Basically I want to use it for a compute-host and video-out because of the two HDMI ports. To do the video-out I wanted to feed the video data in over USB (I'm fine with usb-2) and to make it look as clean as possible, I wanted to use the USB-c port on the side. The plan was to 3d-print a custom case that let me use one of the right-angled USB-c-to-ribbon cables as an internal connection, and still expose all the other ports as useful in their own right.

The board I'll build that it'll attach to can then be connected via the GPIO pins, and also provide power to the Pi over the 2 +5v pins.

So, the problem is that I can't get the USB-c port to behave like a USB2 port :( Here's a photo of the cables I'm using.

Image

I initially followed the instruction on the Aliexpress page for the orientation of the FCP cable, but in fact I figured that (it being insulated on one side) I could try all the combinations without causing any harm. No joy. I even tried inserting the USB-c adaptor in the other way around (so it pointed down, not up) in case that was an issue. Still no joy.

I added:

Code: Select all

# USB-c port to host mode
dtoverlay=dwc2
dr_mode=host
... to /boot/config.txt

and appended to the end of /boot/cmdline.txt:

Code: Select all

console=serial0,115200 console=tty1 root=PARTUUID=5e3da3da-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles modules-load=dwc2

And then rebooted, but if I plug a USB-relay device (I wanted something powered in case power wasn't being transmitted, and all my hubs are USB3 :) ) into the USB-A socket at the end of the cable, I see nothing with 'lsusb'.

Code: Select all

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 008: ID 04d8:003f Microchip Technology, Inc. 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
If I plug the same device into one of the standard USB2 ports on the pi, it appears in the output of lsusb:

Code: Select all

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 008: ID 04d8:003f Microchip Technology, Inc. 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
usb-devices reports (for bus-3, which seems to be the usbc-port)

Code: Select all

T:  Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 1
D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=1d6b ProdID=0002 Rev=04.19
S:  Manufacturer=Linux 4.19.75-v7l+ dwc2_hsotg
S:  Product=DWC OTG Controller
S:  SerialNumber=fe980000.usb
C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
So, am I doing anything obviously wrong ? Is there a command I have to run after changing files in /boot or does it pick them up automatically ? Are there other modules I need to load, or other configuration I need to set ?

I'd really prefer to be able to do all this internally, rather than have to plug a 6" cable into and out of the case just to connect my board to the Pi ...

Thanks for any help :)

trejan
Posts: 3716
Joined: Tue Jul 02, 2019 2:28 pm

Re: Using the pi4's usb-c port as a host

Sun Nov 03, 2019 9:57 pm

It is a single line in /boot/config.txt

Code: Select all

dtoverlay=dwc2,dr_mode=host
You don't need to alter cmdline.txt

hippy
Posts: 10742
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Using the pi4's usb-c port as a host

Sun Nov 03, 2019 10:41 pm

If you are passing data from a PC or Pi into a Pi 4B which is being used as if a USB peripheral device, you want peripheral, device or gadget mode ( whatever it's called in config.txt ) on the Pi 4B's USB-C, not host.

ThrudTheBarbarian
Posts: 17
Joined: Fri Jul 11, 2014 4:15 pm

Re: Using the pi4's usb-c port as a host

Sun Nov 03, 2019 10:50 pm

@trejan:

Thanks :)

I actually tried it first with the single line "dtoverlay=dwc2,dr_mode=host" but that didn't work, and everything else was one thing per line, so I tried splitting it up after I found examples of people having the two-line version on the 'net.

I'll give it another go with the one-line version though...

@hippy:

No, I want the Pi to be a host - I want to plug in an STM32 board, and it's far easier to write a libusb host-based service on the Pi and have a usb-device on the STM32 than the other way around. The STM32 will be providing the video data over an isochronous (or maybe bulk) link and it'll be the only thing on that port.

Thanks all, for the replies :)

I did see (once)

Code: Select all

[  177.963424] usb 3-1: new full-speed USB device number 2 using dwc2
[  178.183433] usb 3-1: device descriptor read/64, error -71
[  178.523430] usb 3-1: device descriptor read/64, error -71
[  178.863443] usb 3-1: new full-speed USB device number 3 using dwc2
[  179.083450] usb 3-1: device descriptor read/64, error -71
[  179.423456] usb 3-1: device descriptor read/64, error -71
[  179.543543] usb usb3-port1: attempt power cycle
I guess the next thing to do is to buy a C<->A adaptor and see if that works. At least then I'll be able to rule out the cable.

trejan
Posts: 3716
Joined: Tue Jul 02, 2019 2:28 pm

Re: Using the pi4's usb-c port as a host

Sun Nov 03, 2019 11:12 pm

ThrudTheBarbarian wrote:
Sun Nov 03, 2019 10:50 pm
I actually tried it first with the single line "dtoverlay=dwc2,dr_mode=host" but that didn't work, and everything else was one thing per line, so I tried splitting it up after I found examples of people having the two-line version on the 'net.
That single line is all you need to do. I've been using a USB A to USB C adapter with one of my Pi 4 boards and its been working fine. I suspect the adapter cable you're using as it should work with no other configuration changes.

ThrudTheBarbarian
Posts: 17
Joined: Fri Jul 11, 2014 4:15 pm

Re: Using the pi4's usb-c port as a host

Sun Nov 03, 2019 11:34 pm

Yeah, I'm suspecting the same thing myself. Maybe I'll just have to put up with something sticking out of the case :(

I'll order the usb-c to usb-a and see what that shows...

Thanks :)

ThrudTheBarbarian
Posts: 17
Joined: Fri Jul 11, 2014 4:15 pm

Re: Using the pi4's usb-c port as a host

Wed Nov 06, 2019 3:32 am

So, just to close the loop on this.

I got my C:A adapter, and plugged in the USB-relay, then rebooted. Nada.

I changed the /boot/config.txt and moved the

Code: Select all

# USB-c port to host mode
dtoverlay=dwc2,dr_mode=host
line to the end, so it's in the [all] group and rebooted...

Et voila! I can see the USB relay device on the usb-c port :)

I still can't see the relay when it's plugged into the flexible cable, so it looks as though that was the problem. I also ordered some right-angle usbc<-->usba (male) adapters, so I guess I can put a USB-A receptacle on the motherboard and just use the right-angle cable. It's a bit bulky and it'll mean access to the HDMI is a bit harder, but it's still better than an external wire.

Now to set up a test device on the STM32 and see if I can get communication going :)

Return to “Advanced users”