Back to Raspberry Pi Taiwan

【教學/基礎】使用 Debug Probe 從序列埠登入 Raspberry Pi 5 | 2024 年最新教學

Last Updated on 2024 年 3 月 15 日 by 小編

使用 Raspberry Pi Debug Probe 和 Raspberry Pi 5 相接
使用 Raspberry Pi Debug Probe 和 Raspberry Pi 5 相接

Raspberry Pi 5 專用的 UART 接頭

Raspberry Pi 5 專用 UART 接頭

Raspberry Pi 5 特色之一是有專用的 UART 接頭,這對於不使用鍵盤滑鼠登入(headless)的開發者是一大福音~

如何從序列埠登入 Raspberry Pi 5?

硬體需要使用 Raspberry Pi Debug Probe,一端連接 Raspberry Pi 5 的專用 UART 接頭,另一端和電腦 USB 相接,再透過終端機軟體(例如 Windows 使用 MobaXterm、Linux 使用 PuTTY、Mac 使用 screen)就可以登入到 Raspberry Pi 5。

從序列埠登入 Raspberry Pi 5 所需硬體

從序列埠登入 Pi 5 所需硬體(Raspberry Pi Debug Probe)
從序列埠登入 Pi 5 所需硬體(Raspberry Pi Debug Probe)

購買 Raspberry Pi Debug Probe 將內含以下三項所需硬體,購買連結

  • Raspberry Pi Debug Probe(含塑膠外殼)x1
  • Raspberry Pi USB microB Cable(一米)x1
  • 3-pin JST 接頭轉 3-pin JST 接頭(15cm)x1

Raspberry Pi Debug Probe 接線

3-pin JST 轉接線要接到 Debug Probe 上方有標示 UART 的位置才是正確的,如下圖左邊。

Debug Probe 接線

使用 Raspberry Pi Debug Probe 和 Raspberry Pi 5 相接

從序列埠登入 Raspberry Pi 5 軟體設定

Windows 設定

