UART Read/Write Demo
Demo overview
This demo shows how to test the UART serial communication on the development board.
The serial ports supported by the board and their corresponding device nodes are listed below.
| Serial port | Device node |
|---|---|
| RS232 UART0 | ttyS0 |
| TTL UART0 | ttyS4 |
| RS485 UART7 | ttyS7 |
| RS485 UART8 | ttyS8 |
The following uses TTL UART0 as an example to walk through the test procedure in detail, including hardware connection, software configuration, and the specific steps to implement serial read/write.
Preparation
Before starting the test, complete the following preparations:
Hardware connection
Use a USB-to-TTL serial module to connect the PC to the board's TTL UART4 interface. The exact location of the TTL UART4 interface is shown in the figure; make sure the connection is correct and secure.

Software preparation
Open Device Manager and confirm the device is recognized correctly. After the first connection you may need to restart the PC before the correct device name "XR21V1410 USB UART" appears, as shown in the figure.

On the PC, open a serial debugging tool (for installing the debugging tool, see "Quick Start / Debugging Tools Installation"), select the corresponding serial port — COM13 in this demo. Set the baud rate to 115200, data bits to 8, and no parity bit, as shown below. Click "Open" to establish the connection.

Procedure
TTL UART4 serial test
Copy the executable smdt_uart_rw from this demo's bin directory (05-Development Materials\Software Development Materials\linux_demo\smdt_uart_rw\bin) to the board's filesystem (the source code is available under the src path). Open a terminal and run the following command to switch to the directory containing the smdt_uart_rw executable.
cd ‘文件所在目录’After switching, run ls to confirm that smdt_uart_rw is in the current directory.
lsIf the executable smdt_uart_rw is present in the current directory, continue. Run the following command to change the file's permissions.
chmod 777 smdt_uart_rwAfter changing the permissions, run the following command to verify the change.
ls -ld smdt_uart_rwThe result should be: -rwxrwxrwx 1 root root 19016 Mar 3 09:55 smdt_uart_rw.
-rwxrwxrwx indicates the permission change succeeded and the file is executable; you may continue.
Continue by running the following command to view the program's parameter information.
./smdt_uart_rw -hThe result is shown below:

Board receives
Run the following command and wait to receive data from the PC.
./smdt_uart_rw -d /dev/ttyS4 -r -s 9On the PC, use the serial debugging tool to send "ShimetaPi".

The board's debug serial terminal will print the received data.
Board sends
Run the following command; the board sends data to the PC via the UART4 serial port. The sent data is "012345670".
./smdt_uart_rw -d /dev/ttyS4 -w -s 9The serial debugging tool will receive the following data.

