I ❤ UART

Yesterday I was trying to make Raspberry Pi 3 UART work on GPIO14 and 15, as it has been for the last decade, without luck. The ultimate objective was to be able to use Mavproxy on the Pi to talk to Ardupilot. I was following (almost) literally the instruction found in this Stackexchange Q&A, this RPi forum post and this other post here. But the UART was always silent. Obviously I first tried to clear out every possible hardware error, also becoming less and less sure that ttyAMA0 was the correct interface (ttyS0 was always giving I/O error).

Finally, I found the solution on this blog post. It suggested to download a totally different overlay file, this one1, with also a different extension, .dtb vs. .dtbo — don’t ask me the difference —, but it worked!

pelan@drone:~> dmesg | grep -i "ama\|tty\|serial\|uart"
[Wed May 23 13:12:57 2018] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  net.ifnames=0 dwc_otg.lpm_enable=0 console=tty1 root=/dev/sda2 rootfstype=btrfs elevator=deadline rootdelay=10 rootwait
[Wed May 23 13:12:57 2018] console [tty1] enabled
[Wed May 23 13:12:57 2018] Serial: AMBA PL011 UART driver
[Wed May 23 13:12:57 2018] uart-pl011 3f201000.serial: could not find pctldev for node /soc/gpio@7e200000/uart0_pins, deferring probe
[Wed May 23 13:12:57 2018] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[Wed May 23 13:12:58 2018] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[Wed May 23 13:12:58 2018] usb usb1: SerialNumber: 3f980000.usb
[Wed May 23 13:12:58 2018] uart-pl011 3f201000.serial: cts_event_workaround enabled
[Wed May 23 13:12:58 2018] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[Wed May 23 13:12:58 2018] 3f215040.serial: ttyS0 at MMIO 0x0 (irq = 166, base_baud = 31250000) is a 16550
[Wed May 23 13:12:59 2018] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[Wed May 23 13:12:59 2018] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[Wed May 23 13:13:00 2018] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Wed May 23 13:13:00 2018] usb 1-1.4: SerialNumber: 0019E06B586BA8A1F2FF0049
[Wed May 23 13:55:53 2018] uart-pl011 3f201000.serial: no DMA platform data
pelan@drone:~> ltime /boot/firmware/overlays/*bt*
-rwxr-xr-x 1 root root 1.3K Mar  7  2016 /boot/firmware/overlays/pi3-miniuart-bt-overlay.dtb
-rwxr-xr-x 1 root root 1.1K Jul 20  2017 /boot/firmware/overlays/pi3-miniuart-bt.dtbo
-rwxr-xr-x 1 root root  810 Jul 20  2017 /boot/firmware/overlays/pi3-disable-bt.dtbo
pelan@drone:~> cat /boot/firmware/config.txt | tail -15
program_usb_boot_mode=1

start_x=1
gpu_mem=128

# change ttyAMA0 back to original (see Bluetooth and mini-uart on Pi 3). Also disable console=ttyAMA0,115200 if you plan to use ttyAMA0 for other purposes
core_freq=250
enable_uart=1
#dtoverlay=pi3-disable-bt
# found here: https://www.briandorey.com/post/raspberry-pi-3-uart-overlay-workaround
dtoverlay=pi3-miniuart-bt-overlay

# Disable audio (added by raspberrypi-sys-mods)
# dtparam=audio=no
pelan@drone:~> md5sum /boot/firmware/overlays/pi3-miniuart-bt-overlay.dtb 
9d9fdb1cb554e2b8527801f4c274c9f5  /boot/firmware/overlays/pi3-miniuart-bt-overlay.dtb

And this is the “final product” 😂 where, according to the RPi3 pinout, we have:

  • pin 2 – 5V
  • pin 4 – unused
  • pin 6 – ground
  • pin 8 – GPIO 14 or UART0 TX that is connected to Pixhawk Telem2 RX (green cable)
  • pin 10 – GPIO 15 or UART0 RX that is connected to Pixhawk Telem2 TX (orange cable)

RPi3 pinout

Also note in the below image how the Teensy Telemetry is working marvellously with it’s solid red led and just the TX (from the Pixhawk point of view) orange pin attached. I’m pretty sure that I never told Ardupilot to spam Mavlink messages even if not requested, and this explains why I lost a couple of hours wondering why this setup wasn’t working all the times. The explanation is that Mavlink telemetry starts to flow only when Mavproxy is launched on the Pi3 and thus Ardupilot is kindly asked to send telemetry on it’s TX pin. Hooray!

.

Ok, and now if you want to see a guy with a proper, well explained setup, just look at this video.

  1. md5sum: 7c0930f83d29e4becb47bfa55840348b assets/attachments/20180523/pi3-miniuart-bt-overlay.zip