在 OpenWrt 更改 UART 串口波特率

相关文档:

我看到论坛上有很多问题询问 “如何更改串口速率” ,以为很简单,但一点也不简单。

OpenWrt 通过内核命令行参数设置 UART 串口波特率,因此它是硬编码到内核中的,据我所知,这是更改串口波特率的唯一方法。

如果你运气好,也许你的内核支持更改串口速率,那么你可以尝试使用 sttymgetty 命令:

mgetty -s 19200 /dev/ttyS0 

或者

stty -F /dev/ttyS0 9600 clocal cread cs8 -cstopb -parenb 

要读取串口设置,使用:

stty -F /dev/ttyS0 -a 

在最近的版本中,你可以通过以下方式轻松从软件包安装 stty:

opkg update
opkg install coreutils-stty

你可以在 menuconfig 中的以下位置找到 stty

Base system -> busybox -> Coreutils -> stty

例如,TP-Link WR741ND V4.x的默认设置为: “console=ttyATH0,115200”

现在的问题是如何更改这个内核命令行参数,目前唯一的方法是自行编译一个带有不同 “console=” 参数的内核。

首先你需要知道需要设置哪个波特率。 在这个例子中,我们使用 TP-LINK WR741ND,它的 UART 串口波特率设置为 115200,我们需要将其更改为 19200。

首先检查你当前路由器使用的波特率和端口,通过 telnet 或 ssh 登录到你的路由器,然后找出当前的设置。通常 UART 串口是 ttyS0ttyATH0

使用以下命令检查你的串口设置:

  • fw_printenv
    • baudrate=115200
    • console=console=ttyS0,115200
  • 或: logread | grep tty
    • ...

找到你的配置文件位置:

  • grep ttyATH0 ./trunk/target/linux/ar71xx/ -R

building 你自己的镜像之前编辑文件:

  • ./trunk/target/linux/ar71xx/image/Makefile

找到你的调制解调器对应的行:

  • tlwr740_cmdline=board=TL-WR741ND console=ttyS0,115200
  • tlwr740v4_cmdline=board=TL-WR741ND-v4 console=ttyATH0,115200

将 “console=ttyATH0,115200” 更改为你需要的速度:

  • tlwr740_cmdline=board=TL-WR741ND console=ttyS0,19200
  • tlwr740v4_cmdline=board=TL-WR741ND-v4 console=ttyATH0,19200

你可以通过 kernel_menuconfig 直接修改内核命令行:

  • kernel_menuconfig > Kernel hacking > Default kernel command string

然后你需要使用 'make target/clean world' 重新编译内核并重新刷写固件。

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2025/10/24 10:09
  • by starsfall