ivann3001
Posts: 5
Joined: Thu Jan 11, 2018 4:27 am
Location: Brisbane

Please help to Remap pin Uart 0

Thu Jan 11, 2018 7:02 am

I read a lot of pages how to remap pin on Uart0 but I could not do it. I can remap pin on Uart1 easily by edit /boot/config.txt "dtoverlay=uart1,txd1_pin=40,rxd1_pin=41 #for example.

Please help my solve this problem. Thanks

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

Re: Please help to Remap pin Uart 0

Thu Jan 11, 2018 10:13 am

As you've discovered, there is no standard uart0 overlay, but there should be.

Copy this code into a file called uart0-overlay.dts:

Code: Select all

/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	[email protected] {
		target = <&uart0>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&uart0_pins>;
			status = "okay";
		};
	};

	[email protected] {
		target = <&gpio>;
		__overlay__ {
			uart0_pins: uart0_pins {
				brcm,pins = <14 15>;
				brcm,function = <4>; /* alt0 */
				brcm,pull = <0 2>;
			};
		};
	};

	__overrides__ {
		txd0_pin = <&uart0_pins>,"brcm,pins:0";
		rxd0_pin = <&uart0_pins>,"brcm,pins:4";
		rts0_pin = <&uart0_pins>,"brcm,pins:8";
		cts0_pin = <&uart0_pins>,"brcm,pins:12";
		pin_func = <&uart0_pins>,"brcm,function:0";
	};
};
Compile and install it using:

Code: Select all

dtc [email protected] -I dts -O dtb -o uart0.dtbo uart0-overlay.dts
sudo cp uart0.dtbo /boot/overlays
Don't worry about the compilation warnings.
Then apply it by adding the following to config.txt:

Code: Select all

dtoverlay=uart0,txd0_pin=32,rxd0_pin=33,pin_func=7 # alt3
or

Code: Select all

dtoverlay=uart0,txd0_pin=36,rxd0_pin=37,pin_func=6 # alt2
If that works for you I'll get it added to the standard image.

ivann3001
Posts: 5
Joined: Thu Jan 11, 2018 4:27 am
Location: Brisbane

Re: Please help to Remap pin Uart 0

Fri Jan 12, 2018 1:10 am

Many thanks @PhilE.
Your code works perfectly :)

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

Re: Please help to Remap pin Uart 0

Fri Jan 12, 2018 9:30 am

That overlay will be part of the next firmware release, although I did remove the rts and cts pin parameters because they didn't work properly.

ivann3001
Posts: 5
Joined: Thu Jan 11, 2018 4:27 am
Location: Brisbane

Re: Please help to Remap pin Uart 0

Fri Jan 12, 2018 9:07 pm

It has some noise at the beginning but it doesn't master.

iwbnwif
Posts: 7
Joined: Tue May 31, 2016 2:56 pm

Re: Please help to Remap pin Uart 0

Wed Jan 17, 2018 1:05 pm

Firstly, I am rather new to RPI and very new to the device tree / overlays, so please bare with me!

