STM32L443xx HAL User Manual
|
UART HAL module driver. This file provides firmware functions to manage the following functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions. More...
#include "stm32l4xx_hal.h"
Go to the source code of this file.
Defines | |
#define | USART_CR1_FIELDS |
#define | USART_CR3_FIELDS |
#define | LPUART_BRR_MIN 0x00000300U /* LPUART BRR minimum authorized value */ |
#define | LPUART_BRR_MAX 0x000FFFFFU /* LPUART BRR maximum authorized value */ |
#define | UART_BRR_MIN 0x10U /* UART BRR minimum authorized value */ |
#define | UART_BRR_MAX 0x0000FFFFU /* UART BRR maximum authorized value */ |
Functions | |
static void | UART_EndTxTransfer (UART_HandleTypeDef *huart) |
End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion). | |
static void | UART_EndRxTransfer (UART_HandleTypeDef *huart) |
End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). | |
static void | UART_DMATransmitCplt (DMA_HandleTypeDef *hdma) |
DMA UART transmit process complete callback. | |
static void | UART_DMAReceiveCplt (DMA_HandleTypeDef *hdma) |
DMA UART receive process complete callback. | |
static void | UART_DMARxHalfCplt (DMA_HandleTypeDef *hdma) |
DMA UART receive process half complete callback. | |
static void | UART_DMATxHalfCplt (DMA_HandleTypeDef *hdma) |
DMA UART transmit process half complete callback. | |
static void | UART_DMAError (DMA_HandleTypeDef *hdma) |
DMA UART communication error callback. | |
static void | UART_DMAAbortOnError (DMA_HandleTypeDef *hdma) |
DMA UART communication abort callback, when initiated by HAL services on Error (To be called at end of DMA Abort procedure following error occurrence). | |
static void | UART_DMATxAbortCallback (DMA_HandleTypeDef *hdma) |
DMA UART Tx communication abort callback, when initiated by user (To be called at end of DMA Tx Abort procedure following user abort request). | |
static void | UART_DMARxAbortCallback (DMA_HandleTypeDef *hdma) |
DMA UART Rx communication abort callback, when initiated by user (To be called at end of DMA Rx Abort procedure following user abort request). | |
static void | UART_DMATxOnlyAbortCallback (DMA_HandleTypeDef *hdma) |
DMA UART Tx communication abort callback, when initiated by user by a call to HAL_UART_AbortTransmit_IT API (Abort only Tx transfer) (This callback is executed at end of DMA Tx Abort procedure following user abort request, and leads to user Tx Abort Complete callback execution). | |
static void | UART_DMARxOnlyAbortCallback (DMA_HandleTypeDef *hdma) |
DMA UART Rx communication abort callback, when initiated by user by a call to HAL_UART_AbortReceive_IT API (Abort only Rx transfer) (This callback is executed at end of DMA Rx Abort procedure following user abort request, and leads to user Rx Abort Complete callback execution). | |
static void | UART_TxISR_8BIT (UART_HandleTypeDef *huart) |
TX interrupt handler for 7 or 8 bits data word length . | |
static void | UART_TxISR_16BIT (UART_HandleTypeDef *huart) |
TX interrupt handler for 9 bits data word length. | |
static void | UART_EndTransmit_IT (UART_HandleTypeDef *huart) |
Wrap up transmission in non-blocking mode. | |
static void | UART_RxISR_8BIT (UART_HandleTypeDef *huart) |
RX interrupt handler for 7 or 8 bits data word length . | |
static void | UART_RxISR_16BIT (UART_HandleTypeDef *huart) |
RX interrupt handler for 9 bits data word length . | |
HAL_StatusTypeDef | HAL_UART_Init (UART_HandleTypeDef *huart) |
Initialize the UART mode according to the specified parameters in the UART_InitTypeDef and initialize the associated handle. | |
HAL_StatusTypeDef | HAL_HalfDuplex_Init (UART_HandleTypeDef *huart) |
Initialize the half-duplex mode according to the specified parameters in the UART_InitTypeDef and creates the associated handle. | |
HAL_StatusTypeDef | HAL_LIN_Init (UART_HandleTypeDef *huart, uint32_t BreakDetectLength) |
Initialize the LIN mode according to the specified parameters in the UART_InitTypeDef and creates the associated handle. | |
HAL_StatusTypeDef | HAL_MultiProcessor_Init (UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod) |
Initialize the multiprocessor mode according to the specified parameters in the UART_InitTypeDef and initialize the associated handle. | |
HAL_StatusTypeDef | HAL_UART_DeInit (UART_HandleTypeDef *huart) |
DeInitialize the UART peripheral. | |
__weak void | HAL_UART_MspInit (UART_HandleTypeDef *huart) |
Initialize the UART MSP. | |
__weak void | HAL_UART_MspDeInit (UART_HandleTypeDef *huart) |
DeInitialize the UART MSP. | |
HAL_StatusTypeDef | HAL_UART_RegisterCallback (UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback) |
Register a User UART Callback To be used instead of the weak predefined callback. | |
HAL_StatusTypeDef | HAL_UART_UnRegisterCallback (UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID) |
Unregister an UART Callback UART callaback is redirected to the weak predefined callback. | |
HAL_StatusTypeDef | HAL_UART_RegisterRxEventCallback (UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback) |
Register a User UART Rx Event Callback To be used instead of the weak predefined callback. | |
HAL_StatusTypeDef | HAL_UART_UnRegisterRxEventCallback (UART_HandleTypeDef *huart) |
UnRegister the UART Rx Event Callback UART Rx Event Callback is redirected to the weak HAL_UARTEx_RxEventCallback() predefined callback. | |
HAL_StatusTypeDef | HAL_UART_Transmit (UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout) |
Send an amount of data in blocking mode. | |
HAL_StatusTypeDef | HAL_UART_Receive (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
Receive an amount of data in blocking mode. | |
HAL_StatusTypeDef | HAL_UART_Transmit_IT (UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size) |
Send an amount of data in interrupt mode. | |
HAL_StatusTypeDef | HAL_UART_Receive_IT (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
Receive an amount of data in interrupt mode. | |
HAL_StatusTypeDef | HAL_UART_Transmit_DMA (UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size) |
Send an amount of data in DMA mode. | |
HAL_StatusTypeDef | HAL_UART_Receive_DMA (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
Receive an amount of data in DMA mode. | |
HAL_StatusTypeDef | HAL_UART_DMAPause (UART_HandleTypeDef *huart) |
Pause the DMA Transfer. | |
HAL_StatusTypeDef | HAL_UART_DMAResume (UART_HandleTypeDef *huart) |
Resume the DMA Transfer. | |
HAL_StatusTypeDef | HAL_UART_DMAStop (UART_HandleTypeDef *huart) |
Stop the DMA Transfer. | |
HAL_StatusTypeDef | HAL_UART_Abort (UART_HandleTypeDef *huart) |
Abort ongoing transfers (blocking mode). | |
HAL_StatusTypeDef | HAL_UART_AbortTransmit (UART_HandleTypeDef *huart) |
Abort ongoing Transmit transfer (blocking mode). | |
HAL_StatusTypeDef | HAL_UART_AbortReceive (UART_HandleTypeDef *huart) |
Abort ongoing Receive transfer (blocking mode). | |
HAL_StatusTypeDef | HAL_UART_Abort_IT (UART_HandleTypeDef *huart) |
Abort ongoing transfers (Interrupt mode). | |
HAL_StatusTypeDef | HAL_UART_AbortTransmit_IT (UART_HandleTypeDef *huart) |
Abort ongoing Transmit transfer (Interrupt mode). | |
HAL_StatusTypeDef | HAL_UART_AbortReceive_IT (UART_HandleTypeDef *huart) |
Abort ongoing Receive transfer (Interrupt mode). | |
void | HAL_UART_IRQHandler (UART_HandleTypeDef *huart) |
Handle UART interrupt request. | |
__weak void | HAL_UART_TxCpltCallback (UART_HandleTypeDef *huart) |
Tx Transfer completed callback. | |
__weak void | HAL_UART_TxHalfCpltCallback (UART_HandleTypeDef *huart) |
Tx Half Transfer completed callback. | |
__weak void | HAL_UART_RxCpltCallback (UART_HandleTypeDef *huart) |
Rx Transfer completed callback. | |
__weak void | HAL_UART_RxHalfCpltCallback (UART_HandleTypeDef *huart) |
Rx Half Transfer completed callback. | |
__weak void | HAL_UART_ErrorCallback (UART_HandleTypeDef *huart) |
UART error callback. | |
__weak void | HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart) |
UART Abort Complete callback. | |
__weak void | HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart) |
UART Abort Complete callback. | |
__weak void | HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart) |
UART Abort Receive Complete callback. | |
__weak void | HAL_UARTEx_RxEventCallback (UART_HandleTypeDef *huart, uint16_t Size) |
Reception Event Callback (Rx event notification called after use of advanced reception service). | |
void | HAL_UART_ReceiverTimeout_Config (UART_HandleTypeDef *huart, uint32_t TimeoutValue) |
Update on the fly the receiver timeout value in RTOR register. | |
HAL_StatusTypeDef | HAL_UART_EnableReceiverTimeout (UART_HandleTypeDef *huart) |
Enable the UART receiver timeout feature. | |
HAL_StatusTypeDef | HAL_UART_DisableReceiverTimeout (UART_HandleTypeDef *huart) |
Disable the UART receiver timeout feature. | |
HAL_StatusTypeDef | HAL_MultiProcessor_EnableMuteMode (UART_HandleTypeDef *huart) |
Enable UART in mute mode (does not mean UART enters mute mode; to enter mute mode, HAL_MultiProcessor_EnterMuteMode() API must be called). | |
HAL_StatusTypeDef | HAL_MultiProcessor_DisableMuteMode (UART_HandleTypeDef *huart) |
Disable UART mute mode (does not mean the UART actually exits mute mode as it may not have been in mute mode at this very moment). | |
void | HAL_MultiProcessor_EnterMuteMode (UART_HandleTypeDef *huart) |
Enter UART mute mode (means UART actually enters mute mode). | |
HAL_StatusTypeDef | HAL_HalfDuplex_EnableTransmitter (UART_HandleTypeDef *huart) |
Enable the UART transmitter and disable the UART receiver. | |
HAL_StatusTypeDef | HAL_HalfDuplex_EnableReceiver (UART_HandleTypeDef *huart) |
Enable the UART receiver and disable the UART transmitter. | |
HAL_StatusTypeDef | HAL_LIN_SendBreak (UART_HandleTypeDef *huart) |
Transmit break characters. | |
HAL_UART_StateTypeDef | HAL_UART_GetState (UART_HandleTypeDef *huart) |
Return the UART handle state. | |
uint32_t | HAL_UART_GetError (UART_HandleTypeDef *huart) |
Return the UART handle error code. | |
void | UART_InitCallbacksToDefault (UART_HandleTypeDef *huart) |
Initialize the callbacks to their default values. | |
HAL_StatusTypeDef | UART_SetConfig (UART_HandleTypeDef *huart) |
Configure the UART peripheral. | |
void | UART_AdvFeatureConfig (UART_HandleTypeDef *huart) |
Configure the UART peripheral advanced features. | |
HAL_StatusTypeDef | UART_CheckIdleState (UART_HandleTypeDef *huart) |
Check the UART Idle State. | |
HAL_StatusTypeDef | UART_WaitOnFlagUntilTimeout (UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout) |
This function handles UART Communication Timeout. | |
HAL_StatusTypeDef | UART_Start_Receive_IT (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
Start Receive operation in interrupt mode. | |
HAL_StatusTypeDef | UART_Start_Receive_DMA (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
Start Receive operation in DMA mode. |
UART HAL module driver. This file provides firmware functions to manage the following functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions.
Copyright (c) 2017 STMicroelectronics. All rights reserved.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.
=============================================================================== ##### How to use this driver ##### =============================================================================== [..] The UART HAL driver can be used as follows: (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart). (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API: (++) Enable the USARTx interface clock. (++) UART pins configuration: (+++) Enable the clock for the UART GPIOs. (+++) Configure these UART pins as alternate function pull-up. (++) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() and HAL_UART_Receive_IT() APIs): (+++) Configure the USARTx interrupt priority. (+++) Enable the NVIC USART IRQ handle. (++) UART interrupts handling: -@@- The specific UART interrupts (Transmission complete interrupt, RXNE interrupt, RX/TX FIFOs related interrupts and Error Interrupts) are managed using the macros __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit and receive processes. (++) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() and HAL_UART_Receive_DMA() APIs): (+++) Declare a DMA handle structure for the Tx/Rx channel. (+++) Enable the DMAx interface clock. (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. (+++) Configure the DMA Tx/Rx channel. (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle. (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Prescaler value , Hardware flow control and Mode (Receiver/Transmitter) in the huart handle Init structure. (#) If required, program UART advanced features (TX/RX pins swap, auto Baud rate detection,...) in the huart handle AdvancedInit structure. (#) For the UART asynchronous mode, initialize the UART registers by calling the HAL_UART_Init() API. (#) For the UART Half duplex mode, initialize the UART registers by calling the HAL_HalfDuplex_Init() API. (#) For the UART LIN (Local Interconnection Network) mode, initialize the UART registers by calling the HAL_LIN_Init() API. (#) For the UART Multiprocessor mode, initialize the UART registers by calling the HAL_MultiProcessor_Init() API. (#) For the UART RS485 Driver Enabled mode, initialize the UART registers by calling the HAL_RS485Ex_Init() API. [..] (@) These API's (HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init(), HAL_MultiProcessor_Init(), also configure the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_UART_MspInit() API. ##### Callback registration ##### ================================== [..] The compilation define USE_HAL_UART_REGISTER_CALLBACKS when set to 1 allows the user to configure dynamically the driver callbacks. [..] Use Function HAL_UART_RegisterCallback() to register a user callback. Function HAL_UART_RegisterCallback() allows to register following callbacks: (+) TxHalfCpltCallback : Tx Half Complete Callback. (+) TxCpltCallback : Tx Complete Callback. (+) RxHalfCpltCallback : Rx Half Complete Callback. (+) RxCpltCallback : Rx Complete Callback. (+) ErrorCallback : Error Callback. (+) AbortCpltCallback : Abort Complete Callback. (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. (+) WakeupCallback : Wakeup Callback. #if defined(USART_CR1_FIFOEN) (+) RxFifoFullCallback : Rx Fifo Full Callback. (+) TxFifoEmptyCallback : Tx Fifo Empty Callback. #endif (+) MspInitCallback : UART MspInit. (+) MspDeInitCallback : UART MspDeInit. This function takes as parameters the HAL peripheral handle, the Callback ID and a pointer to the user callback function. [..] Use function HAL_UART_UnRegisterCallback() to reset a callback to the default weak (surcharged) function. HAL_UART_UnRegisterCallback() takes as parameters the HAL peripheral handle, and the Callback ID. This function allows to reset following callbacks: (+) TxHalfCpltCallback : Tx Half Complete Callback. (+) TxCpltCallback : Tx Complete Callback. (+) RxHalfCpltCallback : Rx Half Complete Callback. (+) RxCpltCallback : Rx Complete Callback. (+) ErrorCallback : Error Callback. (+) AbortCpltCallback : Abort Complete Callback. (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. (+) WakeupCallback : Wakeup Callback. #if defined(USART_CR1_FIFOEN) (+) RxFifoFullCallback : Rx Fifo Full Callback. (+) TxFifoEmptyCallback : Tx Fifo Empty Callback. #endif (+) MspInitCallback : UART MspInit. (+) MspDeInitCallback : UART MspDeInit. [..] For specific callback RxEventCallback, use dedicated registration/reset functions: respectively HAL_UART_RegisterRxEventCallback() , HAL_UART_UnRegisterRxEventCallback(). [..] By default, after the HAL_UART_Init() and when the state is HAL_UART_STATE_RESET all callbacks are set to the corresponding weak (surcharged) functions: examples HAL_UART_TxCpltCallback(), HAL_UART_RxHalfCpltCallback(). Exception done for MspInit and MspDeInit functions that are respectively reset to the legacy weak (surcharged) functions in the HAL_UART_Init() and HAL_UART_DeInit() only when these callbacks are null (not registered beforehand). If not, MspInit or MspDeInit are not null, the HAL_UART_Init() and HAL_UART_DeInit() keep and use the user MspInit/MspDeInit callbacks (registered beforehand). [..] Callbacks can be registered/unregistered in HAL_UART_STATE_READY state only. Exception done MspInit/MspDeInit that can be registered/unregistered in HAL_UART_STATE_READY or HAL_UART_STATE_RESET state, thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. In that case first register the MspInit/MspDeInit user callbacks using HAL_UART_RegisterCallback() before calling HAL_UART_DeInit() or HAL_UART_Init() function. [..] When The compilation define USE_HAL_UART_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak (surcharged) callbacks are used.
Definition in file stm32l4xx_hal_uart.c.