# RPI4 additional serial ports do not work



## Alexander Mishin (Jan 30, 2022)

I'm trying to connect a GPS module to my RPI4B via an additional serial port, but it doesn't work for me.

```
[root@rhino /]# uname -a
FreeBSD rhino.xxx 13.0-STABLE FreeBSD 13.0-STABLE #0 stable/13-n249182-6f840e49af37: Sun Jan 30 01:48:22 +04 2022     root@xxx:/usr/obj/usr/src/arm64.aarch64/sys/RPI4_RHINO  arm64
```
I have connected loopbacks on 8&10, 21&24, 32&33 pins and configured my system as followed...
/boot/msdos/config.txt:

```
dtparam=audio=on,i2c_arm=on,spi=off,uart1=off
gpio=2,3=a0
dtoverlay=uart4
dtoverlay=uart5
gpio=8,9,12,13=a4
enable_uart=1
```
After my system is rebooted I had got three devices /dev/ttyu0, /dev/ttyu1 and /dev/ttyu2 and `dmesg` records:

```
[root@rhino /]# dmesg | grep uart
uart0: <PrimeCell UART (PL011)> mem 0x7e201000-0x7e2011ff irq 16 on simplebus0
uart1: <PrimeCell UART (PL011)> mem 0x7e201800-0x7e2019ff irq 44 on simplebus0
uart2: <PrimeCell UART (PL011)> mem 0x7e201a00-0x7e201bff irq 45 on simplebus0
```
I tested uarts working with the following script (got it from somewhere on the internet)


```
import serial
import time
test_string = "[serial port test]".encode('utf-8')
port_list = ["/dev/ttyu0", "/dev/ttyu1", "/dev/ttyu2" ]
for port in port_list:
  ok = False
  try:
    buff = bytearray(len(test_string))
    serialPort = serial.Serial(port, 115200, timeout = 2, writeTimeout = 2)
    bytes_sent = serialPort.write(test_string)
    time.sleep(1)
    bytes_read = serialPort.readinto(buff)
    ok = bytes_read == bytes_sent
    serialPort.close()
  except IOError:
    pass
  print("port %s is %s" % (port, "OK" if ok else "NOT OK"))
```

...and got...

```
[root@rhino /]# ~/src/uart_loopback.py
port /dev/ttyu0 is OK
port /dev/ttyu1 is NOT OK
port /dev/ttyu2 is NOT OK
```
Of course I also tested this with a real GPS module connected and it only worked on uart0(1). I see NMEA strings when the module is connected to pins 8 and 10 but
see nothing when it connected to pins 24 and 21 nor pins 32 and 33.

What did I wrong or what I maybe forgot to do?


----------



## Phishfry (Jan 31, 2022)

Did you download rpi-firmware package for the overlays?
Have you tried moving the overlay settings to /boot/loader.conf ?

When adding a 4 port serial card to FreeBSD I must edit /boot/device.hints on amd64.


----------



## Alexander Mishin (Feb 1, 2022)

Yes I installed the sysutils/rpi-firmware (as a package), copied overlays "uart4.dtbo" and "uart5.dtbo" to "/boot/msdos/overlays" and load them via /boot/msdos/config.txt (that way I can set the option "ctsrts" in the next step).
And as a result I got their device drivers in devfs but no data exchanges through them. Moreover, when I inaccuratelly touch the wires I expect to see some digital noise in the terminal windows but I see nothing.
I believe that this make no difference how to load overlays, from loader.conf or from config.txt, but I'll try to load them the way You suggest.

About /boot/device.hints, the "aarch64" has an FDT and onboard uarts are already defined in the FDT for RPI4 (The overlays mostly set "status = 'okay'"). I think, why would be need to define them once more by the "hints"?


----------



## Alexander Mishin (Feb 2, 2022)

Alas, no miracle happened... Moving uart overlay loading from /boot/msdos/config.txt to /boot/loader.conf didn't get uart4 or uart5 to work for me.
Tried to add the "bootdelay=-2" option to /boot/msdos/uEnv.txt but without success too, the system booting stops when uart0 receives any data.

Keeping look for something that could allow me to boot RPI4 with active GPS. If this even possible without using, erm... a bistable self-locking trigger (works good for about 5-7 years on RPI2)?


----------



## Phishfry (Feb 2, 2022)

Alexander Mishin said:


> think, why would be need to define them once more by the "hints"?


That was just a vague remembrance on x86. I also had trouble adding extra serial ports to APU2/3 because of addresses too. Had to use hints.


----------



## Phishfry (Feb 9, 2022)

I just bought some GPS modules for Hummingboard and I will share my work when I get them.








						2 pcs ublox neo-6m GPS module w/Taoglas Antenna serial port output, USA seller  | eBay
					

Find many great new & used options and get the best deals for 2 pcs ublox neo-6m GPS module w/Taoglas Antenna serial port output, USA seller at the best online prices at eBay! Free shipping for many products!



					www.ebay.com
				











						Ublox GY-NEO6MV2 6M GPS NEO Small Antenna Package for Arduino Location  | eBay
					

It has a simple 4 pin interface. Module with ceramic antenna, signal strong. The antenna size: 8x 20 mm/0.32"x0.8". With data backup battery.



					www.ebay.com


----------

