15
Raspberry Pi 3 + UART/Bluetooth Issues By: Yeo Kheng Meng ([email protected] ckware v1.6 (30 Mar 2016) 1 my presentation can be found here: //engineers.sg/video/raspberry-pi-3-uart-bluetooth-issues--609

Raspberry Pi 3 + UART/Bluetooth issues

  • Upload
    yeokm1

  • View
    11.726

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Raspberry Pi 3 + UART/Bluetooth issues

1

Raspberry Pi 3 + UART/Bluetooth Issues

By: Yeo Kheng Meng ([email protected])Hackware v1.6 (30 Mar 2016)

Video of my presentation can be found here: • https://engineers.sg/video/raspberry-pi-3-uart-bluetooth-issues--609

Page 2: Raspberry Pi 3 + UART/Bluetooth issues

2

Whats new? (Features)Specifications Raspberry Pi 2 Raspberry Pi 3

CPU BCM2836Cortex-A7900MhzARMv7

BCM2837Cortex-A531.2GhzARMv8 (64-bit)

GPU 250Mhz Videocore IV1080p,30FPS,H.264 video decoding

400Mhz Videocore IV 1080p,60FPS,H.264 video decoding

Wifi - 802.11n, 2.4Ghz only, single stream 150Mbps

Bluetooth - Bluetooth 4.1 (Dual-mode)Classic and BLE

http://raspi.tv/2016/raspberry-pi-3-model-b-launches-today-64-bit-quad-a53-1-2-ghz-bcm2837

Page 3: Raspberry Pi 3 + UART/Bluetooth issues

3

Whats new? (Board) Specifications Raspberry Pi 2 Raspberry Pi 3

LED positions Top left Bottom left

microSD storage Spring No Spring

Page 4: Raspberry Pi 3 + UART/Bluetooth issues

4

UART (Debug console) issues on RPi 3

Page 5: Raspberry Pi 3 + UART/Bluetooth issues

5

UART Debug Console

+

USB-TTL cablehttps://www.adafruit.com/product/954

• Universal asynchronous receiver/transmitter

Page 6: Raspberry Pi 3 + UART/Bluetooth issues

6

UART (Serial Debug console) issue

Received output. • Garbled or nothing• Output is 72000 instead of 115200 baud

Expected output

Page 7: Raspberry Pi 3 + UART/Bluetooth issues

7

Hardware architecture (≤ RPi 2)

System on Chip

BCM2835 (RPi 1 B/B+)/ BCM2836 (RPi 2)

• BCM283x has 2 UARTs• UART0: Full UART (/dev/ttyAMA0)

• Based on ARM Primecell PL011• Larger FIFO buffers

• 16x8 transmit• 16x12 receive

• High performance full feature serial port• Older RPi models breaks out UART0 to the pin header

• Default use: Debug console

• UART1: “mini UART” (/dev/ttyS0)

UART0

UART1

BCM2835 datasheet: Page 10https://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Page 8: Raspberry Pi 3 + UART/Bluetooth issues

8

System on Chip

BCM2837 (RPi 3)

Hardware architecture (RPi 3)

SDIO

BCM43438 wireless chip

http://raspi.tv/2016/raspberry-pi-3-model-b-launches-today-64-bit-quad-a53-1-2-ghz-bcm2837

Bluetooth 4.1Wifi

• UART0: Full UART (/dev/ttyAMA0)

• UART1: “mini UART” (/dev/ttyS0)

UART1

UART0

Page 9: Raspberry Pi 3 + UART/Bluetooth issues

9

Why is UART1 a problem?

BCM2835 datasheet: Page 10- 11https://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Note:I use BCM2835 datasheet as datasheets of newer chips have not been released by Broadcom.

Mini UART implementation should be the same across BCM283x.

Problem Explanation

• RPi 3 boot time core frequency is 400Mhz• RPI baud rate default 115200

• baudRateReg calculated on core frequency retrieved at boot time

• Frequency scaling, may drop to 250Mhz to save power under low load

• Fluctuating core frequency -> Fluctuating baud rate

Page 10: Raspberry Pi 3 + UART/Bluetooth issues

10

Who is affected?Anyone who uses the TX/RX header pins

• People who use the serial debug console• Headless systems

• RPi shields that uses the UART• Eg. RS232, GPS/GSM

• Device-Device communication to other MCUs or MPUs• Require high UART performance (aka full UART) and Bluetooth

Page 11: Raspberry Pi 3 + UART/Bluetooth issues

11

How do we solve this? Part (1/2)

Lock a constant core frequency during boot time

• (For old firmware) Add “core_freq=250” XOR “force_turbo=1” to /boot/config.txt• Lock core core_freq to minimum or maximum (400Mhz) respectively• Minimum -> RPi 3 performance will be affected.• Maximum -> Requires good cooling.

• Can still be throttled to 250 Mhz under low voltage or high temperature conditions

• (For new firmware) Add “enable_uart=1” to /boot/config.txt• All RPi distributions will eventually support this option going forward• Similar to “core_freq=250” with clearer intent• Raspbian latest stable updates does not support this yet

• Need bleeding-edge firmware update: “sudo apt-get install rpi-update” & “sudo rpi-update”• Arch Linux requires an update to use this option: Just use “pacman –Syu”• Distros that support this option will disable debug console if “enable_uart=1” is not set• “enable_uart=1” explanation Raspberry Pi Foundation Engineer Phil Elwell (pelwell)

• https://github.com/raspberrypi/firmware/issues/553#issuecomment-199486644

Page 12: Raspberry Pi 3 + UART/Bluetooth issues

12

How do we solve this? Part (2/2)Remap header pins to use Full UART with device tree overlay (pin-crossbar)• Add “dtoverlay=pi3-disable-bt” to /boot/config.txt

• Disables Bluetooth in the process as UART1 is unconnected• Requires extra “sudo systemctl disable hciuart” for Raspbian

• Or add “dtoverlay=pi3-miniuart-bt” to /boot/config.txt• Bluetooth now uses mini-UART• Need to add “core_freq=250” or “force_turbo=1” to

/boot/config.txt so Bluetooth via mini UART is usable• Edit “/lib/systemd/system/hciuart.service” and replace

“ttyAMA0” with “ttyS0” for Raspbian• Bluetooth’s performance will be affected. Only low-

throughput BLE may be effectively usable.

• If any of these options are used, the serial console will be enabled unless “enable_uart=0”

System on Chip

BCM2837 (RPi 3)

SDIO

BCM43438 wireless chip

Bluetooth 4.1Wifi

• UART0: Full UART (/dev/ttyAMA0)

• UART1: “mini UART” (/dev/ttyS0)

UART0

UART1

Page 13: Raspberry Pi 3 + UART/Bluetooth issues

13

Solution summarySet in /boot/config.txt• Serial console and normal Bluetooth

• Lock frequency• Old: “core_freq=250” XOR “force_turbo=1” • New: ”enable_uart=1”. Add “force_turbo=1” to lock at high frequency.

• High performance Serial• Switch UART0 and UART1 pins• No Bluetooth

• “dtoverlay=pi3-disable-bt” • (Raspbian) Run “sudo systemctl disable hciuart”

• Slow Bluetooth Classic or BLE• “dtoverlay=pi3-miniuart-bt” AND (“core_freq=250” XOR “force_turbo=1”)• (Raspbian) Edit “/lib/systemd/system/hciuart.service” and replace “ttyAMA0” with “ttyS0”

• Add “enable_uart=0” to disable debug console

• The use of the mini UART will always require locking of Core frequency

Page 14: Raspberry Pi 3 + UART/Bluetooth issues

14

Arch Linux Bluetooth’s issues

• Raspbian uses “pi-bluetooth” to provide Bluetooth features

• “pi-bluetooth” has not been ported to Arch Linux

• Someone has posted a temporary package to AUR• https://archlinuxarm.org/forum/viewtopic.php?f=67&t=10017s• https://aur.archlinux.org/packages/pi-bluetooth/

• My setup instructions using that package• https://gist.github.com/yeokm1/d6c3ca927919c61257cd

Page 15: Raspberry Pi 3 + UART/Bluetooth issues

15

Useful links1. BCM2835 datasheet: https://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

2. Original Github issue: https://github.com/raspberrypi/firmware/issues/553

3. “enable_uart=1” explanation by Raspberry Pi Foundation Engineer Phil Elwellhttps://github.com/raspberrypi/firmware/issues/553#issuecomment-199486644

4. UART DT overlays: http://www.briandorey.com/post/Raspberry-Pi-3-UART-Boot-Overlay-Part-Two

5. Detailed DT overlays: https://github.com/raspberrypi/linux/blob/rpi-4.1.y/arch/arm/boot/dts/overlays/README

6. Arch Linux ARM Bluetooth forum issue thread: https://archlinuxarm.org/forum/viewtopic.php?f=65&t=9961

7. Instructions to enable Arch Linux Bluetooth: https://gist.github.com/yeokm1/d6c3ca927919c61257cd