Just like the title says, I want to use both the GPIO UART and the USB Gadget at the same time.

Background: I've been working on modding up one of the Adafruit IoT printer projects, which uses the pi zero's GPIO based UART to perform its communications to the printer. Following all the steps, one thing that is called out is:

Under “Interfacing Options,” select “Serial.” Turn OFF the login shell over serial, and ENABLE the hardware serial port. NO and YES, respectively. This is vital!1

So I started back over the systemd configuration and attempted to update my /boot/cmdline.txt to include a console=serial1,115200 (instead of serial0), assuming (poorly) that since the g_serial mod is loaded later in the process that I'd be able to still get a login shell on ttyGS0 (assuming that I followed the rest of the standard systemd service creation you can find all over the internet).

After experimentation, setting the console=ttyGS0, console=ttyAMA0, and console=serial1 resulted in nothing useful and no login prompt over USB serial. As expected, setting console=serial0 resulted in the printer vomiting piles of Linux kernel bootup debug out over the serial port - so clearly the getty@.service is functioning correctly. Checking the debug logs:

Oct 30 01:39:18 iot kernel: [    4.883816] hub 1-0:1.0: USB hub found
Oct 30 01:39:18 iot kernel: [    4.886928] hub 1-0:1.0: 1 port detected
Oct 30 01:39:18 iot kernel: [    5.085302] g_serial gadget: Gadget Serial v2.4
Oct 30 01:39:18 iot kernel: [    5.087951] g_serial gadget: g_serial ready

Shows that it's getting loaded fine, but clearly, it's not finding / using the associated serial port as show by lsmod which of course means that no systemd service will find it:

root@iot:~# lsmod
Module                  Size  Used by
brcmfmac              273230  0
brcmutil                9114  1 brcmfmac
snd_bcm2835            23253  0
snd_pcm                89686  1 snd_bcm2835
snd_timer              22428  1 snd_pcm
cfg80211              542242  1 brcmfmac
snd                    60154  3 snd_timer,snd_bcm2835,snd_pcm
rfkill                 21476  4 cfg80211
i2c_bcm2835             6465  1
uio_pdrv_genirq         3718  0
uio                     9901  1 uio_pdrv_genirq
fixed                   3033  0
i2c_dev                 6674  2
g_cdc                   3862  0
u_ether                12901  1 g_cdc
usb_f_acm               5895  1
u_serial               10956  3 usb_f_acm
g_serial                3753  0                    # ---- whomp, whomp :(
libcomposite           48212  3 g_serial,usb_f_acm,g_cdc
dwc2                  128996  0
udc_core               38862  5 usb_f_acm,u_serial,dwc2,u_ether,libcomposite
ip_tables              12427  0
x_tables               22130  1 ip_tables
ipv6                  397673  20

Has anyone else been able to get BOTH the GPIO UART and the USB Serial Gadget working at the same time?

NOTE: I'm aware I can always use SSH to log into the system but that approach isn't going to function long term for this project. Thanks though! :)

  • Are you saying that g_serial works fine when you disable the hardware UART? Otherwise your question boils down to "how do I use g_serial as a login console"? – Dmitry Grigoryev Oct 30 '18 at 14:57
  • Also see if this helps. – Dmitry Grigoryev Oct 30 '18 at 15:03
  • 1
    @DmitryGrigoryev that's correct. If you disable the hardware UART, you can successfully use the g_serial as a login console – Wyatt Oct 30 '18 at 23:05

A console to the USB serial adapter won't work because at boot time the modules are not yet present and even if they are compiled in, the USB detection must run before the port becomes usable.

But do you really want a console, or just a login? For a login, you just have to run a getty on that port, see the systemd file getty@.service.

If you want a console on the device, you can use the command setconsole to set the console to another tty. You just have to call the command after the serial port is available.

  • I am looking to get a real login on that port (so after the system is up and running). The challenge is really "what's the port?" Manually attempting to add an /sbin/agetty --keep-baud 115200,38400,9600 ttySG0 vt220 (which is all systemd should be doing) doesn't result in anything that works. It's like the g_serial isn't actually finding / probing the device is the GPIO UART is enabled. I'm certain it's still there, but just needs to be added as an appropriate line to the kernel's boot. – Wyatt Oct 30 '18 at 10:41
  • You don't need to add it to the kernel boot line, you just have to make sure driver is available. What are the USB id's of the device? – RalfFriedl Oct 30 '18 at 17:41

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.