vpelletier / python-functionfs

Pythonic API for linux's functionfs
GNU General Public License v3.0
40 stars 13 forks source link

ValueError: not enough values to unpack (expected 1, got 0) #15

Closed forderud closed 3 years ago

forderud commented 3 years ago

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:

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.

vpelletier commented 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).

forderud commented 3 years ago

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:

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.

forderud commented 3 years ago

Closing, since my problem have been resolved. Thanks for sharing this great project :-)