Skip to content

File UART.h

FileList > bsp > Inc > UART.h

Go to the source code of this file

Provides functions for initializing, sending, receiving, and managing UART peripherals. More...

  • #include "stm32xx_hal.h"

Public Types

Type Name
enum uart_status_t

Public Functions

Type Name
uart_status_t uart_deinit (UART_HandleTypeDef * handle)
Deinitializes the specified UART peripheral.
uart_status_t uart_init (UART_HandleTypeDef * handle)
Initializes the specified UART peripheral.
uart_status_t uart_recv (UART_HandleTypeDef * handle, uint8_t * data, uint8_t length, TickType_t delay_ticks)
Receives data from UART RX queue.
uart_status_t uart_send (UART_HandleTypeDef * handle, const uint8_t * data, uint8_t length, TickType_t delay_ticks)
Transmits data over UART. If a transmission is in progress, data will be queued.

Detailed Description

This file contains the API for working with UART (Universal Asynchronous Receiver/Transmitter) peripherals in an embedded system, including initialization, data transmission, reception, and queue-based handling (e.g., with FreeRTOS). The functions support flexible configuration of UART instances and integration with user-provided GPIO initialization.

Initialization:

  • Call uart_init() to configure and initialize a specific UART peripheral.
  • Provide the UART configuration structure and handle for the target peripheral.
  • Returns a status code indicating success or failure.

Data Transmission:

  • Call uart_send() to queue data for transmission over the UART.
  • The function will transmit when the peripheral is available.

Data Reception:

  • Call uart_recv() to read received data from the RX queue.
  • Specify the number of bytes to read.

Deinitialization:

  • Call uart_deinit() to reset the UART peripheral and release resources.

Note:

  • The functions HAL_UART_MspGPIOInit() and HAL_UART_MspGPIODeInit() must be overridden by the user to provide GPIO initialization/deinitialization for the selected UART, including enabling clocks and calling HAL_GPIO_Init() with the correct GPIO_InitTypeDef.
  • Each UART peripheral is currently intended for use by a single task since only one receive queue exists.

Public Types Documentation

enum uart_status_t

enum uart_status_t {
    UART_ERR,
    UART_OK,
    UART_SENT,
    UART_RECV,
    UART_EMPTY
};

Public Functions Documentation

function uart_deinit

Deinitializes the specified UART peripheral.

uart_status_t uart_deinit (
    UART_HandleTypeDef * handle
) 

Parameters:

  • handle Pointer to the UART handle.

Returns:

uart_status_t Returns UART_OK on success, UART_ERR on failure.


function uart_init

Initializes the specified UART peripheral.

uart_status_t uart_init (
    UART_HandleTypeDef * handle
) 

Parameters:

  • handle Pointer to the UART handle.

Returns:

uart_status_t Returns UART_OK on success, UART_ERR on failure.


function uart_recv

Receives data from UART RX queue.

uart_status_t uart_recv (
    UART_HandleTypeDef * handle,
    uint8_t * data,
    uint8_t length,
    TickType_t delay_ticks
) 

Parameters:

  • handle Pointer to the UART handle.
  • data Pointer to buffer where received data will be stored.
  • length Number of bytes to read.
  • delay_ticks Ticks to wait for data (0 = non-blocking, portMAX_DELAY = block until available).

Returns:

uart_status_t Returns UART_RECV on success, UART_EMPTY if RX queue empty, UART_ERR on failure.


function uart_send

Transmits data over UART. If a transmission is in progress, data will be queued.

uart_status_t uart_send (
    UART_HandleTypeDef * handle,
    const uint8_t * data,
    uint8_t length,
    TickType_t delay_ticks
) 

Parameters:

  • handle Pointer to the UART handle.
  • data Pointer to the buffer containing data to send.
  • length Number of bytes to transmit.
  • delay_ticks Ticks to wait if TX queue is full (0 = no wait, portMAX_DELAY = wait indefinitely).

Returns:

uart_status_t Returns UART_SENT on queued/sent, UART_ERR on failure.



The documentation for this class was generated from the following file bsp/Inc/UART.h