PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Tue Jan 14, 2020 11:05 am

Did I understand right, that without a customized dt-blob, (I will not yet go into the experience of compiling a new one yet), the HAT probing will occur anyway?
No, not if you have used the gpio directive to change to some pin function other than input.

And if you haven't used either a custom dt-blob or gpio directive then the pin is an input.

User avatar
rin67630
Posts: 1115
Joined: Fri Mar 04, 2016 10:15 am

Re: Pi-4 Activating additional UART ports

Tue Jan 14, 2020 11:36 am

PhilE wrote:
Tue Jan 14, 2020 11:05 am
Did I understand right, that without a customized dt-blob, (I will not yet go into the experience of compiling a new one yet), the HAT probing will occur anyway?

No, not if you have used the gpio directive to change to some pin function other than input.
And if you haven't used either a custom dt-blob or gpio directive then the pin is an input.
Sorry, I am now completely confused...
I have been speaking about the short time during HAT probing.
You wrote it would happen at boot time before the GPIO directive.
During that short time GPIO1 will be an output, providing the system clock to sense the EEPROM. Right?
After that it turns back to an unused input until being set to RX2 by the GPIO directive ALT4. Right again?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Tue Jan 14, 2020 11:38 am

I wrote:
(at the point of probing, which is after the "gpio ..." handling)

User avatar
rin67630
Posts: 1115
Joined: Fri Mar 04, 2016 10:15 am

Re: Pi-4 Activating additional UART ports

Tue Jan 14, 2020 1:46 pm

PhilE wrote:
Tue Jan 14, 2020 11:38 am
I wrote:
(at the point of probing, which is after the "gpio ..." handling)
No pin function can be set (until the kernel boots, at which point the HAT probing is long since finished) except via the firmware.
What is the right statement?
Could you recommend a lecture about the corresponding steps of the boot process?
I could not find the info in https://www.raspberrypi.org/documentati ... ce-tree.md

shubham trivedi
Posts: 22
Joined: Tue May 26, 2020 10:35 am

Re: Pi-4 Activating additional UART ports

Fri Jun 12, 2020 11:44 am

hello there,

I am working on RPi4 B model in my project I am using total 3 UART

1 UART for gsm interfacing (GPIO 14 and 15)

2nd UART I want to use for rs232 communication I am able to enable UART 2 by editing config.txt fine("dtoverlay=uart2") I want to know how I can assign the pin for rs232 I am using (GPIO 12[TX]and13[RX]) pls help me out

3nd UART I want to use for rs485 communication I am able to enable UART 3 by editing config.txt fine("dtoverlay=uart3") I want to know how I can assign the pin for rs485 I am using (GPIO 0[TX] and 1[RX]) pls help me out



I want to how I can use uart2 and uart3 for serial communication kindly help me



thanks in advance

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Fri Jun 12, 2020 1:12 pm

am able to enable UART 2 by editing config.txt fine("dtoverlay=uart2") I want to know how I can assign the pin for rs232 I am using (GPIO 12[TX]and13[RX])
The overlay enables the interface and changes the chosen pins to select the UART function. If you are asking how to change the pins to generate the correct voltages for RS232 and RS485 then it can't be done - you would need external circuitry for that.

klricks
Posts: 7724
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Pi-4 Activating additional UART ports

Wed Jun 17, 2020 3:53 am

shubham trivedi wrote:
Fri Jun 12, 2020 11:44 am
hello there,

I am working on RPi4 B model in my project I am using total 3 UART

1 UART for gsm interfacing (GPIO 14 and 15)

2nd UART I want to use for rs232 communication I am able to enable UART 2 by editing config.txt fine("dtoverlay=uart2") I want to know how I can assign the pin for rs232 I am using (GPIO 12[TX]and13[RX]) pls help me out

3nd UART I want to use for rs485 communication I am able to enable UART 3 by editing config.txt fine("dtoverlay=uart3") I want to know how I can assign the pin for rs485 I am using (GPIO 0[TX] and 1[RX]) pls help me out



I want to how I can use uart2 and uart3 for serial communication kindly help me



thanks in advance
The GPIO pins assigned to UARTs 2-5 can't be changed:
UART2 = GPIO 0 & 1
UART3 = GPIO 4 & 5
UART4 = GPIO 8 & 9
UART5 = GPIO 12 & 13

