Testing All 5 Uarts on Raspberry Pi 4B

From: Fred Finster <fred_at_thegalacticzoo.com>
Date: Tue, 24 Jan 2023 12:53:44 UTC
TOP POST answer : https://forums.raspberrypi.com/viewtopic.php?t=244827  
Testing of all 5 UARTS near bottom of this URL link

https://forums.raspberrypi.com/viewtopic.php?t=244827&sid=9955627b0e7844c752f46b5ae55ef684&start=75 
Page 4 URL link

*I copied and pasted below.  I /apologize in advance for troubles I am 
inflicting on text only email viewers.  I have set my Thunderbird/*

*/email to send out only text email.   Fred/*

  FreeBSD creates /dev/ttyu1

Sounds like  you need to disable bt???? Adding "dtoverlay=disable-bt" 
switches the UART roles so that UART0 is mapped to 14 & 15 (Alt0), 
leaving UART1 unmapped.


https://forums.raspberrypi.com/viewtopic.php?t=244827&sid=f4a784a3c40ed0940e6fbb9f81af5015&start=25#p1590882 
<https://forums.raspberrypi.com/viewtopic.php?t=244827&sid=f4a784a3c40ed0940e6fbb9f81af5015&start=25#p1590882>


      Re: Pi-4 Activating additional UART ports
      <https://forums.raspberrypi.com/viewtopic.php?t=244827&sid=f4a784a3c40ed0940e6fbb9f81af5015&start=25#p1590882>

Mon Jan 06, 2020 10:36 am 
<https://forums.raspberrypi.com/viewtopic.php?p=1590882&sid=3091c9b0b98ce61a2a9be011e1ef5386#p1590882>

On all Pis, UART0 is a PL011 that appear to Linux as ttyAMA<n>, and 
UART1 is an 8250 clone that appears as ttyS0. On a Pi4, UART2-5 are 
additional PL011s that also appear as ttyAMA<n>. The number starts at 0 
for the first enabled PL011 and counts up through all the enabled 
interfaces. The numbering is stable for any given combination of UARTs, 
but enabling or disabling one can change the number assignments of others.

Adding "enable_uart=1" to config.txt on a Pi4 enables ttyS0 (UART1) on 
GPIOs 14 & 15 (Alt5), leaving UART0 driving the Bluetooth interface on 
30-33 (Alt3). Adding "dtoverlay=disable-bt" switches the UART roles so 
that UART0 is mapped to 14 & 15 (Alt0), leaving UART1 unmapped.

As rpdom says, you can only enable one function on any pin at once, and 
enabling the same alternate function (e.g. RXD0) on multiple pins 
usually results in failure (outputs tend to work, inputs don't, but it 
is essentially undefined behaviour).

*//*

*/
/*

*/From:/*John Rushford <jjrushford_at_gmail.com>
*/Date:/*Sun, 22 Jan 2023 03:27:38 UTC

Mark,

Thanks for the reply.  I only have “dtoverlay=uart3” in the config.txt and with that entry, FreeBSD creates /dev/ttyu1 and /dev/cuau1 along with the .init and .lock files.
So, I tried with this entry in /etc/ttys and it was of no help, still no data:

	ttyu1 "none" vt100 on secure

thanks
John
jjrushford@gmail.com <mailto:jjrushford@gmail.com>

> On Jan 21, 2023, at 8:18 PM, Mark Millard <marklmi@yahoo.com> wrote:
> 
> On Jan 21, 2023, at 18:34, John Rushford <jjrushford@gmail.com> wrote:
> 
>> I have installed FreeBSD 13.1 on a raspberry PI 4b rev 1.4 and I am trying to use the additional serial ports that are available with the PI 4 with an Adafruit ultimate GPS card.
>> I found that it was problematic using the first serial port ttyu0 on GPIO pins 14 and 15 as data on the line from the GPS would interrupt the boot process and I verified that I was in fact able see data time stamps from the GPS card on the first uart port once I got FreeBSD to boot.
>> 
>> Now since I do not wish to use the first serial port, I’ve built the rpi-firmware port and copied all the uart dtb’s to /boot/msdos/overlays and I’ve tried enabling the uart’s in /boot/msdos/config.txt with “dtoverlay=uart3” for example.  
>> Enabling them does in fact  result in device entries created for them in /dev but, I am unable to see any data on the corresponding ttyuX or cuauX ports.
>> 
>> Just to eliminate a wiring error, I installed another SD card with Raspberry PI OS, enabled uart3 and I am able to see data on uart3 without any issue confirming I have everything wired up properly.
>> 
>> With FreeBSD, I have set the proper baud rate on the ports and I’ve tried disabling flow control on them, using stty, but no matter what I do, I never see any data on them.  Unless I’m missing something, I can only conclude there is some bug in FreeBSD preventing me from using these additional serial ports.  Has anyone here on this mailing list been able to use them?  If so, what does it take?
> 
> You did not mention /etc/ttys editing. So I wonder if you
> changed any of the lines like, say,
> 
> # Serial terminals
> # The 'dialup' keyword identifies dialin lines to login, fingerd etc.
> ttyu0   "/usr/libexec/getty 3wire"      vt100   onifconsole secure
> ttyu1   "/usr/libexec/getty 3wire"      vt100   onifconsole secure
> ttyu2   "/usr/libexec/getty 3wire"      vt100   onifconsole secure
> ttyu3   "/usr/libexec/getty 3wire"      vt100   onifconsole secure
> 
> to use, say, none instead of "/usr/libexec/getty 3wire", and other
> related edits.
> 
> But I've not tried to get any extra serial ports going on
> an RPi4B. So the above is just guess work about something
> to experiment with.
> 
> ===
> Mark Millard
> marklmi at yahoo.com

https://forums.raspberrypi.com/viewtopic.php?t=244827 Testing All 5 
Uarts on Raspberry Pi 4B near bottom of this URL link.

Question has anybody here on FreeBSD arm mailing list group made some or 
all of the Raspbian Linux Tools operational on FreeBSD? Maybe this is a 
simple recompile with a couple modifications?

I should just try myself first.  Just checking that NO ONE ELSE has 
already completed a Tool and is willing to share.

raspi-gpio,  rasp-imager,  rasp-config, dtoverlay


I suggest you start by running the following to establish whether the 
configuration has been successful:

$ raspi-gpio get 0-15 $ ls /dev/ttyAMA*

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 pi@raspberrypi:~$ ls /dev/ttyAMA* /dev/ttyAMA0 /dev/ttyAMA1 
/dev/ttyAMA2 /dev/ttyAMA3 /dev/ttyAMA4

config.txt   file contains

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).

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.

    I wonder, as GPIO 14 and 15 already used for uart0, how could Uart5
    flow control use GPIO 14 & 15 ?

By not enabling UART0.


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 <https://forums.raspberrypi.com/viewtopic.php?t=244827#>

|#!/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 <https://forums.raspberrypi.com/viewtopic.php?t=244827#>

|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:

Anyone know of Top Hats for a Raspberry Pi 4 that brings all 5 uarts to 
a 3.3V TTL level and drive some LEDs to see TX and RX activity, plus 
MAX232 style drivers to shift

from 3.3 Volt level to + - ~10V RS-232 drive level to a DB-9 IBM 
compatible D shell Connector?  With possibly a RS-485 driver style 
connection for long wiring runs?

Does this exist?  or  Should one fire up KiCAD and design such a board 
specifically for Raspberry Pi 4B 5 uarts?  Probably a market size of 10 
- 50 boards world wide, not much?

Hope this works for you John R.

-- 
Fred  Finster
fred@thegalacticzoo.com
+1 971-718-9144
https://GhostBSD-ARM64.blogspot.com
https://ghostbsd.org