W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之 UART 篇

近期閱讀 Brian Dorey 上的一篇文章︰

Raspberry Pi 3 UART Overlay Workaround

Monday 07 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(n) 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.

【※ 400MHz / 250MHz = 1.6 ?】

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.

───

 

不得不令人想起

春雷早發︰樹莓派 2 Model B ︰拍照害羞篇?!》之事︰

杜甫‧空囊

翠柏苦猶食,晨霞高可餐。
世人共鹵莽,吾道屬艱難。
不爨井晨凍,無衣床夜寒。
囊空恐羞澀,留得一錢看。

hG86pRyl
閃光燈殭死症?!

B9Ut_QwIQAACrp_
都是 U16 惹的禍??

180px-Actual_blu_tack
來點 寶貼吧!!

忘了當年是誰說的『 PC 沒有不當機的??』,否則要『 RESET 開關幹嘛!!』。為了多了解『 RPI 2 』,閱讀了『樹莓派論壇』,驚訝《 Why is the PI2 camera-shy ? 》一段討論!ㄚˊ!拍照會當機光過敏 ??解決方法是『用寶貼』或『 Sugru 』???作者寫這篇文章的時候,『討論』依然進行中,看來會有更多的人參與的吧!!

作者認為聽到『剛買的新東西有瑕疵』,大概總會『高興不起來』的。如果已經知道『問題是什麼』,也有了『解決的方法』,那麼『感性』與『理性』的交匯處,或許落在『合理性』之上的吧!畢竟一般的使用上 ── 比方說,裝在外殼裡 ──,大體也遇不著這個問題,何不『放下議論』向前行呢?

───

 

那ㄟㄚㄋㄟ˙??這將會影響很多 UART 界面之裝置!!而且所謂『 WORKAROUND 』總叫人覺得『ㄑㄇ氣』不好!!??為什麼『 mini-uart 』會少了一個『時鐘』??!!這樹莓派基金會當真是︰每有新品,驚嚇連連!!!果然應了古話︰

人無遠慮,必有近憂。

好事不出門,壞事傳千里。

 

既已無力回天,心想何不『降頻、共存』以求其次,豈料那篇大作的這個部份資訊,偏偏又已過時︰

Raspberry Pi 3 – Bluetooth PL011 UART (9bit on mini-UART)?

by steaky1212 » Tue Mar 01, 2016 9:20 am

Hi,

I saw a brief comment on the forum (The Raspberry Pi 3 Model B Q&A thread) that the new Bluetooth module uses the PL011 UART and the GPIO header will be using Broadcom’s mini-UART instead. Is this the case?

I have a project where I needed a 9-bit UART and so was modifying the parity bit (mark/space/one/zero) on an 8bit UART to get this to work. As the mini-UART is not fully 16550 compliant (and doesn’t have a parity bit), then this will not work.

Am I correct in all of this? And if so then how do I get a fully functioning UART on the RPi3 (FTDI chips are not an option)?

Thanks in advance,
Steaky

……

by PhilE » Fri Mar 11, 2016 7:06 pm
Change the serial1 in cmdline.txt to serial0. (That use of serial1 was a short-lived special needed when the miniuart overlay was first added – with the latest firmware it is no longer necessary, and serial0 is always the non-BT uart).

───

 

真真是子曰:

不曰『如之何,如之何』者,吾末如之何也已矣。

 

終究人非聖賢,孰能無過?自錯誤中學習,也是重要的方法???此時看來『嘗試錯誤』、『與時偕行』誠有大用哉!!!

於是乎查閱

rpi-firmware/overlays/README

# line 478
Name: pi3-disable-bt
Info: Disable Pi3 Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15
      N.B. To disable the systemd service that initialises the modem so it
      doesn't use the UART, use 'sudo systemctl disable hciuart'.
Load: dtoverlay=pi3-disable-bt
Params: <None>

