Skip to content

system: Add stty utility for terminal control - #3724

Merged
acassis merged 1 commit into
apache:masterfrom
fangpeina:stty
Aug 14, 2026
Merged

system: Add stty utility for terminal control#3724
acassis merged 1 commit into
apache:masterfrom
fangpeina:stty

Conversation

@fangpeina

Copy link
Copy Markdown
Contributor

Summary

Add a stty command to NuttX, providing a standard Unix-like interface for
viewing and configuring terminal (TTY) device settings at runtime via termios.

Impact

  • Features: Adds stty utility for runtime terminal configuration
  • User Experience: Users can inspect and modify TTY settings from NSH
  • Build: No build system changes; new CONFIG_SYSTEM_STTY option, depends on CONFIG_SERIAL_TERMIOS

Testing

Testing on sim, qemu and physical device.

Configuration:

  • Board: sim:nsh (Linux host)
  • Config: CONFIG_SIM_UART_NUMBER=1, CONFIG_SIM_UART_PTY=y, CONFIG_SERIAL_TERMIOS=y, CONFIG_SYSTEM_STTY=y

Runtime Test Results(sim):

nsh> stty -F /dev/ttySIM0
/dev/ttySIM0 connected to pseudotty: /dev/pts/31
Terminal settings for /dev/ttySIM0:
  speed unknown or not supported by driver; min = 1; time = 0;
  c_iflag: 0x00000000 -icrnl -igncr -inlcr
  c_oflag: 0x00000000 -opost -onlcr -ocrnl
  c_lflag: 0x00000000 -echo -icanon -isig
  c_cflag: 0x000000bf -clocal cread -cstopb
nsh> stty -F /dev/ttySIM0 cooked
/dev/ttySIM0 connected to pseudotty: /dev/pts/31
Settings applied to /dev/ttySIM0
nsh> stty -F /dev/ttySIM0
/dev/ttySIM0 connected to pseudotty: /dev/pts/31
Terminal settings for /dev/ttySIM0:
  speed unknown or not supported by driver; min = 1; time = 0;
  c_iflag: 0x00000100 icrnl -igncr -inlcr
  c_oflag: 0x00000005 opost onlcr -ocrnl
  c_lflag: 0x0000000b echo icanon isig
  c_cflag: 0x000000bf -clocal cread -cstopb
nsh> stty -F /dev/ttySIM0 raw -echo
/dev/ttySIM0 connected to pseudotty: /dev/pts/31
Settings applied to /dev/ttySIM0
nsh> stty -F /dev/ttySIM0
/dev/ttySIM0 connected to pseudotty: /dev/pts/31
Terminal settings for /dev/ttySIM0:
  speed unknown or not supported by driver; min = 1; time = 0;
  c_iflag: 0x00000000 -icrnl -igncr -inlcr
  c_oflag: 0x00000004 -opost onlcr -ocrnl
  c_lflag: 0x00000000 -echo -icanon -isig
  c_cflag: 0x000000bf -clocal cread -cstopb
nsh> 
nsh> stty
Terminal settings for stdin:
  speed unknown or not supported by driver; min = 1; time = 0;
  c_iflag: 0x00000100 icrnl -igncr -inlcr
  c_oflag: 0x00000005 opost onlcr -ocrnl
  c_lflag: 0x0000000b echo icanon isig
  c_cflag: 0x000000bf -clocal cread -cstopb
nsh> stty -F /dev/null
ERROR: /dev/null is not a TTY
nsh> stty -F /dev/noexist
ERROR: Failed to open /dev/noexist: 2

Runtime Test Results(goldfish-armv7a-ap):

goldfish-armv7a-ap> stty -F /dev/ttyS1
Terminal settings for /dev/ttyS1:
  speed 115200 baud; min = 1; time = 0;
  c_iflag: 0x00000100 icrnl -igncr -inlcr
  c_oflag: 0x00000005 opost onlcr -ocrnl
  c_lflag: 0x0000000b echo icanon isig
  c_cflag: 0x000000b0 -clocal cread -cstopb

This commit adds a system utily 'stty' to NuttX, providing a standard
Unix-like interface for configuring terminal (TTY) device settings.
The command allows runtime configuration of termios attributes for
serial ports and other character devices.

Usage examples:

  # Set raw mode on ttyS0 (for binary communication)
  nsh> stty -F /dev/ttyS0 raw -echo

  # Set console mode for interactive terminal
  nsh> stty -F /dev/ttyS0 cooked

  # Display current settings
  nsh> stty -F /dev/ttyS0

  # Configure stdin (if it's a TTY)
  nsh> stty echo icanon

  # Set baudrate (if driver support)
  nsh> stty -F /dev/ttyS1 speed 115200

Signed-off-by: fangpeina <fangpeina@xiaomi.com>

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fangpeina nice addition! Please add the Documentation about this new command

@fangpeina

Copy link
Copy Markdown
Contributor Author

@fangpeina nice addition! Please add the Documentation about this new command

Done. Related PR: #19845

@acassis
acassis merged commit be038ce into apache:master Aug 14, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants