Since my previous post on they issues with the pi I have been doing some more experimenting with the USB-C port on the pi as a Linux gadget interface. As the pi4 has both host and client USB simultaneously (unlike previous versions) it makes it much easier alter the gadget code between tests. In doing so I discovered that my laptop wont enumerate the gadget in some situations due to more spec in-compliance.
A note on the pi’s “OTG” interface: An OTG USB interface supports both host and client modes, the newer term used for a Type C interface with this capability is a dual role device. While the pi’s SOC’S inbuilt USB interface supports both host and client mode the USB-C connector interface on the pi is only designed to support client mode (UFP in type C terminology).
This new issue occurs when the pi is powered over the 5V gpio pins as these are directly linked to the USB-C power pins, this causes the pi to emit power from the USB-C port (the USB-C spec prohibits this for clients (section 188.8.131.52.3.1 of the spec for anyone interested)). This causes some USB-C hosts to not enumerate the gadget when used with a C-C cable as it detects Vbus and fails to enter host mode. If the pi is powered by the USB host it will detect as there is no reverse Vbus to cause confusion during the port configuration phase.
Testing on some more devices my phone and the 3.0 USB-C port on my laptop detect the pi, these ports just use the CC resistors and ignore the presence of Vbus. The USB 3.1 on my laptop however doesn’t. As a test I also tried using some USB-A adaptors to rule out any CC issues, I Used a USB A-C cable attached to the pi and either a USB C-A adaptor or a USB hub with a C connector to the laptop and A ports at the laptop end. With this setup the order that things are plugged in generates different results, if the pi is plugged in first it wont detect but if the laptop is plugged in first it will. This makes logical sense as if the laptop is plugged in first it goes into host mode before it sees the Vbus from the pi. The oddest combination is to plug the C-A-C cable adaptor in with the pi being the host and the laptop as the client as the laptop enumerates the pi as a client in this configuration, the fact that this works is partly the fault of the laptop as it connects up its USB host pins in when connected in either host or client configuration.
There are some workarounds to this issue if you are encountering it. The first is to try a different USB-C port on the device you are connecting with as they might behave differently, alternatively a USB-A port with an A-C cable. Using a C-A then an A-C cable will also work if you plug the non pi end in first. in the longer term hopefully this will be fixed when the CC resistor issue is fixed.