nuttx/Documentation
Lingao Meng aa3157e234 arch/sim: Add PTY mode for simulated UART
The simulated UART driver currently opens the host path configured by
CONFIG_SIM_UARTx_NAME directly. This requires the host-side serial endpoint
to exist before NuttX opens the UART, so users and CI jobs need an external
setup step such as socat to create a PTY pair. It also means the host
endpoint path is effectively a build-time choice: changing the host device
path requires changing configuration and rebuilding, which is inconvenient
for tests that allocate a fresh PTY path on each run.

Add CONFIG_SIM_UART_PTY for Linux sim builds. When enabled, non-console
simulated UART ports allocate a host pseudoterminal from /dev/ptmx, put the
host master side in raw mode, and print the host slave path when the NuttX
UART is opened. The NuttX-side device name remains CONFIG_SIM_UARTx_NAME,
for example /dev/ttySIM0, so applications continue to use the normal NuttX
serial API.

Keep the option disabled by default so existing configurations still open
the configured host path directly. Console UART handling is also left on the
existing host-open path.

Also make host_uart_checkin() and host_uart_checkout() check the actual
POLLIN/POLLOUT bits returned by poll(). This avoids treating error-only or
unrelated poll events as readable or writable serial readiness.

The main benefit is simpler and more deterministic simulator integration: a
simulated UART can expose a real host-visible /dev/pts/N endpoint by itself,
without pre-creating a matching host device and without rebuilding NuttX
when the host PTY path changes. This is useful for host-side test scripts
and external protocol tools while keeping application code on the standard
NuttX UART interface.

Companion apps-side test branch:

  https://github.com/LingaoM/nuttx-apps/tree/sim_uart_tester

Testing:

  Host:

    Ubuntu 22.04 x86_64

  Board/config:

    sim:nsh

  Apps test code:

    https://github.com/LingaoM/nuttx-apps/tree/sim_uart_tester

  Common test configuration:

    CONFIG_NSH_BUILTIN_APPS=y
    CONFIG_EXAMPLES_HELLO=y
    CONFIG_SIM_UART_NUMBER=1
    CONFIG_SIM_UART0_NAME="/dev/ttySIM0"
    CONFIG_SIM_UART_PTY=y

  DMA-mode build and test:

    1. Configure sim:nsh with the companion apps tree:

         ./tools/configure.sh -a ../nuttx-apps sim:nsh

    2. Enable the common test configuration above and keep DMA enabled:

         CONFIG_SIM_UART_DMA=y
         CONFIG_SERIAL_TXDMA=y
         CONFIG_SERIAL_RXDMA=y

    3. Build:

         make clean
         make -j16

    4. Start NuttX:

         ./nuttx

    5. In NSH, run the hello test app:

         nsh> hello
         /dev/ttySIM0 connected to pseudotty: /dev/pts/73

    6. In another terminal, run the host-side tester from the companion apps
       branch with the printed PTY path:

         cd ../nuttx-apps
         ./examples/hello/test_sim_uart_pty.py /dev/pts/73

    7. The host-side tester sends 32768 bytes from the host to NuttX and
       receives 49152 bytes from NuttX to the host. The payload includes
       non-text binary bytes. Both sides validate deterministic payload
       contents and checksums, then exchange an ACK.

    8. Observed host-side output:

         HOST_OPEN: /dev/pts/73
         HOST_TX: 32768 bytes checksum=0x1f9989f4
         HOST_RX: 49152 bytes checksum=0x06a45c69
         HOST_TX: ACK
         TEST PASSED

    9. Observed NuttX output:

         sim_uart_pty_test: binary RX 32768 TX 49152 passed

  Non-DMA build and test:

    1. Disable DMA for the same sim:nsh configuration:

         # CONFIG_SIM_UART_DMA is not set
         # CONFIG_SERIAL_TXDMA is not set
         # CONFIG_SERIAL_RXDMA is not set

    2. Refresh the configuration and rebuild. On this host, the installed
       Python olddefconfig shim is broken, so I refreshed Kconfig directly
       with kconfig-conf and the same environment that the NuttX Makefile
       passes to Kconfig:

         APPSDIR=/mnt/ssd/code/code/nuttx-apps \
         APPSBINDIR=/mnt/ssd/code/code/nuttx-apps \
         BINDIR=/mnt/ssd/code/code/nuttx \
         EXTERNALDIR=/mnt/ssd/code/code/nuttx/dummy \
           kconfig-conf --olddefconfig Kconfig

         make clean
         make -j16

    3. Repeated the same runtime steps as the DMA test:

         ./nuttx
         nsh> hello
         cd ../nuttx-apps
         ./examples/hello/test_sim_uart_pty.py /dev/pts/73

    4. Observed the same successful binary transfer result:

         HOST_TX: 32768 bytes checksum=0x1f9989f4
         HOST_RX: 49152 bytes checksum=0x06a45c69
         HOST_TX: ACK
         TEST PASSED
         sim_uart_pty_test: binary RX 32768 TX 49152 passed

  After the non-DMA test, I restored the default DMA configuration, rebuilt,
  and reran the same binary PTY test successfully so the final local build
  state was back on CONFIG_SIM_UART_DMA=y.

