This application note explains how to use the STM32H7 UART interfaces in the FreeRTOS demo application.
1. Understanding UART Interfaces
1.1. FreeRTOS UART Implementation
The FreeRTOS BSP provides a device driver for the UART interfaces. The driver is configured (enabled / disabled) at the BSP build time, using the HAL_UART_MODULE_ENABLED
configuration option, defined in the stm32h7xx_hal_conf.h
file.
1.2. FreeRTOS UART C-Binding API
The UART driver implements the following C-binding API:
Function | Description | Comments |
| ||
Initialize a specified UART interface |
| |
| ||
Receive an amount of data |
| |
| ||
Send an amount of data |
| |
| ||
De-Initialize the UART interface |
|
1.3. UART CLI Command
The FreeRTOS application implements the following UART related CLI command:
Command | Description | Comments |
| Read data from the specified UART interface at the |
2. Validating UART Operation
Use the following step-wise procedure to validate the UART operation:
Connect the target USART3 interface to the Linux development host (eg. via a UART-to-USB adapter).
On the STM32H7-BSB Rev 1A board: P5.14 (TX/PB10), P5.16 (RX/PB11);
On the STM32H7-BSB Rev 2A board: P5.15 (TX/PB10), P5.16 (RX/PB11).
Power cycle the target board and let it boot to the FreeRTOS CLI.
Generate a 1MB test file on the Linux development host:
$ echo -n `</dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c1048576` > /tmp/rdata
From the FreeRTOS CLI, run the following command (read a 1MB data stream at 115200):
CLI> uart_test 3 115200 1048576
Run the following command in a terminal window (referred to as term1 herein) on the Linux development host:
$ stty raw -echo 115200 -F /dev/ttyUSB0; cat < /dev/ttyUSB0 > /tmp/utest
In a second terminal window (term2) on the Linux development host run the following command:
$ stty raw -echo 115200 -F /dev/ttyUSB0; cat /tmp/rdata > /dev/ttyUSB0
Wait for the
uart_test
CLI command to complete:uart test completed. CLI>
Terminate cat by pressing Ctrl-C on term1 terminal and verify the sent and received files are identical:
^C $ md5sum /tmp/rdata /tmp/utest 05e2c95e78835af6e01397e0acecf8fc /tmp/rdata 05e2c95e78835af6e01397e0acecf8fc /tmp/utest