Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3881

General discussion • Re: RPi 5 USB gadget mode possible?

$
0
0
That guide is very light on details (for instance why are they setting up two ethernet interfaces? Why are they talking about bridging them?) and mistaken in at least one place.

Running rpi-update is also not generally recommended.

You can do it withourt running dnsmasq but Network Manager doesn't play well with the ethernet gadget so you have some different hoops to jump through.

Here's the minimum you need to do:
  1. See and apply Bookworm Point to Point Ethernet (inc g_ether).
  2. Code:

    sudo apt update && sudo apt upgrade -y
  3. Add the following to your config.txt

    Code:

    dtoverlay=dwc2,dr_mode=peripheral
  4. Add the following to the end of your cmdlline.txt making sure everything remains on one line

    Code:

    modules-load=dwc2,g_ether
  5. Reboot

I'll leave configuring things on the USB host as an exercise for the reader.

You might want to take a look at USB Ethernet Gadget A Beginner's Guide but bear in mind that the networking sections have not yet been updated for Bookworm/Network Manager.

Oh, and unless you're running with no additional devices connected and with a light CPU/system load expect power issues - most USB port can't supply the current needed.
Hello,

I actually posted a comment on that blog but it isn't approved yet, I found this thread in the meantime and thought to post here as well.

Can't seem to get that guide to work to create additional ethernet interfaces.

This is what I've done:

Code:

cat /boot/firmware/config.txt
returns:

Code:

[cm5]dtoverlay=dwc2,dr_mode=host
^ "Add dtoverlay=dwc2 to the /boot/firmware/config.txt file" in the guide; since above is the default value I didn't change anything

Code:

cat /boot/firmware/cmdline.txt
returns:

Code:

console=serial0,115200 console=tty1 root=PARTUUID=cc6cf2c5-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=SE
added:

Code:

modules-load=dwc2
^ "Add modules-load=dwc2 to the end of /boot/firmware/cmdline.txt file"; added text

cat /etc/modules returns:

Code:

i2c-dev
added:

Code:

libcomposite
^ "Add libcomposite to the end of the /etc/modules file", added text

Code:

sudo apt-get install dnsmasq

Code:

sudo nano /usr/local/sbin/usb-gadget.sh
<the content of which is the script on https://www.hardill.me.uk/wordpress/202 ... -c-gadget/>

Code:

chmod +x /usr/local/sbin/usb-gadget.sh
^ Not mentioned in the guide / blog-post; to make the script executable

Code:

sudo nano /lib/systemd/system/usbgadget.service
<the content of which is the systemd file on the above webpage>

sudo systemctl enable usbgadget.service
returns:

Code:

Created symlink /etc/systemd/system/sysinit.target.wants/usbgadget.service /lib/systemd/system/usbgadget.service.
Rebooted

systemctl status usbgadget returns:

Code:

usbgadget.service - My USB gadget     Loaded: loaded (/lib/systemd/system/usbgadget.service; enabled; preset: enabled)     Active: failed (Result: exit-code) since Fri 2024-08-02 23:33:10 CEST; 46s ago    Process: 1680 ExecStart=/usr/local/sbin/usb-gadget.sh (code=exited, status=203/EXEC)   Main PID: 1680 (code=exited, status=203/EXEC)        CPU: 1msAug 02 23:33:10 rpi5 systemd[1]: Starting usbgadget.service - My USB gadget...Aug 02 23:33:10 rpi5 (adget.sh)[1680]: usbgadget.service: Failed to locate executable /usr/local/sbin/usb-gadget.sh: Permission deniedAug 02 23:33:10 rpi5 (adget.sh)[1680]: usbgadget.service: Failed at step EXEC spawning /usr/local/sbin/usb-gadget.sh: Permission deniedAug 02 23:33:10 rpi5 systemd[1]: usbgadget.service: Main process exited, code=exited, status=203/EXECAug 02 23:33:10 rpi5 systemd[1]: usbgadget.service: Failed with result 'exit-code'.Aug 02 23:33:10 rpi5 systemd[1]: Failed to start usbgadget.service - My USB gadget.
sudo chmod +x /usr/local/sbin/usb-gadget.sh
Rebooted

systemctl status usbgadget returns:

Code:

usbgadget.service - My USB gadget     Loaded: loaded (/lib/systemd/system/usbgadget.service; enabled; preset: enabled)     Active: active (exited) since Fri 2024-08-02 23:36:19 CEST; 22s ago    Process: 1680 ExecStart=/usr/local/sbin/usb-gadget.sh (code=exited, status=0/SUCCESS)   Main PID: 1680 (code=exited, status=0/SUCCESS)        CPU: 91msAug 02 23:36:09 rpi5 systemd[1]: Starting usbgadget.service - My USB gadget...Aug 02 23:36:14 rpi5 usb-gadget.sh[1727]: Error: unknown connection 'bridge-br0'.Aug 02 23:36:14 rpi5 usb-gadget.sh[1735]: Error: unknown connection 'bridge-slave-usb0'.Aug 02 23:36:14 rpi5 usb-gadget.sh[1739]: Error: unknown connection 'bridge-slave-usb1'.Aug 02 23:36:19 rpi5 systemd[1]: Finished usbgadget.service - My USB gadget.
nmcli dev status returns:

Code:

DEVICE         TYPE      STATE                   CONNECTION         eth0           ethernet  connected               Wired connection 1 lo             loopback  connected (externally)  lo                 wlan0          wifi      disconnected            --                 p2p-dev-wlan0  wifi-p2p  disconnected            --  
I'll happily try what you wrote but what I don't get is that people seem to indicate that the guide / blog-post works and I can't seem to get it to work :(

Statistics: Posted by TheSwede86 — Tue Aug 06, 2024 7:44 pm



Viewing all articles
Browse latest Browse all 3881

Trending Articles