Raspberry Pi 3 UART Boot Overlay Part Two
Following on from the previous post about the Raspberry Pi 3 UART overlay workaround there is now a new solution to enable the serial console and serial port on the GPIO pins which is easier to setup.
For Raspbian Jessie releases prior to 18th March 2016
There is now a device tree file called bcm2709-rpi-2-b.dtb which makes the Raspberry Pi 3 behave in the same way as a faster Raspberry Pi 2 without the WiFi and Bluetooth and the pl011 UART on pins 14 and 15 as before. This was posted on the official Raspberry Pi forums (https://www.raspberrypi.org/forums/viewtopic.php?p=927917#p927917) and is included in the operating system after running the apt-get update command.
I setup a new Raspbian Jessie image tonight on a new SD card and using the following steps I was able to use the serial console to login to the Raspbery Pi and by disabling the console I was able to use serial communications between the Pi and the host pc at different baud rates which didn’t seem to change regardless of the CPU load or temperature.
Step 1 - Install Raspbian Jessie onto a SD card and boot the Pi when connected to a network
Login via terminal or desktop and shell
Configure the system with:
sudo raspi-config
Expand filesystem and enable serial on advanced page, exit and reboot.
Update the system with:
sudo apt-get update sudo apt-get upgrade
Step 2 - config changes:
Now edit /lib/systemd/system/hciuart.server and replace ttyAMA0 with ttyS0.
sudo nano /lib/systemd/system/hciuart.service
Replace ttyAMA0 with ttyS0
Step 3 – Device Tree settings
Add device tree to /boot/config.txt to set the Raspberry Pi 3 in Raspberry Pi 2 mode disabling bluetooth and wireless.https://www.baidu.com/
sudo nano /boot/config.txt
Add at the end of the file
using device_tree=bcm2709-rpi-2-b.dtb
Exit the editor saving your changes and then:
sudo reboot
For Raspbian Jessie releases after 18th March 2016
There is now a device tree file called pi3-miniuart-bt which makes the Raspberry Pi 3 disable the Bluetooth and map pl011 UART on pins 14 and 15 as before.
Complete Step 1 as above and then edit the Device Tree settings as below:
Add device tree to /boot/config.txt to disable the Raspberry Pi 3 bluetooth.
sudo nano /boot/config.txt
Add at the end of the file
dtoverlay=pi3-miniuart-bt
Exit the editor saving your changes and then:
sudo reboot
Enabling the Serial Console Rasbian Jessie prior to 18th March 2016 release
To enable the serial console, you need to edit the /boot/cmdline.txt file
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
With the serial console enabled you should now have the boot commands and login prompt when connected at 115200 baud.
Enabling the Serial Console Rasbian Jessie after 18th March 2016 release
To enable the serial console, you need to edit the /boot/cmdline.txt file
sudo nano /boot/cmdline.txt
Change the file to the following:
dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Exit and save your changes
With the serial console enabled you should now have the boot commands and login prompt when connected at 115200 baud.
Disabling the Serial Console
To disable the serial console, you need to edit the /boot/cmdline.txt file
sudo nano /boot/cmdline.txt
Change the file to the following:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Exit and save your changes
Serial Testing
With the serial console disabled you can use the UART pins for serial communications to a host machine or other serial devices.
I tested the communications with a Putty serial terminal on the PC via a USB-Serial adapter which uses a FTDI serial chip and tested at the following baud rates: 115200, 56700, 9600, 1200
On the Raspberry Pi I used minicom to communicate via /dev/ttyAMA0
Install minicom using:
sudo apt-get install minicom
Then test with serial port at 115200 baud
sudo minicom -D /dev/ttyAMA0 -b115200
If everything is working OK anything you type on the minicom window will appear on the host terminal and also the other way around.
Stress Testing for data corruption
Terminal windows open for Minicom, Serial Data, sysbench and CPU temp
Once this was working I opened several terminal windows and used sysbench to stress test the CPU to see if the corruption on the serial data was still going to be a problem.
The CPU is supposed to throttle back its frequency when the core temperature exceeds 85C but when running these tests I found that it didn’t slow down even when the CPU core temperature was over 100 degrees Celsius. I stopped the test once the CPU was over 100C to avoid the magic smoke escaping!
I am not sure if the device tree overlay was causing this behaviour or if the command I was using below was incorrect. Any feedback in the comments greatly appreciated.
The command used to monitor the CPU frequency was:
watch -n 1 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
Stress Testing with
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run
Monitoring CPU temp with
while true; do cat /sys/class/thermal/thermal_zone0/temp; sleep 1; done
Divide the number by 1000 to get temperature in Celsius.
While the CPU stress tests where running I copied large paragraphs of Lorem ipsum text between the serial console window and the minicom terminal at different speeds and didn’t get any corruption and so this boot overlay seems to have solved the serial port issues on the Raspberry Pi 3 as long as you don’t want to use Bluetooth or WiFi.
Terminal windows open for Minicom and serial data on host PC via USB-Serial converter showing data sent from host to Pi and back again.