我使用的是 Raspberry Pi 4 (8G) 版本。以前通过 serial0 与 Pixhawk 通信时,它工作得很好。但几个月前,我将操作系统从 Ubuntu 16 Ubiquity 更改为 Ubuntu Mate 20。其他功能运行良好,但当我尝试使用 serial0 连接到 Pixhawk 时,我发现 serial0 不存在。我在网上做了一些研究,发现一些用户在使用 RPi3 和 4 时遇到了类似的 serial0 禁用问题。我尝试使用他们提到的一些脚本和一些步骤来更改 config.txt 相关文件,但它们都不适合我。我遵循的主要步骤如下 在 Pi4 Ubuntu 20.04 上启用 UART 通信
我注意到 dmesg 信息有一些不同:它应该有三行:
$ dmesg | grep tty
[ 0.001061] printk: console [tty0] enabled
[ 1.919367] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 29, base_baud = 0) is a PL011 rev2
[ 1.924677] fe215040.serial: ttyS0 at MMIO 0x0 (irq = 31, base_baud = 62500000) is a 16550
但是我的 RPi 只有两行:
ubuntu@ubuntu-desktop:~$ dmesg | grep tty
[ 0.000245] printk: console [tty0] enabled
[ 1.412273] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 14, base_baud = 0) is a PL011 rev2
ubuntu@ubuntu-desktop:~$ mavproxy.py --master=/dev/ttyS0,921600
Connect /dev/ttyS0,921600 source_system=255
Failed to connect to /dev/ttyS0,921600 : [Errno 2] could not open port /dev/ttyS0: [Errno 2] No such file or directory: '/dev/ttyS0'
因此,看起来 ttyS0 已被禁用。您认为它与内核命令行“8250.nr_uarts = 0”有关系吗?
ubuntu@ubuntu-desktop:~$ dmesg | grep uart
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 smsc95xx.macaddr=DC:A6:32:B2:AD:BF vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 net.ifnames=0 dwc_otg.lpm_enable=0 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc quiet splash quiet splash
相关文件如下:
ubuntu@ubuntu-desktop:~$ cat /boot/firmware/config.txt
# Please DO NOT modify this file; if you need to modify the boot config, the
# "usercfg.txt" file is the place to include user changes. Please refer to
# the README file for a description of the various configuration files on
# the boot partition.
# The unusual ordering below is deliberate; older firmwares (in particular the
# version initially shipped with bionic) don't understand the conditional
# [sections] below and simply ignore them. The Pi4 doesn't boot at all with
# firmwares this old so it's safe to place at the top. Of the Pi2 and Pi3, the
# Pi3 uboot happens to work happily on the Pi2, so it needs to go at the bottom
# to support old firmwares.
[pi4]
kernel=uboot_rpi_4.bin
max_framebuffers=2
[pi2]
kernel=uboot_rpi_2.bin
[pi3]
kernel=uboot_rpi_3.bin
[all]
arm_64bit=1
device_tree_address=0x03000000
# The following settings are "defaults" expected to be overridden by the
# included configuration. The only reason they are included is, again, to
# support old firmwares which don't understand the "include" command.
# enable_uart=1
cmdline=cmdline.txt
include syscfg.txt
include usercfg.txt
# Enable the FKMS ("Fake" KMS) graphics overlay, enable the camera firmware
# and allocate 128Mb to the GPU memory
dtoverlay=vc4-fkms-v3d
gpu_mem=128
start_x=1
# Comment out the following line if the edges of the desktop appear outside
# the edges of your display
disable_overscan=1
# If you have issues with audio, you may try uncommenting the following line
# which forces the HDMI output into HDMI mode instead of DVI (which doesn't
# support audio output)
#hdmi_drive=2
# If you have a CM4, uncomment the following line to enable the USB2 outputs
# on the IO board (assuming your CM4 is plugged into such a board)
#dtoverlay=dwc2,dr_mode=host
ubuntu@ubuntu-desktop:~$ cat /boot/firmware/usercfg.txt
# Place "config.txt" changes (dtparam, dtoverlay, disable_overscan, etc.) in
# this file. Please refer to the README file for a description of the various
# configuration files on the boot partition.
ubuntu@ubuntu-desktop:~$ cat /boot/firmware/README
An overview of the files on the /boot/firmware partition (the 1st partition
on the SD card) used by the Ubuntu boot process (roughly in order) is as
follows:
* bootcode.bin - this is the second stage bootloader loaded by all pis with
the exception of the pi4 (where this is replaced by flash
memory)
* config.txt - the first configuration file read by the boot process
* syscfg.txt - the file in which system modified configuration will be
placed, included by config.txt
* usercfg.txt - the file in which user modified configuration should be
placed, included by config.txt
* start*.elf - the third stage bootloader, which handles device-tree
modification and which loads...
* uboot*.bin - various u-boot binaries for different pi platforms; these
are launched as the "kernel" by config.txt
* boot.scr - the boot script executed by uboot*.bin which in turn
loads...
* vmlinuz - the Linux kernel, executed by boot.scr
* initrd.img - the initramfs, executed by boot.scr
ubuntu@ubuntu-desktop:~$ cat /boot/firmware/syscfg.txt
# This file is intended to be modified by the pibootctl utility. User
# configuration changes should be placed in "usercfg.txt". Please refer to the
# README file for a description of the various configuration files on the boot
# partition.
enable_uart=0
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on
cmdline=cmdline.txt
我还尝试将 /boot/firmware/syscfg.txt 中的 enable_uart=0 更改为 1。之后,系统无法启动,这表明该文件确实影响了系统。然后我把文件改回来,系统正常启动。
ubuntu@ubuntu-desktop:~$ cat /boot/firmware/cmdline.txt
net.ifnames=0 dwc_otg.lpm_enable=0 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc quiet splash
ubuntu@ubuntu-desktop:~$ sudo systemctl status [email protected]
● [email protected]
Loaded: masked (Reason: Unit [email protected] is masked.)
Active: inactive (dead)
ubuntu@ubuntu-desktop:~$ groups
ubuntu adm tty dialout cdrom sudo dip video plugdev input lxd lpadmin sambashare spi i2c gpio
但 UART 仍然未启用。如果有人能提供一些建议,我将不胜感激。
答案1
通过安装 Ubuntu 20 Ubiquity 解决了这个问题。即使它是一个测试版,对我来说也很有用。看来他们在 Linux 内核配置方面做了一些工作,使这些物理端口运行良好。