1. 接上 Debug Probe 以後的裝置管理員列表,出現新的 COM 裝置(本例為 COM3

"Windows 接上 Debug Probe 時的裝置管理員列表,出現新的 COM 裝置

2. 下載、安裝、開啟 MobaXterm

Windows 開啟 MobaXterm

3. 選擇裝置管理員顯示的序列埠號(本例為 COM3),Speed 填入 115200
選擇正確的序列埠和適合的 Speed

4. 連上 Raspberry Pi 如下圖。如果等了幾秒還是沒有畫面,可將 Raspberry Pi 重開(電源重插拔)就可以順利看到登入訊息。

Windows 透過 Debug Probe 登入到 Raspberry Pi 5

 

Ubuntu/Linux 設定

1. 接上 Debug Probe 之後,在終端機上打 ls /dev/ttyACM* 會出現新的裝置節點例如 /dev/ttyACM0

新的裝置節點 /dev/ttyACM0

2. 開啟 PuTTY,在 Connection type 先選擇 Serial,再根據剛剛的連接埠依序填入 Serial lineSpeed 的值。由於該節點是長在 ttyACM0,因此在 Serial line 也填入 ttyACM0Speed 填入 115200

PuTTY 在 Linux 的設定

3. 如果出現 Unable to open serial port 如下圖,改用 sudo 權限執行 PuTTY。

無法開啟序列埠

4. 相關的參數填完後,按 “Open” 將能連上 Raspberry Pi 如下圖。如果畫面沒顯示任何文字,可將電源重插拔後就可以看到開機訊息。

Ubuntu 從 UART 登入 Raspberry Pi 5

MacOS 設定

1. 在終端機輸入 ls /dev/tty.usbmodem*,如果出現 /dev/tty.usbmodem 後面可能有數字或是沒數字(例如畫面如下,本例為 /dev/tty.usbmodem13402)。

在 Mac 的終端機執行 ls /dev/tty.usbmodem*

2. 使用指令 screen 連線進去,baudrate 使用 115200(畫面如下,本例為 screen /dev/tty.usbmodem13402 115200

在 Mac 的終端機執行 screen /dev/tty.usbmodem 115200

3. 如果出現 Cannot open line ‘/dev/tty.usbmodem’; for R/W: Resource busy 錯誤訊息,可以將連接到 Mac 的 USB 傳輸線拔掉再重新插回,之後再重新執行一次 screen 指令即可。

如果出現 Cannot open line '/dev/tty.usbmodem' for R/W: Resource busy 錯誤訊息

4. 使用 screen 連線成功後就可以順利看到登入訊息如下圖。

dd

5. 如果使用 screen 後沒畫面出現(一片空白),可以重新插拔 Raspberry Pi 的電源試試看(Debug Probe 接到 Mac 的 USB 不要拔掉)

備註:在 Mac 環境除了使用 screen 以外,還可以使用 CoolTerm 連線。

補充:使用序列埠登入 Raspberry Pi 4B 以前的版本

使用 PL2303 接 Raspberry Pi 4/3B+/3B/2/1/Zero/Zero2

在 Raspberry Pi 5 之前的型號,如果需要 從序列埠登入到 Raspberry Pi,可以使用 USB 轉 TTL 序列埠傳輸線(例如 PL2303HXD)接到 Pin 6(Ground)、Pin 8(UART0_TX)、Pin 10(UART0_RX)如下圖,再使用終端機透過序列埠連線登入。

使用 USB 轉 TTL 序列埠傳輸線接線圖

使用 Debug Probe 接 Raspberry Pi 4/3B+/3B/2/1/Zero/Zero2

除了使用 PL2303HXD 這類的 USB 轉 TTL 序列埠傳輸線以外,也可以使用 Raspberry Pi Debug Probe 和 Raspberry Pi 相接。接線方式為 Debug Probe 的黑色線(GND)接到 Pin 6(Ground)、黃色線(RX)接到 Pin 8(UART0_TX)、橙色線(TX)接到 Pin 10(UART0_RX)如下圖。

使用 Debug Probe 接到 Raspberry Pi 4/3B+/3B/2 系列

但是從 Pi 3B 開始,因為增加 CYW43438(原 BCM43438)WiFi/Bluetooth 晶片,其中藍牙使用 UART0 (/dev/ttyAMA0),因此 Raspbian 或是 Raspberry Pi OS 系統預設會將 /dev/ttyAMA0 保留給藍牙。因此我們想從樹莓派的序列埠登入的話,可以有以下兩種方法:

方法 1

使用 Raspbian 或是 Raspberry Pi OS 提供的 raspi-config 工具,從 3 Interface Options > I5 Serial Port > <Yes>,重開機以後將可以從序列埠登入。

raspi-config > 3 Interface Options

raspi-config > 3 Interface Options > I5 Serial Port

raspi-config > 3 Interface Options > I5 Serial Port > Yes

Reboot Raspberry Pi

方法 2

手動修改 /boot/config.txt/boot/cmdline.txt 如下。

1. 設定 /boot/config.txt,在最下方加上以下幾行:

core_freq=250
enable_uart=1
dtoverlay=pi3-miniuart-bt

備註:dtoverlay=pi3-miniuart-bt 可以加,也可以不加。如果加的話,就可以同時使用 Serial 登入,也可以同時使用藍牙功能

2. 修改 /boot/cmdline.txt,將

console=tty1 root=PARTUUID=XXXXXXXX-XX rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait splash plymouth.ignore-serial-consoles 

前面新增 console=serial0,115200 ,重新開機後生效。

console=serial0,115200 console=tty1 root=PARTUUID=XXXXXXXX-XX rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait splash plymouth.ignore-serial-consoles

參考資料

馬上購買 Raspberry Pi Debug Probe

👉👉👉 馬上報名 Raspberry Pi 5 體驗會(10/30) 👈👈👈
👉👉👉 Raspberry Pi 5 Model B 購買點我 👈👈👈

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

Back to Raspberry Pi Taiwan
has been added to your cart.
Checkout