Skip to content

Instantly share code, notes, and snippets.

@wuhanstudio
Last active October 15, 2025 12:38
Show Gist options
  • Select an option

  • Save wuhanstudio/a77fc07aaaef05730a4f51dbf83c41fc to your computer and use it in GitHub Desktop.

Select an option

Save wuhanstudio/a77fc07aaaef05730a4f51dbf83c41fc to your computer and use it in GitHub Desktop.
g_serial as USB serial console
#/bin/bash
# Enable kernel module
echo "g_serial" >> /etc/modules
nano /etc/inittab
```
::respawn:/sbin/getty -L ttyAM0 115200 vt100
::respawn:/sbin/getty -L ttyGS0 115200 vt100
```
# Add systemd service
mkdir -p /etc/systemd/system/[email protected]
nano /etc/systemd/system/[email protected]/10-switch-role.conf
```
[Service]
ExecStartPre=-/bin/sh -c "echo 2 > /sys/bus/platform/devices/sunxi_usb_udc/otg_role"
```
# Start service
systemctl --no-reload enable [email protected]
echo "ttyGS0" >> /etc/securetty
reboot

Initial Armbian setup

Once booted, do the inital setup. The password, user accounts and so on.

Type in reboot and once booted again login as root with the password you've set.

Enabling usbhost* devices

Now, once logged in type in:

armbin-config

You'll get a configuration screen and a complaint about no internet. Just ignore it and you'll see the Configuration Utility screen.

Within this screen, you'll select System > Hardware and enable the following (by pressing Space):

  • usbhost0
  • usbhost1
  • usbhost2
  • usbhost3

Once done, press Enter to apply changes. Use Escape to return back and exit out of the utility.

(We aren't done yet though)

Adding ethernet/serial drivers

With your favorite text editor open /boot/armbianEnv.txt

After the overlays line add:

extraargs=console=ttyGS0,115200 modules-load=dwc2,g_cdc (if you want a USB serial for debugging)

and

modules-load=dwc2,g_ether (without USB serial device)

Exit and save and reboot the board for these to apply.

(Recommended) Optionally hardcode the MAC addresses of the USB gadget device

If you choose to use either g_cdc or g_ether you might notice that on each reboot the MAC address changes and messes with your host systems' ability to properly save the connection settings for your Pi board. This can be fixed by just setting the MAC addresses yourself.

In the same extraargs in the /boot/armbianEnv.txt file you can add:

  • For g_cdc: g_cdc.host_addr=00:22:82:ff:ff:00 g_cdc.dev_addr=00:22:82:ff:ff:01
  • For g_ether: g_ether.host_addr=00:22:82:ff:ff:00 g_ether.dev_addr=00:22:82:ff:ff:01

In here host_addr referrs to the address seen on the computer which is the USB host (aka your PC) and dev_addr is the one seen from your Pi board.

How to connect the Pi to the net?

Once you've set those kernel parameters and have rebooted, you must set up network otherwise that USB gadget device isn't being used.

We must do this both on the Pi and the host machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment