Page 1 of 2

Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 4:18 am
by ptamike
The new Pi-4 features additional hardware UART ports but I've been unable to find any documentation explaining how to access them.

Can anyone help?

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 6:54 am
by rpdom
An updated ARM Peripherals document is going to be released soon that will cover the additional UARTs and I2C buses on the Pi 4B.

I think it has been mentioned somewhere about the GPIOs that they are available on and which ALT modes need to be selected.

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 7:09 am
by PhilE

Code: Select all

$ dtoverlay -a | grep uart
This will show that there are four new overlays - uart2 to uart5.

Code: Select all

$ dtoverlay -h uart2
The help info shows the GPIOs used by each new UART - 0-3 for UART 2, 4-7 for 3, 8-11 for 4 and 12-15 for 5. This does mean that UART 5 overlaps with the standard UARTs on 14 & 15, but UART 5 has its flow control signals there - TXD5 and RXD5 appear on 12 & 13.

Code: Select all

$ raspi-gpio funcs
Run on a Pi 4, this will show all of the alternate functions available on the 4.

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 7:36 am
by ptamike
Thanks for the answers. I'll look forward to seeing the new documentation.

In the meantime, can anyone suggest what I would need to add to /boot/config.txt to activate one of the new ports?

Thanks,

Mike

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 7:42 am
by PhilE

Code: Select all

dtoverlay=uart3        # without flow control pins
dtoverlay=uart3,ctsrts # with flow control pins
etc.

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 6:32 pm
by Notupus
And how do we enable a serial terminal on each uart?

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 7:02 pm
by klricks
Can more than 1 UART be used at the same time?

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 7:53 pm
by PhilE
To create a console on a UART, add "console=ttyAMAn,115200" to /boot/cmdline.txt, where n is a small integer - look in /dev to get the right number.

All 4 extra UARTs can be used at the same time provided their pins don't clash with something else you need.

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 8:25 pm
by Notupus
PhilE wrote:
Sat Jul 06, 2019 7:09 am

Code: Select all

$ raspi-gpio funcs
Run on a Pi 4, this will show all of the alternate functions available on the 4.
raspi-gpio does not exist on existing raspian lite images, how do I install that?

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 8:42 pm
by PhilE
sudo apt-get install raspi-gpio

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 8:47 pm
by Notupus
Also shouldn't the serial setting also set uart 0 to terminal mode, I know mine doesn't.

Re: Pi-4 Activating additional UART ports

Posted: Sat Jul 06, 2019 9:51 pm
by PhilE
The default kernel command line includes console=serial0, which the firmware translates to ttyAMA0 or ttyS0 as necessary. I don't think it would be appropriate to automatically create consoles on all enabled UARTs - many people would want to use them for something else.

Re: Pi-4 Activating additional UART ports

Posted: Sun Jul 07, 2019 7:14 am
by Notupus
Yea, but maybe add a way to do it from raspi-config?

Re: Pi-4 Activating additional UART ports

Posted: Tue Jul 09, 2019 9:48 am
by stefanvlad
I'm also interested in enabling a second UART

Re: Pi-4 Activating additional UART ports

Posted: Tue Jul 09, 2019 9:57 am
by PhilE
Do you feel there is some information missing from the posts above?

Re: Pi-4 Activating additional UART ports

Posted: Tue Jul 09, 2019 11:35 am
by stefanvlad
Sorry... I ran under the impression that some documentation is still pending. But you did say

Code: Select all

dtoverlay=uart3        # without flow control pins
dtoverlay=uart3,ctsrts # with flow control pins
How do I enable all of them. For instance

Code: Select all

dtoverlay=uart2,uart3,uart4,uart5
uart1 being enabled by default, pi 4 having 4 extra uarts. Correct me if I'm wrong.

Re: Pi-4 Activating additional UART ports

Posted: Tue Jul 09, 2019 11:45 am
by PhilE
You need one dtoverlay= for each overlay. Anything else on the line is treated as a parameter. If you don't want to use the flow control signals then a fully loaded system would be:

Code: Select all

dtoverlay=uart2
dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5
I'm sure you can guess how to enable flow control for any/all of them.

Note that the kernel will reject attempts to enable UARTs where the pins are in use by something else (e.g. UART0, UART1 or one of the I2C ports), or it might even disable the other thing, so make sure what you are trying to do is possible.

Re: Pi-4 Activating additional UART ports

Posted: Mon Jul 29, 2019 10:38 am
by MWpi
Hi All,

I have followed the above, but can not figure out how to open an additional UART. I normally use /dev/ttyS0 or serial0, so have tried ttyS2, AMA2, serial2 etc... is there a step I am missing in enabling this, or has the addressing/binding changed with the 4?

I have enabled uart2 by adding to the /boot/config.txt:
dtoverlay=uart2

MW

Re: Pi-4 Activating additional UART ports

Posted: Mon Jul 29, 2019 12:07 pm
by PhilE
On my Pi4 it appears as /dev/ttyAMA1 - there are no "serial<x>" aliases for the additional UARTs yet.

What other interface do you have enabled? uart2 attempts to use GPIOs 0 & 1 (0-3 if you're enabled RTS/CTS), so it won't work if something else (e.g. i2c0/i2c_vc) has grabbed 0 & 1.

Re: Pi-4 Activating additional UART ports

Posted: Mon Jul 29, 2019 7:49 pm
by MWpi
Hello,

Thanks for the reply. I have installed Buster (full) out of the box, so unless those pins are doing something by default, I don't know.

/dev/ttyAMA1 does appear, can be opened, but there is no traffic. Traffic is present when using GPIO14/15 (TX/RX checked)

Also, using:

Code: Select all

ls -l /dev/ttyA*
shows both AMA0 and AMA1, even though

Code: Select all

dtoverlay -l says:
No overlays loaded

This is with /boot/config.txt configured with:

Code: Select all

dtoverlay=uart2
It would appear that the uart does not load correctly (as seen with dtoverlay -l), unless I force

Code: Select all

sudo dtoverlay uart2
This is a strange one, indeed.

MW

Re: Pi-4 Activating additional UART ports

Posted: Mon Jul 29, 2019 7:56 pm
by MWpi
Update:

No idea why, but this is now working on AMA1. Must be a combination of me manually using sudo and loading and unloading, as I haven't changed anything in config.txt, or changed pins.

MW

Re: Pi-4 Activating additional UART ports

Posted: Mon Aug 05, 2019 12:04 pm
by p.rakowski
Hello.
Thanks to this topic, I managed to run additional UART ports. But I have problems with running the raspberry again. I've come to the point that restarting will block one uart port connected to Gpio-0, Gpio-1 (TXD2, RXD2) pins. I have to unplug these pins each time I start the system. Is there any solution to this problem?

greetings

Re: Pi-4 Activating additional UART ports

Posted: Tue Aug 06, 2019 9:03 am
by asafyurdakul
Hi everyone

Thanks for how to uarts activated on RPI-4. I added overlay lines (like below) to "/boot/config.txt" on my RPI-4

Code: Select all

[all]
enable_uart=1
dtoverlay=uart2
dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5
I have tested RX/TX for all activated uarts.
The results are below.

OK : There is no problem about transmit and receive.
NOK : Not worked.

uart1: OK
uart2: OK
uart3: NOK
uart4: OK
uart5: TX OK but RX not OK

There is a problem for uart3 and uart5.
I didn't understand why uart3 not worked and uart5 semi worked...
Please help me.

Regards

Re: Pi-4 Activating additional UART ports

Posted: Tue Aug 06, 2019 3:16 pm
by PhilE
I suggest you start by running the following to establish whether the configuration has been successful:

Code: Select all

$ raspi-gpio get 0-15
$ ls /dev/ttyAMA*
On my Pi4B I get the following:

Code: Select all

raspi-gpio get 0-15
GPIO 0: level=1 fsel=3 alt=4 func=TXD2 pull=NONE
GPIO 1: level=1 fsel=3 alt=4 func=RXD2 pull=UP
GPIO 2: level=1 fsel=4 alt=0 func=SDA1 pull=UP
GPIO 3: level=1 fsel=4 alt=0 func=SCL1 pull=UP
GPIO 4: level=1 fsel=3 alt=4 func=TXD3 pull=NONE
GPIO 5: level=1 fsel=3 alt=4 func=RXD3 pull=UP
GPIO 6: level=1 fsel=0 func=INPUT pull=UP
GPIO 7: level=1 fsel=0 func=INPUT pull=UP
GPIO 8: level=1 fsel=3 alt=4 func=TXD4 pull=NONE
GPIO 9: level=1 fsel=3 alt=4 func=RXD4 pull=UP
GPIO 10: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 11: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 12: level=1 fsel=3 alt=4 func=TXD5 pull=NONE
GPIO 13: level=1 fsel=3 alt=4 func=RXD5 pull=UP
GPIO 14: level=0 fsel=4 alt=0 func=TXD0 pull=NONE
GPIO 15: level=1 fsel=4 alt=0 func=RXD0 pull=UP
[email protected]:~$ ls /dev/ttyAMA*
/dev/ttyAMA0  /dev/ttyAMA1  /dev/ttyAMA2  /dev/ttyAMA3  /dev/ttyAMA4
The config.txt contains:

Code: Select all

enable_uart=1
dtoverlay=pi3-miniuart-bt
dtoverlay=uart5
dtoverlay=uart4
dtoverlay=uart3
dtoverlay=uart2
(The miniuart overlay uses ttyS0 for Bluetooth, freeing /dev/ttyAMA0).

I deliberately reversed the order of the UART overlays to demonstrate that ordering here makes no difference to the ttyAMA numbering. Using this script:

Code: Select all

#!/bin/sh

sudo stty -F /dev/ttyAMA0 115200
sudo stty -F /dev/ttyAMA1 115200
sudo stty -F /dev/ttyAMA2 115200
sudo stty -F /dev/ttyAMA3 115200
sudo stty -F /dev/ttyAMA4 115200

while true; do
  sudo sh -c "echo 0 > /dev/ttyAMA0"
  sudo sh -c "echo 1 > /dev/ttyAMA1"
  sudo sh -c "echo 2 > /dev/ttyAMA2"
  sudo sh -c "echo 3 > /dev/ttyAMA3"
  sudo sh -c "echo 4 > /dev/ttyAMA4"
  sleep 1
done
and moving my PC serial cable around the pins I found the following mapping:

Code: Select all

GPIO14 = TXD0 -> ttyAMA0
GPIO0  = TXD2 -> ttyAMA1
GPIO4  = TXD3 -> ttyAMA2
GPIO8  = TXD4 -> ttyAMA3
GPIO12 = TXD5 -> ttyAMA4
In other words, transmitting works on all 5 PL011/ttyAMA UARTs.

Running "cat /dev/ttyAMA<x>" on each of the different UARTs in turn and moving the TX pin of the PC serial port around the various RXD pins produced the RX mapping:

Code: Select all

GPIO15 = RXD0 -> ttyAMA0
GPIO1  = RXD2 -> ttyAMA1
GPIO5  = RXD3 -> ttyAMA2
GPIO9  = RXD4 -> ttyAMA3
GPIO13 = RXD5 -> ttyAMA4
Be aware that if you have a console running ttyAMA0 (or any UART) then it will compete for your input, so you may have to try a few times.

Re: Pi-4 Activating additional UART ports

Posted: Tue Aug 06, 2019 3:29 pm
by danjperron
Is it me but enabling uart2 is irrelevant since GPIO0 and GPIO1 are not available!

Unless it is possible to disable I2C0.

Why every body want uart2?

uart5 is the best one to enable if you need I2c and SPI.