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

Re: Please help to Remap pin Uart 0

Fri May 18, 2018 7:44 am

Thanks PhiliE for your response , it worked.

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

Re: Please help to Remap pin Uart 0

Fri May 18, 2018 11:57 am

I've been looking into the issue of why the UART is left maped to GPIOs 14 and 15, and the answer is essentially because the firmware is not expecting it to move. Only Compute Modules are able to make use of the GPIOs above 27, so the firmware assumes that the primary UART (the one not used by Bluetooth) will either be on GPIOs 14&15 or it will be disabled. Parsing the default CM dt-blobs during bootup causes 14 & 15 to be switched to UART0, which will later be switched to UART1 if needed. If it's determined that the UART should be disabled, and if 14 & 15 are still mapped to UARTs, then they are returned to inputs. Because you want the UART to be enabled, the unmapping logic doesn't apply and the UART ends up in two different places.

There are a few solutions to this:
1. Get the firmware to read the Device Tree to work out where the UART is mapped, and undo the 14&15 mapping as necessary. This is feasible but cumbersome.
2. Get the firmware to always remove the 14 & 15 mapping, trusting the kernel to remap the UART. This would probably lose early-console output.
3. Modify the overlay to explicitly return GPIOs 14 & 15 to inputs.

Of these, 3 is my clear favourite. You can download a patched overlay here - copy it into /boot/overlays, disable any forced GPIO patching you may have in place form /etc/rc.local etc., and reboot.

Let me know if it works for you, and I'll push the change into the kernel for future releases.

moemoe
Posts: 2
Joined: Tue Jun 26, 2018 11:51 am

Re: Please help to Remap pin Uart 0

Tue Jun 26, 2018 12:31 pm

PhilE wrote:
Fri May 18, 2018 11:57 am
Of these, 3 is my clear favourite. You can download a patched overlay here - copy it into /boot/overlays, disable any forced GPIO patching you may have in place form /etc/rc.local etc., and reboot.

Let me know if it works for you, and I'll push the change into the kernel for future releases.
This works great when used at boot time (/boot/config.txt), but for some reason doesn't change anything when loaded at run time?

Code: Select all

[email protected]:~# dtoverlay -v uart0 txd0_pin=36 rxd0_pin=37 pin_func=6
run_cmd: which dtoverlay-pre >/dev/null 2>&1 && dtoverlay-pre
DTOVERLAY[debug]: Found override txd0_pin
DTOVERLAY[debug]:   override txd0_pin: cell target brcm,pins @ offset 8 (size 4)
DTOVERLAY[debug]: Found override rxd0_pin
DTOVERLAY[debug]:   override rxd0_pin: cell target brcm,pins @ offset 12 (size 4)
DTOVERLAY[debug]: Found override pin_func
DTOVERLAY[debug]:   override pin_func: cell target brcm,function @ offset 8 (size 4)
DTOVERLAY[debug]:   override pin_func: cell target brcm,function @ offset 12 (size 4)
DTOVERLAY[debug]: delete_node(/__symbols__)
DTOVERLAY[debug]: Wrote 920 bytes to '/tmp/.dtoverlays/0_uart0.dtbo'
DTOVERLAY[debug]: Wrote 956 bytes to '/sys/kernel/config/device-tree/overlays/0_uart0/dtbo'
run_cmd: which dtoverlay-post >/dev/null 2>&1 && dtoverlay-post
[email protected]:~# gpio readall
+-----+------+-------+      +-----+------+-------+
| Pin | Mode | Value |      | Pin | Mode | Value |
+-----+------+-------+      +-----+------+-------+
|   0 | OUT  | Low   |      |  27 | IN   | Low   |
|   1 | IN   | High  |      |  28 | IN   | Low   |
|   2 | IN   | High  |      |  29 | IN   | Low   |
|   3 | IN   | High  |      |  30 | IN   | Low   |
|   4 | IN   | High  |      |  31 | IN   | Low   |
|   5 | IN   | High  |      |  32 | IN   | Low   |
|   6 | IN   | High  |      |  33 | IN   | Low   |
|   7 | IN   | High  |      |  34 | IN   | High  |
|   8 | IN   | High  |      |  35 | IN   | High  |
|   9 | IN   | Low   |      |  36 | IN   | Low   |
|  10 | IN   | Low   |      |  37 | IN   | High  |
|  11 | IN   | Low   |      |  38 | IN   | Low   |
|  12 | IN   | Low   |      |  39 | IN   | Low   |
|  13 | IN   | Low   |      |  40 | IN   | Low   |
|  14 | ALT0 | High  |      |  41 | IN   | Low   |
|  15 | ALT0 | High  |      |  42 | IN   | Low   |
|  16 | IN   | Low   |      |  43 | IN   | Low   |
|  17 | IN   | Low   |      |  44 | IN   | Low   |
|  18 | IN   | Low   |      |  45 | IN   | Low   |
|  19 | IN   | Low   |      |  46 | IN   | High  |
|  20 | IN   | Low   |      |  47 | OUT  | High  |
|  21 | IN   | Low   |      |  48 | ALT0 | Low   |
|  22 | IN   | Low   |      |  49 | ALT0 | High  |
|  23 | IN   | Low   |      |  50 | ALT0 | High  |
|  24 | IN   | Low   |      |  51 | ALT0 | High  |
|  25 | IN   | Low   |      |  52 | ALT0 | High  |
|  26 | IN   | Low   |      |  53 | ALT0 | High  |
+-----+------+-------+      +-----+------+-------+
[email protected]:~#

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

Re: Please help to Remap pin Uart 0

Tue Jun 26, 2018 2:14 pm

Yes, dynamic Device Tree reconfiguration is not supported in all cases. I2C and SPI buses get notified of changes (because they ask), but some others don't.

moemoe
Posts: 2
Joined: Tue Jun 26, 2018 11:51 am

Re: Please help to Remap pin Uart 0

Wed Jun 27, 2018 8:09 am

PhilE wrote:
Tue Jun 26, 2018 2:14 pm
Yes, dynamic Device Tree reconfiguration is not supported in all cases. I2C and SPI buses get notified of changes (because they ask), but some others don't.
That's a pity, because I relied on remapping the serial port to different peripherals on different ports.

So I better use a library like http://abyz.me.uk/rpi/pigpio/cif.html for switching alt modes?

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

Re: Please help to Remap pin Uart 0

Wed Jun 27, 2018 8:15 am

Yes, I think you'll have to.

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 3 guests