Linux上通过串口连接嵌入式Linux终端

1. 安装 minicom

Debian/Ubuntu:

sudo aptitude update
sudo aptitude install minicom

2. 插上设备并查看系统是否已经检测到设备

sudo dmesg | grep tty

如果没有检测到设备,得到的结果类似:

[    0.000000] console [tty0] enabled
[    8.264501] systemd[1]: Created slice system-getty.slice.
  • 拔下usb转串口线,输入命令 lsusb会看到一些已经连接到usb的设备:

    Bus 002 Device 002: ID 8087:8000 Intel Corp. 
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 8087:8008 Intel Corp. 
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 004: ID 13d3:5188 IMC Networks 
    Bus 003 Device 006: ID 13d3:3402 IMC Networks  
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    
  • 再次插上usb转串口线,再次运行命令 lsusb,会看到输出结果相比之前增加了一行:

    Bus 002 Device 002: ID 8087:8000 Intel Corp. 
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 8087:8008 Intel Corp. 
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 004: ID 13d3:5188 IMC Networks 
    Bus 003 Device 006: ID 13d3:3402 IMC Networks 
    Bus 003 Device 008: ID 18f8:0f99 --- --- --- (注意这行是新加的!)
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    
  • 现在我们知道了usb转串口的 vendor idproduct id,让我们加载Linux内核的usbserial模块来激活这个设备:

  sudo modprobe usbserial vendor=0x18f8 product=0x0f99 
  • 再次运行 dmesg 命令,输出结果类似:

    usbserial_generic 1-1:1.0: generic converter detected
    usb 1-1: generic converter now attached to ttyUSB0
    usbcore: registered new interface driver usbserial_generic 
    

可以把自动加载usbserial模块添加到开机启动里,编辑文件/etc/modules,添加一行:

  usbserial vendor=0x18f8 product=0x0f99

3. 连接到设备

假设设备路径为 /dev/ttyUSB0,运行命令:

sudo minicom -s

Serial port setup里修改第一行为/dev/ttyUSB0

选择Save setup as dfl保存设置

上一页
下一页