RPi4 pin-outs: https://cdn.mos.cms.futurecdn.net/kSo96 ... LMKqzc.png

From /boot/overlays/README

Code: Select all

Name:   uart0
Info:   Change the pin usage of uart0
Load:   dtoverlay=uart0,<param>=<val>
Params: txd0_pin                GPIO pin for TXD0 (14, 32 or 36 - default 14)

        rxd0_pin                GPIO pin for RXD0 (15, 33 or 37 - default 15)

        pin_func                Alternative pin function - 4(Alt0) for 14&15,
                                7(Alt3) for 32&33, 6(Alt2) for 36&37


Name:   uart1
Info:   Change the pin usage of uart1
Load:   dtoverlay=uart1,<param>=<val>
Params: txd1_pin                GPIO pin for TXD1 (14, 32 or 40 - default 14)

        rxd1_pin                GPIO pin for RXD1 (15, 33 or 41 - default 15)


Name:   uart2
Info:   Enable uart 2 on GPIOs 0-3
Load:   dtoverlay=uart2,<param>
Params: ctsrts                  Enable CTS/RTS on GPIOs 2-3 (default off)


Name:   uart3
Info:   Enable uart 3 on GPIOs 4-7
Load:   dtoverlay=uart3,<param>
Params: ctsrts                  Enable CTS/RTS on GPIOs 6-7 (default off)


Name:   uart4
Info:   Enable uart 4 on GPIOs 8-11
Load:   dtoverlay=uart4,<param>
Params: ctsrts                  Enable CTS/RTS on GPIOs 10-11 (default off)


Name:   uart5
Info:   Enable uart 5 on GPIOs 12-15
Load:   dtoverlay=uart5,<param>
Params: ctsrts                  Enable CTS/RTS on GPIOs 14-15 (default off)
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

shubham trivedi
Posts: 22
Joined: Tue May 26, 2020 10:35 am

Re: Pi-4 Activating additional UART ports

Wed Jun 17, 2020 10:51 am

hi there,

thanks for your reply .....i am working on it



i want to know one more thing that is how i can enable mutiple i2c when i am enabling i2c its showing 68 address i want to see other address also

please guide me if you have any relevant guide step by step share with me help me out

thanks in advance

danjperron
Posts: 3745
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Pi-4 Activating additional UART ports

Wed Jun 17, 2020 11:53 am

This is not 68 address!

It shows that you have something at the address 68. This is normally an RTC.

Each I2C devices have their own specific address. You need to be careful by settings each device with a different address. Some have fix address and some have pins dedicated to change the address.

shubham trivedi
Posts: 22
Joined: Tue May 26, 2020 10:35 am

Re: Pi-4 Activating additional UART ports

Thu Jun 18, 2020 7:41 am

thank you for your reply

yes it is RTC address I have converted 68 address in UU by setting my rtc working properly

now I want to interface one more i2c device (mcp3426) for that no new i2c address in coming how to enable other i2c port in rpi4 there are 6 i2c presents can you please tell me how to enable other i2c address pls share your view and help me out

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Thu Jun 18, 2020 7:59 am

I2C is a bus that can support many devices at once, as long as they all have different addresses (eventually you could run out of bandwidth, but that is unlikely to be a problem for you). All you have to do is connect the same SCL and SDA signals to all of the devices, and the I2C protocol does the rest. The mcp3426 datasheet (which you should read) says that it can have an address in the range 0x68 to 0x6f, and that it is programmed at the factory. If you have an mcp3426 programmed with an address of 0x68 then unfortunately you'll need to use a different I2C bus (unless you can change the address of the RTC) - or get an mcp3426 with a different address.

shubham trivedi
Posts: 22
Joined: Tue May 26, 2020 10:35 am

Re: Pi-4 Activating additional UART ports

Thu Jun 18, 2020 10:22 am

thanks for your reply

yes i want to use differnt i2c bus but i don't know how to enable different i2c bus please help me how i can get one more i2c bus please share step or procedure for enabling different i2c bus as in Rpi4 6 i2c inbuilt so let me know how to enable other i2c