I have a WaveShare display (https://www.waveshare.com/wiki/3.5inch_HDMI_LCD) which occupies physical pins 1-26 of the GPIO connector, even though it hardly uses any of them. I am not even using the touch part, just the power and HDMI input.

I would like to remap the PL011 UART to the connector, and specifically to GPIO pins that are not occupied by the display connector (say GPIO20 and GPIO21).

I think I can use the overlay at #2 and include the following line in /boot/config.txt

Code: Select all

dtoverlay=uart0,txd0_pin=20,rxd0_pin=21,pin_func=7 # alt3
Is there anything else I need to do, for example disabling hciuart as described here: viewtopic.php?t=138223 ?

Which file device will the PL011 (hardware) UART then appear as in /dev/ ?

My goal is to use the hardware UART on two pins with the termios API. I need the hardware UART because I want to send and receive packets which are framed by an initial break.

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

Re: Please help to Remap pin Uart 0

Wed Jan 17, 2018 1:46 pm

Unfortunately your scheme won't work. There is only one set of pins brought out onto the 40-pin header that can carry the UART signals - GPIOs 14-17 (TXD, RXD, CTS & RTS). These signals can be from UART0 (ttyAMA0) or UART1 (ttyS0), but not both. You need to read page 102 of the BCM2835 ARM Peripherals guide, where you will find details of the possible permutations.

iwbnwif
Posts: 7
Joined: Tue May 31, 2016 2:56 pm

Re: Please help to Remap pin Uart 0

Wed Jan 17, 2018 2:45 pm

PhilE wrote: Unfortunately your scheme won't work. There is only one set of pins brought out onto the 40-pin header that can carry the UART signals - GPIOs 14-17 (TXD, RXD, CTS & RTS). These signals can be from UART0 (ttyAMA0) or UART1 (ttyS0), but not both. You need to read page 102 of the BCM2835 ARM Peripherals guide, where you will find details of the possible permutations.
Thank you for the fast reply!

Ah, if I understand correctly then... it is only possible to remap pins within the confines of the allowable alternative functions for each pin.

So, in this context the capability provided by the overlay is the same at boot time as something like:

Code: Select all

gpio -g mode 14 alt0

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

Re: Please help to Remap pin Uart 0

Wed Jan 17, 2018 2:53 pm

Yes, pretty much. The overlay is intended for use on a Compute Module, where there are more pins available for user applications. There is more information in the README:

Code: Select all

[email protected]:~$ dtoverlay -h uart0
Name:   uart0

Info:   Change the pin usage of uart0

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

iwbnwif
Posts: 7
Joined: Tue May 31, 2016 2:56 pm

Re: Please help to Remap pin Uart 0

Wed Jan 17, 2018 3:04 pm

Thanks and sorry, yes I should have realised this is the CM forum.

Actually, my end plan is to use two CM3 but I was experimenting with a pair of RPI3 first.

All is not lost though because the display has a micro-USB power input, so I can power it that way and leave the GPIO connect completely free.

Thank you for the insight and saving me a bit of time trying to debug an impossible configuration!

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Mon Apr 16, 2018 1:32 pm

Hi @PhilE,

I used your code for my CM3 Lite. I connected the CM3 to my laptop using a USB to TTL converter. I use screen to view if my CM3 is booting or not. Well it is booting and your code works. However, I am not able to send any input from my keyboard to the CM3. So this means, Tx is working but Rx is not working. I tried with both alt2 an alt3, but the same result. Tx works, Rx doesn't work.
Last edited by Sohil.Mehta on Tue Apr 17, 2018 10:37 am, edited 2 times in total.

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

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 10:14 am

Are the flow control settings correct on both ends? If the terminal emulator on your laptop has RTS/CTS enabled then it may be waiting for a Clear-To-Send signal. Try sending characters to another target if you have one.

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 10:31 am

Update: When I use Alt2 or Alt3, I get data even on pin 14 (Tx). But pin 15 (Rx) doesn't work. How can this be possible? It should work only on 36 or 32 right for Alt2 and Alt3 respectively. Also, only when I use the default Alt0 pins 14 and 15, both Rx and Tx work i.e I am able to receive data from CM3 and I am able to send data to the CM3 from my laptop

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 10:36 am

PhilE wrote:
Tue Apr 17, 2018 10:14 am
Are the flow control settings correct on both ends? If the terminal emulator on your laptop has RTS/CTS enabled then it may be waiting for a Clear-To-Send signal. Try sending characters to another target if you have one.
If that's the case, it should not work for Alt0 right? But Rx and Tx works perfectly well on 15 and 14.

Anyway, I will try what you told me to do. Are you trying to say I use some other terminal on my Linux machine instead of screen and check what's happening?

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

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 10:54 am

It sounds like you have the same function mapped to mutiple pins, which is usually bad.

Install raspi-gpio if you don't already have it (sudo apt-get install raspi-gpio), or use your favourite GPIO utility, and record the state of all GPIOs. Then, if TXD0 and RXD0 appears in multiple places, use the utility to return the other pins to inputs. In raspi-gpio that would be (assuming 14 and 15 are still on alt0):

Code: Select all

$ raspi-gpio get
$ raspi-gpio set 14 ip
$ raspi-gpio set 15 ip

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

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 11:18 am

Code: Select all

dtoverlay=uart0,txd0_pin=36,rxd0_pin=37,pin_func=6
This makes sense - it selects TXD0 and RXD0 on 36 & 37.

Code: Select all

dtoverlay=uart0,txd0_pin=36,rxd0_pin=37
This doesn't make sense - by default the overlay uses Alt0, which are SPI functions on 36 and 37.
I dint even have to unmap pins 14 and 15. @PhilE can you explain why this worked?
The overlay changes the pins used by UART0, so as well as enabling UART0 functions on new pins it removes Alt0 from 14 & 15 (provided you change the pins).

You need to take some of the guesswork out of the testing by confirming that the pins are in the expected states after each configuration change. "raspi-gpio get" will do this.

Code: Select all

enable_uart=1
This is the default on a Pi without Bluetooth, so removing it shouldn't make any difference.

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 1:10 pm

Yes you are absolutely right PhilE. I made a mistake. Please ignore. I deleted my comment too.

So I did exactly what you said in the above comment. I set 14 and 15 to ip. Also, I removed the line enable_uart=1 and have retained dtoverlay=uart0,...........,pin_func=6 in config.txt Now, after I reboot, the changes are lost and 14 and 15 are set as TXD0 and RXD0 again. Also, they are conflicting with 36 and 37. This means I need to permanently disable UART0 on 14 and 15. How to do this? Include raspi-gpio set 14 ip and raspi-gpio set 15 ip in /etc/rc.local ?

Tx works on 36. Rx still doesn't work.

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

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 1:20 pm

You shouldn't need anything except the overlay, so either it isn't working or something else is overwriting the GPIO settings afterwards.

Put this in your config.txt and remove (or comment out) all other settings:

Code: Select all

dtoverlay=uart0,txd0_pin=36,rxd0_pin=37,pin_func=6
Reboot, then run "raspi-gpio get" and post the output.

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 2:12 pm

Did as you said. Here's the output:

https://imgur.com/87Uk1Li

BTW, putting raspi-gpio set 14 ip and raspi-gpio set 15 ip in rc.local worked. But I want to know how to make it work without rc.local.

Sohil.Mehta
Posts: 25
Joined: Thu Feb 01, 2018 6:45 am

Re: Please help to Remap pin Uart 0

Tue Apr 17, 2018 2:14 pm

There is nothing wrong with my USB to TTL converter. Coz it is working on 14 and 15 and even on 36 and 37 (by doing rc.local). I guess some setting in GPIO is getting overwritten.

Flavor
Posts: 3
Joined: Fri Jun 02, 2017 5:38 pm

Re: Please help to Remap pin Uart 0

Wed May 02, 2018 8:49 pm

I am trying to get UART0 to work on GPIO36/37.

On my Compute Module 3, if I set

Code: Select all

dtoverlay=uart0,txd0_pin=36,rxd0_pin=37,pin_func=6
then at bootup, I will get

Code: Select all

|  14 | ALT0 | High  |
|  15 | ALT0 | High  |
...
|  36 | ALT2 | High  |
|  37 | ALT2 | High  |
At that point, /dev/ttyAMA0 doesn't seem to work.

If I manually set 14 and 15 as input using

Code: Select all

sudo gpio -g mode 14 in
sudo gpio -g mode 15 in
then /dev/ttyAMA0 will start working.

What is the preferred way to boot up with UART0 on pins 36/37 and with pins 14/15 as input?

aayushi
Posts: 3
Joined: Wed May 16, 2018 6:50 am

Re: Please help to Remap pin Uart 0

Wed May 16, 2018 10:42 am

Hi @PhilE,



I want to connect HDMI display 5" (26 header pins) to R-Pi3. Also want to use UART0 (Tx= GPIO14, Rx=GPIO15).
So remapped UART 0 to Tx= GPIO36 and RX = GPIO=37 by using the command in config.txt file :

dtoverlay=uart0 ,txd0_pin36,rxdo_pin=37,pin_func=7 # alt 3

Also included following command in rc.local :

raspi-gpio set 14 ip
raspi-gpio set 15 ip

On entering "raspi-gpio get command" , i am getting TXD0 and RXD0 enabled at GPIO 14, GPIO 15 and GPIO36 ,GPIO37 respectively ,but still serial communication is not working, Though it was working on GPIO14, GPIO15 .

Now how to enable serial communication on GPIO 36, GPIO37 ?

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

Re: Please help to Remap pin Uart 0

Wed May 16, 2018 11:15 am

Having the same pin function, especially input functions, mapped to multiple pins is usually a bad idea, so I think the investigation is going to split into two halves:
  1. does unmapping the UART from 14 and 15 allow it to work on 36 and 37, and
  2. how to automatically unmap it from 14 and 15.
For 1, after the board has booted, use raspi-gpio (or your preferred gpio tool) to return pins 14 and 15 to inputs:

Code: Select all

$ raspi-gpio set 14-15 ip
Now verify that the UART is working.

aayushi
Posts: 3
Joined: Wed May 16, 2018 6:50 am

Re: Please help to Remap pin Uart 0

Thu May 17, 2018 5:58 am

Hi PhilE,

I tried the same as you said but still UART is not working.

Now what to do?
Attachments
IMG_20180517_111237267.jpg
IMG_20180517_111237267.jpg (108.21 KiB) Viewed 907 times

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

Re: Please help to Remap pin Uart 0

Thu May 17, 2018 3:08 pm

Having had a chance to try myself, I can see that the problem is your alt function for 36 and 37. Alt3 (7) for 36 and 37 is SD1_DAT0&1 - you want Alt2 (6), which works once you set 14 and 15 to inputs. I hope to have an answer to the lack of unmapping of 14 and 15 soon.

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 4 guests