使用串口登录Ubuntu

By | 2019-09-06

电脑硬件:QOTOM Q300P[ubuntu],Q600P[windows10]

Windows串口使用COM4

Ubuntu串口使用第一个/dev/ttyS0,115200 baud 8n1

配置Grub

  • 编辑/etc/default/grub并添加以下代码:
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
  • 修改完成后的代码:
 ...
 GRUB_DEFAULT=0
 #GRUB_TIMEOUT_STYLE=hidden
 GRUB_TIMEOUT=5
 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
 #GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
 GRUB_CMDLINE_LINUX_DEFAULT=""
 GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200"

 # Uncomment to enable BadRAM filtering, modify to suit your needs
 # This works with Linux (no patch required) and with any kernel that obtains
 # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
 #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

 # Uncomment to disable graphical terminal (grub-pc only)
 GRUB_TERMINAL="console serial"
 GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
 ...
  • 更新grub
sudo update-grub 或 sudo grub-mkconfig -o /boot/grub/grub.cfg

修改ttyS0配置文件

  • 添加ttyS0配置 (如果上面的方法无效就试试)
vim /ect/init/ttyS0.conf
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 115200 ttyS0 vt100

WIN10测试结果

使用putty进行串口连接

serial console

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注