danjperron
Posts: 3745
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Pi-4 Activating additional UART ports

Thu Jun 18, 2020 10:31 am

Please check the README in /boot/overlays folder.

ex: Four more i2c by including this in the config.txt

Code: Select all

dtoverlay=i2c1,pins_2_3
dtoverlay=i2c3,pins_4_5
dtoverlay=i2c4,pins_6_7
dtoverlay=i2c6,pins_0_1
You need to put pull up resistor on the new SDA and SCL pin (4k7 ohm typical, One side at 3.3V the other on the pin).

N.B. please update and upgrade your Pi, some old version didn't sort properly the i2c devices.

Daniel

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 2:17 pm

I’m having an issue with the Bluetooth when I activate any of the additional UARTs. I’ve tried this on two different RPi’s with the same behavior. Whenever dtoverlay=uartx (x being 2,3,4 or 5) is added to the config.txt file the Bluetooth fails to load on about half of the boots. I’ve tried a reboot vs. a full shutdown power cycle and it seems to make no difference. Anyone else that is using the additional UARTs seeing this behavior?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 2:24 pm

I wonder if there is a load-order problem sometimes; in the bad state, try and work out if /dev/ttyAMA0 is still the Bluetooth UART and not one of the others.

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 3:26 pm

Thanks for the help. I'm new to this platform so not exactly sure how to check that? I did some poking around in the system logs and found this when its in the bad state:

Jun 21 07:45:20 raspberrypi btuart[353]: Initialization timed out.
Jun 21 07:45:20 raspberrypi btuart[353]: bcm43xx_init
Jun 21 07:45:20 raspberrypi systemd[1]: hciuart.service: Control process exited, code=exited, status=1/FAILURE
Jun 21 07:45:20 raspberrypi systemd[1]: hciuart.service: Failed with result 'exit-code'.
Jun 21 07:45:20 raspberrypi systemd[1]: Failed to start Configure Bluetooth Modems connected by UART.

Edit: I did see that both /dev/ttyAMA0 and AMA1 exist via the ls command. How would I check if AMA0 is attached to the Bluetooth UART? Thanks I’m a total newb at this os.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 5:33 pm

I was thinking you might try sending some data and seeing where it appears, but there is a better way:

Code: Select all

pi@raspberrypi:~$ ls -l /sys/class/tty/ttyAMA*/device
lrwxrwxrwx 1 root root 0 Jun 21 18:24 /sys/class/tty/ttyAMA0/device -> ../../../3f201000.serial
That link shows that ttyAMA0 corresponds to UART0. Searching the .dts for Pi 4 give this list of UART associations:

