zephyr/samples/drivers/uart/native_tty
Marko Sagadin 54cbf45c74 drivers: uart: add support for serial ports on native posix
Add support for communication with serial ports on native POSIX platform
via UART driver API. Serial port driver supports polling API,
configuration of the serial ports used via devicetree and command line
options, and runtime configuration with `uart_configure`.
Multiple instances of the driver are supported.
Example use and configuration is also demonstrated in the
`samples/drivers/uart/native_tty` sample.

Closes: #56586

Signed-off-by: Marko Sagadin <marko.sagadin42@gmail.com>
2023-06-21 09:27:22 +02:00
..
boards
src
CMakeLists.txt
prj.conf
README.rst
sample.yaml

.. _sample-uart-native-tty:

Native TTY UART
###############

Overview
********

This sample demonstrates the usage of the Native TTY UART driver. It uses two
UART to USB bridge dongles that are wired together, writing demo data to one
dongle and reading it from the other."

The source code for this sample application can be found at:
:zephyr_file:`samples/drivers/uart/native-tty`.

You can learn more about the Native TTY UART driver in the
:ref:`TTY UART <native_tty_uart>` section of the Native posix board
documentation.

Requirements
************

#. Two UART to USB bridge dongles. Each dongle must have its TX pin wired to the
   other dongle's RX pin. The ground connection is not needed. Both dongles must
   be plugged into the host machine.
#. The DT overlay provided with the sample expects the dongles to appear as
   ``/dev/ttyUSB0`` and ``/dev/ttyUSB1`` in the system. You can check what they
   are in your system by running the command ``ls -l /dev/tty*``. If that is not
   the case on your machine you can either change the ``serial-port`` properties
   in the ``boards/native_posix.overlay`` file or using the command line options
   ``-uart_port`` and ``-uart_port2``.

Building and Running
********************

This application can be built and executed on Native Posix as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/uart/native_tty
   :host-os: unix
   :board: native_posix
   :goals: run
   :compact:

Sample Output
=============

.. code-block:: console

   uart_1 connected to pseudotty: /dev/pts/6
   uart2 connected to the serial port: /dev/ttyUSB1
   uart connected to the serial port: /dev/ttyUSB0
   *** Booting Zephyr OS build v3.4.0-rc2-97-ge586d02c137d ***
   Device uart sent: "Hello from device uart, num 9"
   Device uart2 received: "Hello from device uart, num 9"
   Device uart sent: "Hello from device uart, num 8"
   Device uart2 received: "Hello from device uart, num 8"
   Device uart sent: "Hello from device uart, num 7"
   Device uart2 received: "Hello from device uart, num 7"
   Device uart sent: "Hello from device uart, num 6"
   Device uart2 received: "Hello from device uart, num 6"
   Device uart sent: "Hello from device uart, num 5"
   Device uart2 received: "Hello from device uart, num 5"
   Device uart sent: "Hello from device uart, num 4"
   Device uart2 received: "Hello from device uart, num 4"
   Device uart sent: "Hello from device uart, num 3"
   Device uart2 received: "Hello from device uart, num 3"
   Device uart sent: "Hello from device uart, num 2"
   Device uart2 received: "Hello from device uart, num 2"
   Device uart sent: "Hello from device uart, num 1"
   Device uart2 received: "Hello from device uart, num 1"
   Device uart sent: "Hello from device uart, num 0"
   Device uart2 received: "Hello from device uart, num 0"

   Changing baudrate of both uart devices to 9600!

   Device uart sent: "Hello from device uart, num 9"
   Device uart2 received: "Hello from device uart, num 9"
   Device uart sent: "Hello from device uart, num 8"
   Device uart2 received: "Hello from device uart, num 8"
   Device uart sent: "Hello from device uart, num 7"
   Device uart2 received: "Hello from device uart, num 7"
   Device uart sent: "Hello from device uart, num 6"
   Device uart2 received: "Hello from device uart, num 6"
   Device uart sent: "Hello from device uart, num 5"
   Device uart2 received: "Hello from device uart, num 5"
   Device uart sent: "Hello from device uart, num 4"
   Device uart2 received: "Hello from device uart, num 4"
   Device uart sent: "Hello from device uart, num 3"
   Device uart2 received: "Hello from device uart, num 3"
   Device uart sent: "Hello from device uart, num 2"
   Device uart2 received: "Hello from device uart, num 2"
   Device uart sent: "Hello from device uart, num 1"
   Device uart2 received: "Hello from device uart, num 1"
   Device uart sent: "Hello from device uart, num 0"
   Device uart2 received: "Hello from device uart, num 0"