Template:ArticleMainWriter Template:ArticleApprovedVersion Template:UpdateNeededForNewRelease
1. Purpose[edit source]
This article describes how to use TTY with a user terminal. The TTY overview is described in Serial TTY overview article.
The use case of the following examples is a data transfer between a STM32 MPU board and PC, over a USB to a RS232 adapter cable.
The setup of this use case is described in details in the How to get Terminal article.
For the following examples:
- uart4 is activated by default (for the Linux console)
- usart3 is enabled by device tree
- The usart3 pins are connected to a RS232 card
- The RS232 card is connected to the PC over the USB to RS232 adapter cable.
Note: Some TTY tools are used in this article. A list of TTY tools is defined a dedicated article [TTY Tools ].
2. Print the file name of the terminal connected to standard input (with tty tool)[edit source]
Template:Board$ tty Template:Green Template:Highlight
3. Change serial port configuration (with stty tool)[edit source]
Many serial port properties can be displayed and changed with the stty tool. The full feature list is available in stty user manual pages [1] .
Template:Board$ stty --help
- Display the current configuration:
Template:Board$ stty -a -F /dev/ttySTM1 Template:Highlight speed 115200 baud; rows 45; columns 169; line = 0;
- Display only the current baud rate:
Template:Board$ stty -F /dev/ttySTM1 speed 115200 Template:Highlight
- Change the baud rate:
stty -F /dev/ttySTMx EXPECTED_BAUDRATE
Example: change the baud rate to 19200
Template:Board$ stty -F /dev/ttySTM1 19200 Template:Highlight
The stty tool proposes many arguments allowing many operations on a tty terminal, such as:
- special settings (various arguments such as speed, line discipline, minimum number of characters for a completed read, size, timeout, etc...)
- control settings
- input settings
- output settings
- local settings
- combination settings
Note: If you want to go further, an interesting tutorial describes termios and stty [2].
4. Send / Receive data (with stty, minicom, echo and cat tools)[edit source]
Sending data can be simply done by opening the device as a file and writing data to it:
- Configure a port on ttySTM1 (usart3)
Template:Board$ stty -F /dev/ttySTM1 115200 -echo
- Open a port on ttySTM1 (usart3) to receive data
Template:Board$ cat /dev/ttySTM1 &
- On the remote PC, identify the tty terminal associated to RS232 card connected on STM32MPU USART3 pins
Template:PC$ ls /dev/ttyUSB* /dev/ttyUSB0
- Open a minicom terminal on the remote device connected on USART3 pins
Template:PC$ minicom -D /dev/ttyUSB0
- Send data from remote PC to STM32MPU over USART3
Template:PC$ echo "HELLO" > /dev/ttyUSB0
- send data from STM32MPU to remote PC over USART3
Template:Board$ echo "HELLO" > /dev/ttySTM1
5. Identify processes using a tty serial device (with fuser tool)[edit source]
Template:Board$ fuser /dev/ttySTM0 395 691 3872 Template:Highlight
6. Link a tty serial device with a line discipline (with ldattach tool)[edit source]
Attach ttySTM1 with line discipline number n :
Template:Board$ ldattach n /dev/ttySTM1
7. File transfer over serial console[edit source]
Please see the dedicated article How to transfer a file over serial console.