Code: Select all

		uart0: serial@7e201000 {
		uart1: serial@7e215040 {
		uart2: serial@7e201400 {
		uart3: serial@7e201600 {
		uart4: serial@7e201800 {
		uart5: serial@7e201a00 {
The addresses on the right are addresses as seen on an internal bus, whereas the address in the symbolic link is valid in ARM space, but the final 6 digits are the same in both space.

Run the "ls -l ..." for a "good" boot and a "bad" boot and compare the results. If my theory is correct you might sometimes see ttyAMA0 pointing to e.g. uart2 (3f201400.serial).

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 6:08 pm

i get this output on both a good and bad boot, this is with dtoverlay=uart5.

Code: Select all

pi@raspberrypi:~ $ ls -l /sys/class/tty/ttyAMA*/device
lrwxrwxrwx 1 root root 0 Jun 21 11:05 /sys/class/tty/ttyAMA0/device -> ../../../fe201000.serial
lrwxrwxrwx 1 root root 0 Jun 21 11:05 /sys/class/tty/ttyAMA1/device -> ../../../fe201a00.serial
EDIT: also this for a good boot

Code: Select all

pi@raspberrypi:~ $ systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-06-21 11:05:12 PDT; 5min ago
     Docs: man:bluetoothd(8)
 Main PID: 742 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4035)
   Memory: 1.8M
   CGroup: /system.slice/bluetooth.service
           └─742 /usr/lib/bluetooth/bluetoothd

Jun 21 11:05:12 raspberrypi systemd[1]: Starting Bluetooth service...
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Bluetooth daemon 5.50
Jun 21 11:05:12 raspberrypi systemd[1]: Started Bluetooth service.
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Starting SDP server
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Bluetooth management interface 1.14 initialized
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Sap driver initialization failed.
Jun 21 11:05:12 raspberrypi bluetoothd[742]: sap-server: Operation not permitted (1)
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Endpoint registered: sender=:1.18 path=/org/bluez/hci0/
Jun 21 11:05:12 raspberrypi bluetoothd[742]: Endpoint registered: sender=:1.18 path=/org/bluez/hci0/
lines 1-20/20 (END)
And this when it fails:

Code: Select all

● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:bluetoothd(8)

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 7:01 pm

OK, so it doesn't look like an initialisation order bug. Another possibility is that the driver doesn't cope well with the fact that the extra UARTs all share the same interrupt as the original UART. It should be easy to setup a few loopback tests between UARTs - I'll take a look.

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Sun Jun 21, 2020 7:31 pm

PhilE wrote:
Sun Jun 21, 2020 7:01 pm
OK, so it doesn't look like an initialisation order bug. Another possibility is that the driver doesn't cope well with the fact that the extra UARTs all share the same interrupt as the original UART. It should be easy to setup a few loopback tests between UARTs - I'll take a look.
Much appreciated!

I also found this thread in which the last couple of posts describes the same issue with no apparent solution.
viewtopic.php?t=244741

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Tue Jun 23, 2020 11:08 am

The problem turned out to be easier to deal with than an interrupt sharing problem, although the hunt for a cleaner solution was fruitless.

I think you'll find that with additional UARTs enabled, the cases when Bluetooth works are when /dev/serial1 is a symbolic link to ttyAMA0:

Code: Select all

lrwxrwxrwx 1 root root 7 Jun 23 11:33 /dev/serial1 -> ttyAMA0
and when it doesn't work it points to ttyAMA1:

Code: Select all

lrwxrwxrwx 1 root root 7 Jun 23 11:29 /dev/serial1 -> ttyAMA1
The cause is a udev rule that creates the symbolic link, and it being designed to cope with different kernel configurations but not multiple PL011 UARTs.

You can download a fixed version of the udev rule from here: https://drive.google.com/file/d/1tA3vCV ... sp=sharing
Install it with:

Code: Select all

$ sudo cp /etc/udev/rules.d/99-com.rules 99-com.rules.orig
$ sudo cp 99-com.rules /etc/udev/rules.d/99-com.rules
and reboot.

If it solves the problem for you it will become part of the next release of the raspberrypi-sys-mods package.

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Tue Jun 23, 2020 3:28 pm

I downloaded and installed your fix this morning and have booted it 10+ times with no failures of the BT. I will test the serial port out later tonight but I'm sure it will work fine.

Great job and thank you for the quick fix!!

myk777
Posts: 11
Joined: Mon Jun 08, 2020 8:19 pm

Re: Pi-4 Activating additional UART ports

Tue Jun 23, 2020 11:58 pm

Both the serial port and the BT work great

Thanks again!!!
Attachments
5BE72D71-8AA0-48FA-97BD-9892A9FE0F98.jpeg
5BE72D71-8AA0-48FA-97BD-9892A9FE0F98.jpeg (107.83 KiB) Viewed 3175 times
Last edited by myk777 on Tue Jul 14, 2020 7:39 pm, edited 1 time in total.

Finn2708
Posts: 2
Joined: Mon Jun 29, 2020 7:12 pm

Re: Pi-4 Activating additional UART ports

Fri Jul 03, 2020 10:41 am

Adding any of

Code: Select all

dtoverlay=uart2
dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5
to /boot/firmware/usercfg.txt on a Pi 4b running Ubuntu 20.04 leads to a rainbow splashscreen on reboot, even though there are uart*.dtbo files in /boot/firmware/overlays.

Resetting usercfg.txt with a secondary linux machine allows the Pi to boot up again.

Are there any suggestions on how to activate the additional ports on ubuntu?

Other people seem to be struggling with this too:
https://raspberrypi.stackexchange.com/q ... rver-20-04

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3815
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi-4 Activating additional UART ports

Fri Jul 03, 2020 1:07 pm

No idea - sorry. The overlay seems fairly innocuous.

Return to “Device Tree”