You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu下将串口设置为PIO模式(非DMA)并验证状态

Forcing PIO Mode on Intel 16550A Serial Port (/dev/ttyS0) on Ubuntu

Let’s work through this step by step—your need for high-deterministic parity error detection means locking your serial port into PIO mode is critical, so let’s clear up the confusion and get you sorted.

First: Fix the Driver Parameter Misconception

The fsl_lpuart.nodma parameter you came across is designed for Freescale/NXP LPUART controllers, not the Intel 16550A integrated serial port in your Lenovo V520S. Your port uses the standard 8250/serial kernel driver (the go-to for legacy UARTs like 16550A), so that parameter won’t have any effect here.

Checking Current DMA/PIO State

Since setserial and stty don’t expose DMA status, use these reliable methods to check your port’s current mode:

  • Kernel Log Check: Run dmesg | grep -i ttyS0 and scan for lines mentioning DMA or PIO. For example, you might see [ 0.123456] 00:06: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A—if DMA was enabled, it would explicitly state using DMA.
  • Proc Filesystem Check: Run cat /proc/tty/driver/serial to get detailed serial port stats. Look for the line for ttyS0; the flags field will show if DMA is active (a flag like 0x2000 means DMA is enabled, its absence confirms PIO mode). Example snippet:
    serinfo:1.0 driver revision:
    0: uart:16550A port:000003F8 irq:4 tx:0 rx:0 flags:0x100000
    
  • Sysfs Check: Some kernel versions expose DMA status via sysfs: cat /sys/class/tty/ttyS0/device/dma_enabled—a value of 0 means PIO mode, 1 means DMA is active.

Forcing PIO Mode (Disabling DMA)

Use one of these methods to lock your port into PIO mode:

1. Kernel Boot Parameter (Temporary or Permanent)

Your Intel system uses GRUB (not U-Boot, where setenv defargs is used), so here’s how to set the correct kernel parameter:

  • Temporary Test: Reboot, press Esc to bring up the GRUB menu, select your Ubuntu entry, press e to edit the boot command. Find the line starting with linux, add 8250.nodma=1 to the end, then press F10 to boot. This disables DMA for all 8250-based serial ports. If you only want to target ttyS0, use 8250.nodma=0x1 (bit 0 maps to the first serial port).
  • Permanent Setting: Edit /etc/default/grub with your preferred text editor, find either GRUB_CMDLINE_LINUX_DEFAULT or GRUB_CMDLINE_LINUX, add 8250.nodma=1 inside the quoted string. For example:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash 8250.nodma=1"
    
    Save the file, run sudo update-grub, then reboot. The setting will persist across reboots.

2. Module Parameter (If 8250 is Loaded as a Module)

If the 8250 driver is loaded as a kernel module (check with lsmod | grep 8250), you can set the parameter at load time:

  • One-Time Load: Run sudo modprobe -r 8250 && sudo modprobe 8250 nodma=1
  • Permanent Module Setting: Create a file /etc/modprobe.d/8250.conf with this line:
    options 8250 nodma=1
    
    Reboot, and the module will load with DMA disabled by default.

3. Runtime Sysfs Toggle (If Supported)

Some newer kernels let you toggle DMA at runtime:

sudo echo 0 > /sys/class/tty/ttyS0/device/dma_enabled

Note: This setting won’t survive a reboot unless you add it to a startup script (like /etc/rc.local or a systemd service).

Verifying PIO Mode is Active

After applying any of the above, re-run the checks from the "Checking Current DMA/PIO State" section to confirm DMA is disabled. For your parity error detection use case, PIO mode will give you the deterministic byte-by-byte processing you need—avoiding the batch-transfer delays and potential detection gaps that can come with DMA.

内容的提问来源于stack exchange,提问作者Luis Alvarado Day

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:34:16