Ubuntu – Enable UART communication on Pi4 Ubuntu 20.04

20.04command lineraspberrypiserial port

I have Ubuntu 20.04 (32 bit) installed on RPI4 (4GB). I have loopback wire installed on Pin 8,10.

I need to use Bluetooth and also basic serial communication over Pin 8,10 to communicate with a Roboclaw motor controller.

Did install RASPI-CONFIG on Ubuntu using script at https://github.com/EmilGus/install_raspi-config but even though it installed successfully it loads with improper boot configuration error. That led me to /boot/firmware directory where I found config.txt, cmdline.txt etc. I removed the console=...

$ dmesg | grep tty
[    0.001061] printk: console [tty0] enabled
[    1.919367] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 29, base_baud = 0) is a PL011 rev2
[    1.924677] fe215040.serial: ttyS0 at MMIO 0x0 (irq = 31, base_baud = 62500000) is a 16550

So doesn't look like I disabled the console. How do I do that?

$ ls -l /dev/ttyS[0123]
crw-rw---- 1 root dialout 4, 64 Jun 27 12:32 /dev/ttyS0
$ ls -l /dev/serial
lrwxrwxrwx 1 root root 7 Apr  1 11:23 /dev/serial1 -> ttyAMA0

Second when I run sudo minicom -b 115200 -o -D /dev/ttyS0 (with loopback in place – verified correctly installed)

I see no characters. No verification of communication with serial.

Tried to change baud, parity, flow control settings with no effect.

Also have a simple serial test python which also fails to send/receive over serial at /dev/ttyS0 whether I run with sudo or without.

UPDATE
I got an updated install script (same github link above) and now have successfully installed RASPI-CONFIG, however while I can run it the directory structure on the RPi4 w/ Ubuntu 20.04 is different enough that it fails to find the config files it tries to change.

$ sudo raspi-config
grep: /boot/cmdline.txt: No such file or directory
sed: can't read /boot/cmdline.txt: No such file or directory
sed: can't read /boot/cmdline.txt: No such file or directory

I presume that are other Raspberry Pi 4 owners who intend to use the serial port and there's got to be a way to do what RASPI-CONFIG is trying to do on Ubuntu.

I've found the files in /boot/firmware

What should I change manually in them that RASPI-CONFIG would do via script?

Best Answer

I have a setup using both Bluetooth/hci0 and the miniUART/ttyS0 at the same time with Ubuntu 20.04 (Ubuntu 5.4.0-1034.37-raspi 5.4.101) 64bit on Raspberry Pi 4 Model B Rev 1.1 (4G memory). Here is what I did:

  1. Back up the original config.txt and cmdline.txt files

    sudo cp -pr /boot/firmware/cmdline.txt /boot/firmware/cmdline.txt-orig
    sudo cp -pr /boot/firmware/config.txt /boot/firmware/config.txt-orig
    
  2. Edit /boot/firmware/config.txt to comment out the enable_uart=1 like below,

    #enable_uart=1
    
    cmdline=cmdline.txt
    
  3. Remove the console setting console=serial0,115200 from /boot/firmware/cmdline.txt

  4. Disable the Serial Service which used the miniUART

    sudo systemctl stop serial-getty@ttyS0.service
    sudo systemctl disable serial-getty@ttyS0.service
    sudo systemctl mask serial-getty@ttyS0.service
    
  5. Add the user which will use the miniUART to tty and dialout group

    sudo adduser ${USER} tty
    sudo adduser ${USER} dialout
    
  6. Finally, reboot Ubuntu 20.04, then both hci0 and /dev/ttyS0 can work at the same time for me.

Detailed documentation about the UART can be found at https://www.raspberrypi.org/documentation/configuration/uart.md