Assisted-by: Claude:Claude-Fable-5
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-07-25 15:03:56 +08:00
..
_extensions Documentation: port warnings_filter Sphinx extension from Zephyr 2023-11-28 09:18:29 -08:00
_static docs: reduce main content max width from 1200px to 1000px 2021-03-26 23:41:45 -05:00
_templates Documentation: support versioned docs 2020-11-26 10:58:44 -08:00
applications docs/applications/txmorse: Document the txmorse application 2026-07-24 12:03:37 +08:00
components arch/arm: Reserve r10 via ARCHCFLAGS and hoist the PIC module flags. 2026-07-24 23:09:08 +08:00
contributing !arch/stm32: move stm32l1 and finalize the directory split 2026-06-24 14:54:44 -03:00
debugging Documentation: Add documentation of SCHED_DUMP_TASKS and SCHED_DUMP_STACK 2026-06-09 08:04:54 -04:00
faq !boards: Remove NSH_ARCHINIT and board_app_initialize 2026-05-02 18:36:46 +08:00
guides arch/arm/src/stm32: unify pulse count driver into common/stm32 2026-07-12 09:35:51 +08:00
implementation Documentation: Fix kernel module wording. 2026-07-05 19:43:23 +02:00
introduction WIP: Documentation: replace first person perspectives 2025-05-19 20:21:33 +08:00
logos style: fix typos 2025-04-30 13:45:46 +08:00
platforms arch/sim: Add PTY mode for simulated UART 2026-07-25 15:03:56 +08:00
quickstart Documentation: fill in pass1 directory description in organization.rst 2026-07-06 10:18:42 -03:00
reference arch/avr/src/avrdx/avrdx_delay: add custom up_udelay function 2026-06-12 09:55:11 -04:00
ReleaseNotes Documentation: add NuttX 13.0.0 release notes 2026-06-25 19:50:07 +08:00
standards libc/unistd: add getgroups() 2026-06-24 14:55:11 -03:00
testing Documentation/testing: Document MemBrowse integration 2026-06-19 12:21:54 -03:00
.gitignore docs/tags: Introduce tagging feature to the documentation. 2025-04-29 09:18:25 +02:00
conf.py Documentation: conf: Ignore .venv 2026-05-29 01:26:21 +08:00
glossary.rst rename doc/ -> Documentation/ 2020-08-24 10:29:55 -07:00
index.rst docs/security: Add Security section to the documentation. 2026-01-06 02:17:20 +08:00
known-warnings.txt fs: Add VFS docs 2024-02-20 18:28:09 -08:00
legacy_README.md style: Fix "the the" typo across the codebase. 2026-03-23 11:07:49 +01:00
make.bat Documentation: Remove all tail spaces from *.rst and *.html 2020-10-18 10:51:22 -07:00
Makefile doc: Improve sphinx build time + add autobuild help info. 2026-01-27 09:50:55 +08:00
Pipfile docs/plantuml: Add PlantUML support to Documentation build 2026-02-15 08:47:23 +01:00
Pipfile.lock build(deps): bump starlette from 1.0.1 to 1.3.1 in /Documentation 2026-06-18 12:49:49 -04:00
security.rst docs/security: Add Security section to the documentation. 2026-01-06 02:17:20 +08:00
substitutions.rst Remove the double blank line from source files 2022-02-20 20:10:14 +01:00