Name: pi3-miniuart-bt
Info: Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore
      UART0/ttyAMA0 over GPIOs 14 & 15. Note that this may reduce the maximum usable baudrate.
      N.B. It is also necessary to edit /lib/systemd/system/hciuart.server and replace ttyAMA0 with ttyS0.
Load: dtoverlay=pi3-miniuart-bt
Params: <None>

 

循言修改

【 /boot/cmdline.txt 】

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

 

以及

【 /boot/config.txt 】

# UART issues
dtoverlay=pi3-miniuart-bt
core_freq=250

 

同時更正

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

[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionPathIsDirectory=/proc/device-tree/soc/gpio@7e200000/bt_pins
Before=bluetooth.service
After=dev-ttyS0.device

[Service]
Type=forking
ExecStart=/usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow -

[Install]
WantedBy=multi-user.target

 

重新開機後,果然

pi@raspberrypi ~ dmesg | grep tty [    0.000000] Kernel command line: 8250.nr_uarts=1 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2709.boardrev=0xa02082 bcm2709.serial=0x5d898162 smsc95xx.macaddr=B8:27:EB:89:81:62 bcm2708_fb.fbswap=1 bcm2709.uart_clock=48000000 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200  console=tty1 root=/dev/mmcblk0p2 kgdboc=ttyAMA0,115200 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait [    0.001294] console [tty1] enabled [    0.305856] 3f215040.uart: ttyS0 at MMIO 0x3f215040 (irq = 29, base_baud = 31250000) is a 16550 [    1.045876] 3f201000.uart: ttyAMA0 at MMIO 0x3f201000 (irq = 83, base_baud = 0) is a PL011 rev2 [    2.298521] console [ttyAMA0] enabled [    3.771052] systemd[1]: Expecting device dev-ttyAMA0.device... [    4.308291] systemd[1]: Starting system-serial\x2dgetty.slice. [    4.326669] systemd[1]: Created slice system-serial\x2dgetty.slice. [    6.160579] usb 1-1.4: pl2303 converter now attached to ttyUSB0 pi@raspberrypi ~

 

pi@raspberrypi ~ sudo systemctl status hciuart ● hciuart.service - Configure Bluetooth Modems connected by UART    Loaded: loaded (/lib/systemd/system/hciuart.service; enabled)    Active: active (running) since 六 2016-03-12 19:15:23 CST; 2min 36s ago   Process: 453 ExecStart=/usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow - (code=exited, status=0/SUCCESS)  Main PID: 1009 (hciattach)    CGroup: /system.slice/hciuart.service            └─1009 /usr/bin/hciattach /dev/ttyS0 bcm43xx 115200 noflow -   3月 12 19:15:23 raspberrypi hciattach[453]: bcm43xx_init  3月 12 19:15:23 raspberrypi hciattach[453]: Flash firmware /lib/firmware/BCM43430A1.hcd  3月 12 19:15:23 raspberrypi hciattach[453]: Set Controller UART speed to 115200 bit/s  3月 12 19:15:23 raspberrypi hciattach[453]: Device setup complete  3月 12 19:15:23 raspberrypi systemd[1]: Started Configure Bluetooth Modems connected by UART. pi@raspberrypi ~ 

 

OK 的矣。再依

 

將 USB TTL Serial Loopback 』串回樹莓派︰

  • The red lead should be connected to 5V,
  • The black lead to GND,
  • The white lead to TXD.
  • The green lead to RXD.

Check the diagram below if you are not sure about the connections. But note that the connect is being viewed upside down, so rotate the diagram by 180 degrees to compare it with the photograph.

 


pi@raspberrypi ~ $ sudo screen /dev/ttyUSB0 115200

指令驗證 PL011 UART ︰

pi@raspberrypi: ~_ttyAMA0

 

幸好一切正常的耶!!!

 

 

 

 

 

 

 

 

 

 

 

 

在〈W!o+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之 UART 篇〉中有 1 則留言

留言功能已關閉。