Closed forderud closed 3 years ago
This error means you do not have any UDC (USB Device Controller) available - which, as I indeed believe the 4B has one on its USB-C port, means the corresponding module is not loaded.
An easy way to confirm this is to look into /sys/class/udc
: if there is nothing, no UDC module is loaded. If there is one symlink, then my code will use this UDC. If there are more than one (which is likely quite rare), then the --udc
argument is needed to tell which one to use. Here is how it looks on my pi zero with a raspi Debian:
$ ls -l /sys/class/udc/
total 0
lrwxrwxrwx 1 root root 0 Jan 1 1970 20980000.usb -> ../../devices/platform/soc/20980000.usb/udc/20980000.usb
If Linux did not load the module, it probably means the pi's devicetree did not enable it. How to enable it will depend on how your devicetree is managed. I believe Raspbian has a config tool to select which features should be enabled, which is typically used to enable some pins on the GPIO connector, but should also be able to enable the UDC in the devicetree.
In my case the module handling this UDC is the kernel.org dwc2, but I believe there may be another module for it in custom kernels like used in raspbian (I have not tried it for years, so this may be out-of-date).
Thanks for very useful feedback @vpelletier :+1: I've now managed to enable UDC through the following system config tweaks applied to a clean Raspberry Pi OS installation:
sudo pip3 install functionfs
to install functionfs 0.5.0echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "libcomposite" | sudo tee -a /etc/modules
echo "dwc2" | sudo tee -a /etc/modules
This gives the following after a reboot:
pi@raspberrypi:~ $ ls -l /sys/class/udc
total 0
lrwxrwxrwx 1 root root 0 Feb 27 14:38 fe980000.usb -> ../../devices/platform/soc/fe980000.usb/udc/fe980000.usb
The sample script now runs fine on my Raspberry Pi 4.
Closing, since my problem have been resolved. Thanks for sharing this great project :-)
Sorry for asking a newbie question, but I'm struggling to get started with
functionfs
on my Raspberry Pi 4 B that is supposed to have a UDC.Steps performed:
sudo pip3 install functionfs
to install functionfs 0.5.0examples/hid/device.py
script from this reposudo modprobe libcomposite
sudo setcap cap_sys_admin+ep device.py
(don't know if this is correct)I've also tested passing
--username pi
as argument, but the error is still the same. I see there's also a--udc
argument, but don't really know what to pass here. USB gadgets is totally new to me, so I don't really know how to proceed.