ivann3001
Posts: 3
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: 1436
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";

	fragment@0 {
		target = <&uart0>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&uart0_pins>;
			status = "okay";
		};
	};

	fragment@1 {
		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 -@ -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: 3
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: 1436
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: 3
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: 1436
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: 1436
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

pi@raspberrypi:~$ 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!

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 1 guest