Setup for OTG Serial Gadget
Enabling the USB OTG Serial Gadget
Plug your miniSD card into your card reader and navigate to the card's
/boot partition. This is the smaller of the two partitions.
Edit the cmdline.txt file and add this directly after
Edit the config.txt file and add this directly after the last line in the file:
If you have a GNU/Linux host machine, you can simulate enabling the Serial Getty Service on what will be the Raspberry Pi's serial console.
sudo ln -s /lib/systemd/system/getty@.service /media/user/uuid-of-sd-card/etc/systemd/system/getty.target.wants/getty@ttyGS0.service
Log in to your Raspberry Pi through the OTG Serial Console using a GNU/Linux host machine
- Plug your modified miniSD card into your Pi.
- Plug in your power cable.
- Wait 60 seconds.
- Plug in your USB cable into your Raspberry Pi and your PC.
sudo dmesg on your GNU/Linux machine and wait until you see the serial device register as something like
- Open a serial terminal program such as
- Change your serial device in the program to match your OTG registered Pi.
- Press Enter 2 or 3 times and wait a few seconds.
Raspbian GNU/Linux 9 raspberrypi ttyGS0
raspberrypi login: pi
Linux raspberrypi 4.9.41+ #1023 Tue Aug 8 15:47:12 BST 2017 armv6l
The programs included with the Debian GNU/Linux system are free
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Enabling the RPi OTG USB Serial Console Service
In order to use the OTG Serial port as a console, you will need to enable the service on the RPi. If you have a GNU/Linux host machine, this can be done directly on the miniSD card as detailed above. However, it can also be done by booting the Raspberry Pi with keyboard and monitor attached. Then enable the serial
getty console service:
sudo systemctl enable getty@ttyGS0.service
This last step is probably the one you are missing.
Debugging Raspberry Pi OTG Serial Gadget g_serial
On the Raspberry Pi
Connect monitor and keyboard and apply power to the Raspberry Pi.
Once booted login and drop into a root shell:
$ sudo -s
Check that the g_serial kernel module loaded:
# lsmod |grep g_serial
g_serial 3753 0
libcomposite 49619 2 g_serial,usb_f_acm
Check that the g_serial module configured properly:
# dmesg |grep g_serial
[ 0.000000] Kernel command line: bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x1fa00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=PARTUUID=51c4565c-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_serial
[ 4.765063] g_serial gadget: Gadget Serial v2.4
[ 4.771694] g_serial gadget: g_serial ready
[ 4.777739] dwc2 20980000.usb: bound driver g_serial
[ 5.253329] g_serial gadget: high-speed config #2: CDC ACM config
Check that the
g_serial special device file is present
# ls -l /dev/ttyGS*
crw------- 1 pi tty 245, 0 Sep 7 19:53 /dev/ttyGS0
Check that systemd started the console service on the
# systemctl status getty@ttyGS0
● getty@ttyGS0.service - Getty on ttyGS0
Loaded: loaded (/lib/systemd/system/getty@.service; enabled; vendor preset: e
Active: active (running) since Thu 2017-09-07 19:41:20 UTC; 10min ago
Main PID: 310 (login)
‣ 310 /bin/login --
Sep 07 19:41:20 raspberrypi systemd: Started Getty on ttyGS0.
On the host GNU/Linux machine
Check that the host has registered the serial OTG device
sudo dmesg | grep cdc
[ 7887.020889] cdc_acm 1-1:2.0: ttyACM0: USB ACM device
[ 7887.021079] usbcore: registered new interface driver cdc_acm
[ 7887.021080] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Check that the host system has created the special device file for the OTG connected device
sudo ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 Nov 22 09:18 /dev/ttyACM0
Connect to the device using your favorite terminal program. I prefer
minicom... However, your device has particular permissions and group assignment. If you wish to use it as a non-privileged user, you will need to make sure that your user is included in the group. In my example, the group is
dialout... and my user can be added to that group using this command:
sudo usermod -aG dialout user
Hopefully this debugging and setup guide helps.