Published Monday 07 March 2016
Categories: Raspberry Pi |

Share this Share on Facebook Share on Twitter Share on Google Plus
Post View Counter 643

Raspberry Pi 3

Update: 19th March 2016

There is now a new Raspbian Jessie release dated 2016-03-18 which no longer works with this UART workaround. There is a new post at http://www.briandorey.com/post/Raspberry-Pi-3-UART-Boot-Overlay-Part-Two which shows how to use the latest release.

The original post and method below still works on the older operating system releases.

Original post below from the 7th March 2016:

With the release of the Raspberry Pi 3 the original hardware UART from the Broadcom processor has been reassigned to the Bluetooth chipset and the UART output on the GPIO pins now uses a mini-uart port. The mini-uart doesn't have a separate clock divisor and uses the core clock frequency.

I theory this shouldn’t make any difference to using the port but when the new Raspberry Pi 3 arrived we found that the boot console and serial port communications no longer worked at the baud rate specified and seemed to run approximate 1.6 times slower so a 115,200 baud rate was actually running at 72000 baud rate.

The baud rate also fluctuated according to the processor load and speed which made it unusable for any external serial devices.

We posted on the official Raspberry Pi forums https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=138223 to see if it would be possible to remap the hardware UART back to the GPIO pins and one of the Raspberry Pi Engineers, PhillE has been very helpful in finding a workaround for the UART issues and wrote a device tree overlay to remap the hardware UART.

One solution posted was to add core_freq=250 to /boot/cmdline.txt which reduces the CPU speed and cripples the performance of the Raspberry Pi 3 but this retains the Bluetooth functionality, an alternative way to keep the performance but also enable the UART support is to use a device tree overlay and reconfigure the Raspberry Pi 3 to use the new overlay which maps the hardware UART back to the GPIO header.

The Raspberry Pi foundation have posted about this problem on a FAQ for the Raspberry Pi 3 on their forum: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=137932 and replied with:

"My GPIO-connected UART device is broken on Pi 3, why?
The mini-uart is now routed to GPIO14/15 as the PL011 UART is now used for bluetooth communications. The mini-uart doesn't have a separate clock divisor and uses the core clock frequency. Changes in core clock (e.g. through throttling or idle/load frequency changes) will result in arbitrary modification of the effective baud rate. There's no easy way around this, but as a workaround there is a pi3-disable-bt devicetree overlay in latest rpi-update firmware which reverts this change."

The Device Tree Overlay Workaround

First we need to download and install a new device tree overlay.

The Raspberry Pi Engineer PhillE (forum username) has kindly made a custom overlay called pi3-miniuart-bt-overlay.dtb  to remap the UART ports and this needs to be copied into the overlays folder on the SD card and we also copied it into the root / pi3-miniuart-bt-overlay.dtb of the card as well.

We have made a copy of the new boot overlay available to download from here and it will also be included in a future Raspbian Linux release. We have archived the overlay in zip format and it will need to be uncompressed and copied to your SD card.

Next we need to edit the /boot/config.txt file, open the file either on your desktop computer or using the Raspberry Pi via SSH

sudo nano /boot/config.txt

You need to add the following lines:

dtoverlay=pi3-miniuart-bt-overlay
force_turbo=1

Exit and save your changes

Now edit /boot/cmdline.txt

sudo nano /boot/cmdline.txt

Change the file to the following:

dwc_otg.lpm_enable=0 console=serial1,115200  console=tty1 root=/dev/mmcblk0p2  kgdboc=serial1,115200 rootfstype=ext4 elevator=deadline fsck.repair=yes  rootwait

Exit and save your changes

If you have edited the cmdline.txt and config.txt files on your desktop put the SD card back in your Raspberry Pi 3 and boot to either a network SSH session or desktop and run the following in a shell window.

If you want to disable the built in bluetooth you need to stop hciattach trying to use the modem via uart0 which will disable the relevant systemd service

sudo systemctl disable hciuart

Now edit /lib/systemd/system/hciuart.server and replace ttyAMA0 with ttyS0.

sudo nano /lib/systemd/system/hciuart.service

Replace ttyAMA0 with ttyS0

Exit and save your changes

You need to update the operating system with the latest patches with:

 sudo apt-get update
 sudo apt-get upgrade
 sudo reboot

Once your Raspberry Pi 3 has rebooted you should now have access to the serial console via the GPIO header at 115,200 baud.

If you want to use the hardware UART without the serial console you do not need to make the changes to the cmdline.txt file as shown above.

Permalink