1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi 5 の GPIO14/15を UART(/dev/ttyAMA0) として扱う設定

Last updated at Posted at 2024-06-03

確認環境: Raspberry Pi 5 (8GB) + bookworm

有効化
sudo raspi-config nonint do_serial_hw 0
sudo raspi-config nonint do_serial_cons 1
sudo systemctl reboot
再起動後のチェック
# ttyAMA0 デバイス認識の確認
$ dmesg | grep ttyAMA
[    0.010493] 107d001000.serial: ttyAMA10 at MMIO 0x107d001000 (irq = 15, base_baud = 0) is a PL011 rev2
[    0.530390] 1f00030000.serial: ttyAMA0 at MMIO 0x1f00030000 (irq = 125, base_baud = 0) is a PL011 AXI

# /dev/ttyAMA0 の存在の確認
$ ls -lF /dev/ttyAMA*
crw-rw---- 1 root dialout 204, 64 Jun  3 21:38 /dev/ttyAMA0
crw-rw---- 1 root dialout 204, 74 Jun  3 21:38 /dev/ttyAMA10

# GPIO14, GPIO15 の状態
$ pinctrl get 14-15
14: a4    pn | hi // GPIO14 = TXD0
15: a4    pu | hi // GPIO15 = RXD0
/dev/ttyAMA0の使用
screen /dev/ttyAMA0 9600
cu -l /dev/ttyAMA0 -s 9600

raspi-config が行っていること

raspi-config は実際のところ、 config.txtcmdline.txt を編集しているだけです。

do_serial_hw 0 の結果
$ sudo diff -u ./config.txt.orig /boot/firmware/config.txt
--- ./config.txt.orig   2024-06-03 21:32:55.159999986 +0900
+++ /boot/firmware/config.txt   2024-06-03 21:35:36.000000000 +0900
@@ -46,3 +46,4 @@
 otg_mode=1

 [all]
+dtparam=uart0=on
do_serial_cons 1 の結果
$ sudo diff -u ./cmdline.txt.orig /boot/firmware/cmdline.txt
--- ./cmdline.txt.orig  2024-06-03 21:32:59.519999983 +0900
+++ /boot/firmware/cmdline.txt  2024-06-03 21:35:40.000000000 +0900
@@ -1 +1 @@
-console=serial0,115200 console=tty1 root=PARTUUID=dcb19b3b-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=JP
\ No newline at end of file
+console=tty1 root=PARTUUID=dcb19b3b-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=JP
\ No newline at end of file

戻し方

sudo raspi-config nonint do_serial_hw 1
sudo raspi-config nonint do_serial_cons 0
sudo systemctl reboot

解説

TODO: これでなぜ /dev/ttyAMA0 ができて動くのかは、後日書く

あとがきと参考情報

EoT

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?