HAL UART Overview

Introducing UART

group UART_Introduction

  • The UART hardware abstraction layer provides a set of APIs to interface with STM32 peripherals such as UART (Universal Asynchronous Receiver Transmitter), LPUART (Low-Power UART) and USART (Universal Synchronous/Asynchronous Receiver Transmitter) supporting the UART communications (asynchronous, half-duplex single-wire, multiprocessor, LIN, ModBus, …).

It simplifies the configuration, initialization, and management of asynchronous UART communications by supporting various modes, such as polling, interrupt, and DMA, for efficient data transfer.

  • This abstraction layer ensures portability and ease of use across different STM32 series, as well as multiple peripherals supporting the UART communications (USART, UART, and LPUART).

Module and files

The following diagram illustrates the UART module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the UART module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title UART Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_UART]
    [HAL_DMA]
}

package "Low Layer" {
    [LL_LPUART / LL_USART]
    [CMSIS]
    [UART Interrupt routine service]
    [DMA Interrupt routine service]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_UART] : HAL UART API
[Appli] <-- [HAL_UART] : UART callback
[HAL_UART] --> [LL_LPUART / LL_USART] : LL UART API
[HAL_UART] -r-> [HAL_DMA] : HAL DMA_Start_IT\nHAL_DMA_Abort_IT
[HAL_UART] -l-> [HAL_SERVICE] : HAL_GetTick
[HAL_UART] <-- [UART Interrupt routine service]
[HAL_UART] <-r- [HAL_DMA]:Half transfer complete\nTransfer complete\nError
[LL_LPUART / LL_USART] --> [CMSIS]:UART register def
[HAL_DMA] <-d- [DMA Interrupt routine service]
[STM32_HW] -u--> [UART Interrupt routine service]: UARTx Irq
[STM32_HW] -u--> [DMA Interrupt routine service] : DMA Channel Irq
[STM32_HW] <-u-- [LL_LPUART / LL_USART] : UART registers R/W
@enduml

Configuration table

The following table lists the configuration defines for the HAL UART module, specifying their locations, default values, and descriptions:

group UART_Configuration_Table

9- Configuration inside the UART driver:

Software configuration defined in stm32c5xx_hal_conf.h:

Preprocessor flags

Default value

Comment

USE_HAL_UART_MODULE

1

Enable HAL UART driver module

USE_HAL_UART_REGISTER_CALLBACKS

0

Allows you to define your own callback

USE_HAL_UART_DMA

1

Enable DMA code inside the HAL UART

USE_HAL_CHECK_PARAM

0

Enable runtime parameter checking

USE_HAL_UART_CLK_ENABLE_MODEL

HAL_CLK_ENABLE_NO

Enable the gating of the peripheral clock

USE_HAL_CHECK_PROCESS_STATE

0

Enable atomicity of process state checking

USE_HAL_MUTEX

0

Enable semaphore creation for OS

USE_HAL_UART_USER_DATA

0

Add user data inside the HAL UART handle

USE_HAL_UART_GET_LAST_ERRORS

0

Enable retrieval of the last process error codes

Software configuration defined in preprocessor environment:

Preprocessor flags

Default value

Comment

USE_ASSERT_DBG_PARAM

Not defined

Enable parameter checking for HAL and LL

USE_ASSERT_DBG_STATE

Not defined

Enable state checking for HAL