Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

uart_handler * uart_init(uint32_t port, uint32_t rx_mode, uint32_t tx_mode)

Initialize a specified UART interface

port is the UART interface (1 to 8 corresponding to the number of the UART interfaces; rx_mode defines how receivers will be performed, possible values are UART_POLLING, UART_INTERRUPT, UART_DMA; tx_mode defines how transmit will be performed; possible values are UART_POLLING, UART_INTERRUPT, UART_DMA; returns the UART interface handle or 0 in case of error

int uart_read(uart_handler * huart, uint8_t * pdata, uint16_t size, uint32_t timeout)

Receive an amount of data

huart is the UART interface handle; pdata is the pointer to data buffer; size is the amount of data to be received; timeout is the amount of ticks for timeout in polling mode; returns a number of received bytes or a negative error code

int uart_write(uart_handler * huart, uint8_t * pdata, uint16_t size, uint32_t timeout)

Send an amount of data

huart is the UART interface handle; pdata is the pointer to data buffer; size is the amount of data to be sent; timeout is the amount of ticks for timeout in polling mode; returns a number of transmitted bytes or a negative error code

HAL_StatusTypeDef uart_deinit(uart_handler * huart)

De-Initialize the UART interface

huart is the UART interface handle; returns the status of operation

1.3. UART CLI Command

The FreeRTOS application implements the following UART related CLI command:

Command

Description

Comments

uart_test <port> <baudrate> <count>

Read data from the specified UART interface at the baudrate rate and send it back to the same UART interface. The command exits if the count bytes have been received or the special charcter OEF has been detected.

2. Validating UART Operation

Use the following step-wise procedure to validate the UART operation:

...