Skip to main content

Raspberry Pi Compute Module as a USB Gadget

In standalone mode, the SD-Dev plus a Raspberry Pi compute module forms a compact single-board computer hosting your compute modules. These two recipes turn the Raspberry Pi into a USB gadget, so a single USB-C cable to your workstation gives you a serial console or an SSH connection. Both recipes target Raspberry Pi OS Bookworm or later, and every configuration step in them runs on the Raspberry Pi itself, not on your workstation.

USB serial gadget

  1. Edit /boot/firmware/config.txt: comment out otg_mode=1 and add dtoverlay=dwc2,dr_mode=peripheral at the end.
  2. Create /etc/modules-load.d/otg.conf containing:
    dwc2
    g_serial
  3. Reboot.
  4. Connect the SD-Dev to your host with the PWR+D USB-C port.
  5. Access the serial port from your host (for example screen on Linux/macOS, PuTTY on Windows).

The Raspberry Pi creates a /dev/ttyGS0 serial port readable and writable from both sides. To attach a full console:

  1. Symlink the getty service:
    sudo ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyGS0.service
  2. Enable and start it:
    sudo systemctl enable --now getty@ttyGS0.service

USB ethernet gadget

Alternatively, configure the Raspberry Pi as a USB Ethernet gadget for SSH over USB-C:

  1. Edit /boot/firmware/config.txt as above (comment otg_mode=1; add dtoverlay=dwc2,dr_mode=peripheral).
  2. Create /etc/modules-load.d/otg.conf containing:
    dwc2
    g_ether
  3. Reboot, then connect via the PWR+D USB-C port.
  4. Add and activate the connection:
    sudo nmcli con add type ethernet con-name usb-otg ifname usb0
    sudo nmcli con up usb-otg
  5. Find the Raspberry Pi's address and SSH to it:
    ip addr show dev usb0
    From your workstation, connect to that address:
    ssh pi@<address>

To make it persistent, create a systemd service that runs nmcli con up usb-otg at boot.

Next steps