summaryrefslogtreecommitdiff
path: root/ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c')
-rw-r--r--ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c1265
1 files changed, 841 insertions, 424 deletions
diff --git a/ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c b/ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c
index 5460b6b93..9057853fa 100644
--- a/ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c
+++ b/ext/hal/st/stm32cube/stm32f1xx/drivers/src/stm32f1xx_hal_usart.c
@@ -2,15 +2,14 @@
******************************************************************************
* @file stm32f1xx_hal_usart.c
* @author MCD Application Team
- * @version V1.0.4
- * @date 29-April-2016
+ * @version V1.1.0
+ * @date 14-April-2017
* @brief USART HAL module driver.
- * This file provides firmware functions to manage the following
+ * This file provides firmware functions to manage the following
* functionalities of the Universal Synchronous Asynchronous Receiver Transmitter (USART) peripheral:
* + Initialization and de-initialization functions
* + IO operation functions
- * + Peripheral Control functions
- * + Peripheral State and Errors functions
+ * + Peripheral Control functions
@verbatim
==============================================================================
##### How to use this driver #####
@@ -19,7 +18,7 @@
The USART HAL driver can be used as follows:
(#) Declare a USART_HandleTypeDef handle structure.
- (#) Initialize the USART low level resources by implementing the HAL_USART_MspInit() API:
+ (#) Initialize the USART low level resources by implementing the HAL_USART_MspInit () API:
(##) Enable the USARTx interface clock.
(##) USART pins configuration:
(+++) Enable the clock for the USART GPIOs.
@@ -34,82 +33,99 @@
(+++) 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 initilalized DMA handle to the USART DMA Tx/Rx handle.
+ (+++) Associate the initialized DMA handle to the USART DMA Tx/Rx handle.
(+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
+ (+++) Configure the priority and enable the NVIC for the transfer complete
+ interrupt on the DMA Tx/Rx channel.
(+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle
- (used for last byte sending completion detection in DMA non circular mode)
+ (used for last byte sending completion detection in DMA non circular mode)
- (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
+ (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
flow control and Mode(Receiver/Transmitter) in the husart Init structure.
(#) Initialize the USART registers by calling the HAL_USART_Init() API:
(++) These APIs configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
- by calling the customed HAL_USART_MspInit(&husart) API.
-
- -@@- The specific USART interrupts (Transmission complete interrupt,
+ by calling the customized HAL_USART_MspInit(&husart) API.
+
+ -@@- The specific USART interrupts (Transmission complete interrupt,
RXNE interrupt and Error Interrupts) will be managed using the macros
__HAL_USART_ENABLE_IT() and __HAL_USART_DISABLE_IT() inside the transmit and receive process.
-
- (#) Three operation modes are available within this driver :
-
+
+ (#) Three operation modes are available within this driver :
+
*** Polling mode IO operation ***
=================================
- [..]
- (+) Send an amount of data in blocking mode using HAL_USART_Transmit()
+ [..]
+ (+) Send an amount of data in blocking mode using HAL_USART_Transmit()
(+) Receive an amount of data in blocking mode using HAL_USART_Receive()
-
- *** Interrupt mode IO operation ***
+
+ *** Interrupt mode IO operation ***
===================================
- [..]
- (+) Send an amount of data in non blocking mode using HAL_USART_Transmit_IT()
- (+) At transmission end of transfer HAL_USART_TxCpltCallback is executed and user can
+ [..]
+ (+) Send an amount of data in non blocking mode using HAL_USART_Transmit_IT()
+ (+) At transmission end of transfer HAL_USART_TxHalfCpltCallback is executed and user can
add his own code by customization of function pointer HAL_USART_TxCpltCallback
- (+) Receive an amount of data in non blocking mode using HAL_USART_Receive_IT()
- (+) At reception end of transfer HAL_USART_RxCpltCallback is executed and user can
- add his own code by customization of function pointer HAL_USART_RxCpltCallback
- (+) In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can
+ (+) Receive an amount of data in non blocking mode using HAL_USART_Receive_IT()
+ (+) At reception end of transfer HAL_USART_RxCpltCallback is executed and user can
+ add his own code by customization of function pointer HAL_USART_RxCpltCallback
+ (+) In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can
add his own code by customization of function pointer HAL_USART_ErrorCallback
-
- *** DMA mode IO operation ***
+
+ *** DMA mode IO operation ***
==============================
- [..]
- (+) Send an amount of data in non blocking mode (DMA) using HAL_USART_Transmit_DMA()
- (+) At transmission end of half transfer HAL_USART_TxHalfCpltCallback is executed and user can
- add his own code by customization of function pointer HAL_USART_TxHalfCpltCallback
- (+) At transmission end of transfer HAL_USART_TxCpltCallback is executed and user can
+ [..]
+ (+) Send an amount of data in non blocking mode (DMA) using HAL_USART_Transmit_DMA()
+ (+) At transmission end of half transfer HAL_USART_TxHalfCpltCallback is executed and user can
+ add his own code by customization of function pointer HAL_USART_TxHalfCpltCallback
+ (+) At transmission end of transfer HAL_USART_TxCpltCallback is executed and user can
add his own code by customization of function pointer HAL_USART_TxCpltCallback
- (+) Receive an amount of data in non blocking mode (DMA) using HAL_USART_Receive_DMA()
- (+) At reception end of half transfer HAL_USART_RxHalfCpltCallback is executed and user can
- add his own code by customization of function pointer HAL_USART_RxHalfCpltCallback
- (+) At reception end of transfer HAL_USART_RxCpltCallback is executed and user can
- add his own code by customization of function pointer HAL_USART_RxCpltCallback
- (+) In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can
+ (+) Receive an amount of data in non blocking mode (DMA) using HAL_USART_Receive_DMA()
+ (+) At reception end of half transfer HAL_USART_RxHalfCpltCallback is executed and user can
+ add his own code by customization of function pointer HAL_USART_RxHalfCpltCallback
+ (+) At reception end of transfer HAL_USART_RxCpltCallback is executed and user can
+ add his own code by customization of function pointer HAL_USART_RxCpltCallback
+ (+) In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can
add his own code by customization of function pointer HAL_USART_ErrorCallback
- (+) Pause the DMA Transfer using HAL_USART_DMAPause()
- (+) Resume the DMA Transfer using HAL_USART_DMAResume()
- (+) Stop the DMA Transfer using HAL_USART_DMAStop()
-
+ (+) Pause the DMA Transfer using HAL_USART_DMAPause()
+ (+) Resume the DMA Transfer using HAL_USART_DMAResume()
+ (+) Stop the DMA Transfer using HAL_USART_DMAStop()
+
*** USART HAL driver macros list ***
- =============================================
+ =============================================
[..]
Below the list of most used macros in USART HAL driver.
-
- (+) __HAL_USART_ENABLE: Enable the USART peripheral
- (+) __HAL_USART_DISABLE: Disable the USART peripheral
+
+ (+) __HAL_USART_ENABLE: Enable the USART peripheral
+ (+) __HAL_USART_DISABLE: Disable the USART peripheral
(+) __HAL_USART_GET_FLAG : Check whether the specified USART flag is set or not
(+) __HAL_USART_CLEAR_FLAG : Clear the specified USART pending flag
(+) __HAL_USART_ENABLE_IT: Enable the specified USART interrupt
(+) __HAL_USART_DISABLE_IT: Disable the specified USART interrupt
- (+) __HAL_USART_GET_IT_SOURCE: Check whether the specified USART interrupt has occurred or not
-
- [..]
+
+ [..]
(@) You can refer to the USART HAL driver header file for more useful macros
@endverbatim
+ [..]
+ (@) Additionnal remark: If the parity is enabled, then the MSB bit of the data written
+ in the data register is transmitted but is changed by the parity bit.
+ Depending on the frame length defined by the M bit (8-bits or 9-bits),
+ the possible USART frame formats are as listed in the following table:
+ +-------------------------------------------------------------+
+ | M bit | PCE bit | USART frame |
+ |---------------------|---------------------------------------|
+ | 0 | 0 | | SB | 8 bit data | STB | |
+ |---------|-----------|---------------------------------------|
+ | 0 | 1 | | SB | 7 bit data | PB | STB | |
+ |---------|-----------|---------------------------------------|
+ | 1 | 0 | | SB | 9 bit data | STB | |
+ |---------|-----------|---------------------------------------|
+ | 1 | 1 | | SB | 8 bit data | PB | STB | |
+ +-------------------------------------------------------------+
******************************************************************************
* @attention
*
- * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
+ * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -148,22 +164,26 @@
* @{
*/
#ifdef HAL_USART_MODULE_ENABLED
+
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
-/** @defgroup USART_Private_Constants USART Private Constants
+/** @addtogroup USART_Private_Constants
* @{
*/
-#define DUMMY_DATA 0xFFFF
+#define DUMMY_DATA 0xFFFFU
+#define USART_TIMEOUT_VALUE 22000U
/**
* @}
*/
-
-/* Private macros --------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
-/** @addtogroup USART_Private_Functions USART Private Functions
+/* Private functions ---------------------------------------------------------*/
+/** @addtogroup USART_Private_Functions
* @{
*/
+static void USART_EndTxTransfer(USART_HandleTypeDef *husart);
+static void USART_EndRxTransfer(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_EndTransmit_IT(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart);
@@ -173,70 +193,57 @@ static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
-static void USART_DMAError(DMA_HandleTypeDef *hdma);
-static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
+static void USART_DMAError(DMA_HandleTypeDef *hdma);
+static void USART_DMAAbortOnError(DMA_HandleTypeDef *hdma);
+static void USART_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
+static void USART_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
+
+static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
/**
* @}
*/
-/* Exported functions ---------------------------------------------------------*/
-
-
+/* Exported functions --------------------------------------------------------*/
/** @defgroup USART_Exported_Functions USART Exported Functions
* @{
*/
-/** @defgroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
- * @brief Initialization and Configuration functions
+/** @defgroup USART_Exported_Functions_Group1 USART Initialization and de-initialization functions
+ * @brief Initialization and Configuration functions
*
@verbatim
==============================================================================
- ##### Initialization and Configuration functions #####
+ ##### Initialization and Configuration functions #####
==============================================================================
[..]
- This subsection provides a set of functions allowing to initialize the USART
+ This subsection provides a set of functions allowing to initialize the USART
in asynchronous and in synchronous modes.
- (+) For the asynchronous mode only these parameters can be configured:
+ (+) For the asynchronous mode only these parameters can be configured:
(++) Baud Rate
- (++) Word Length
+ (++) Word Length
(++) Stop Bit
- (++) Parity
+ (++) Parity: If the parity is enabled, then the MSB bit of the data written
+ in the data register is transmitted but is changed by the parity bit.
+ Depending on the frame length defined by the M bit (8-bits or 9-bits),
+ please refer to Reference manual for possible USART frame formats.
(++) USART polarity
(++) USART phase
(++) USART LastBit
(++) Receiver/transmitter modes
[..]
- The HAL_USART_Init() function follows the USART synchronous configuration
+ The HAL_USART_Init() function follows the USART synchronous configuration
procedure (details for the procedure are available in reference manuals
(RM0008 for STM32F10Xxx MCUs and RM0041 for STM32F100xx MCUs)).
@endverbatim
* @{
*/
-
-/*
- Additionnal remark: If the parity is enabled, then the MSB bit of the data written
- in the data register is transmitted but is changed by the parity bit.
- Depending on the frame length defined by the M bit (8-bits or 9-bits),
- the possible USART frame formats are as listed in the following table:
- +-------------------------------------------------------------+
- | M bit | PCE bit | USART frame |
- |---------------------|---------------------------------------|
- | 0 | 0 | | SB | 8 bit data | STB | |
- |---------|-----------|---------------------------------------|
- | 0 | 1 | | SB | 7 bit data | PB | STB | |
- |---------|-----------|---------------------------------------|
- | 1 | 0 | | SB | 9 bit data | STB | |
- |---------|-----------|---------------------------------------|
- | 1 | 1 | | SB | 8 bit data | PB | STB | |
- +-------------------------------------------------------------+
-*/
/**
* @brief Initializes the USART mode according to the specified
* parameters in the USART_InitTypeDef and create the associated handle.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
@@ -255,7 +262,7 @@ HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
{
/* Allocate lock resource and initialize it */
husart->Lock = HAL_UNLOCKED;
-
+
/* Init the low level hardware */
HAL_USART_MspInit(husart);
}
@@ -265,11 +272,11 @@ HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
/* Set the USART Communication parameters */
USART_SetConfig(husart);
- /* In USART mode, the following bits must be kept cleared:
+ /* In USART mode, the following bits must be kept cleared:
- LINEN bit in the USART_CR2 register
- HDSEL, SCEN and IREN bits in the USART_CR3 register */
CLEAR_BIT(husart->Instance->CR2, USART_CR2_LINEN);
- CLEAR_BIT(husart->Instance->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
+ CLEAR_BIT(husart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
/* Enable the Peripheral */
__HAL_USART_ENABLE(husart);
@@ -283,13 +290,13 @@ HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
/**
* @brief DeInitializes the USART peripheral.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
{
- /* Check the USART handle allocation */
+ /* Check the USART handle allocation */
if(husart == NULL)
{
return HAL_ERROR;
@@ -300,9 +307,6 @@ HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
husart->State = HAL_USART_STATE_BUSY;
- /* Disable the Peripheral */
- __HAL_USART_DISABLE(husart);
-
/* DeInit the low level hardware */
HAL_USART_MspDeInit(husart);
@@ -317,66 +321,66 @@ HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
/**
* @brief USART MSP Init.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
- __weak void HAL_USART_MspInit(USART_HandleTypeDef *husart)
+__weak void HAL_USART_MspInit(USART_HandleTypeDef *husart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_MspInit can be implemented in the user file
- */
+ the HAL_USART_MspInit could be implemented in the user file
+ */
}
/**
* @brief USART MSP DeInit.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
- __weak void HAL_USART_MspDeInit(USART_HandleTypeDef *husart)
+__weak void HAL_USART_MspDeInit(USART_HandleTypeDef *husart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_MspDeInit can be implemented in the user file
- */
+ the HAL_USART_MspDeInit could be implemented in the user file
+ */
}
/**
* @}
*/
-/** @defgroup USART_Exported_Functions_Group2 IO operation functions
- * @brief USART Transmit and Receive functions
+/** @defgroup USART_Exported_Functions_Group2 IO operation functions
+ * @brief USART Transmit and Receive functions
*
@verbatim
==============================================================================
- ##### IO operation functions #####
+ ##### IO operation functions #####
==============================================================================
[..]
This subsection provides a set of functions allowing to manage the USART synchronous
data transfers.
-
- [..]
+
+ [..]
The USART supports master mode only: it cannot receive or send data related to an input
clock (SCLK is always an output).
(#) There are two modes of transfer:
- (++) Blocking mode: The communication is performed in polling mode.
- The HAL status of all data processing is returned by the same function
- after finishing transfer.
- (++) No-Blocking mode: The communication is performed using Interrupts
+ (++) Blocking mode: The communication is performed in polling mode.
+ The HAL status of all data processing is returned by the same function
+ after finishing transfer.
+ (++) No-Blocking mode: The communication is performed using Interrupts
or DMA, These API's return the HAL status.
- The end of the data processing will be indicated through the
- dedicated USART IRQ when using Interrupt mode or the DMA IRQ when
+ The end of the data processing will be indicated through the
+ dedicated USART IRQ when using Interrupt mode or the DMA IRQ when
using DMA mode.
- The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback()
- user callbacks
+ The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback()
+ user callbacks
will be executed respectively at the end of the transmit or Receive process
- The HAL_USART_ErrorCallback() user callback will be executed when a communication
+ The HAL_USART_ErrorCallback() user callback will be executed when a communication
error is detected
(#) Blocking mode APIs are :
@@ -411,8 +415,8 @@ HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
*/
/**
- * @brief Simplex Send an amount of data in blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Simplex Send an amount of data in blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data buffer
* @param Size: Amount of data to be sent
@@ -421,11 +425,12 @@ HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
*/
HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
{
- uint16_t* tmp=0;
+ uint16_t* tmp;
+ uint32_t tickstart = 0U;
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -436,15 +441,18 @@ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxDa
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX;
+ /* Init tickstart for timeout managment */
+ tickstart = HAL_GetTick();
+
husart->TxXferSize = Size;
husart->TxXferCount = Size;
- while(husart->TxXferCount > 0)
+ while(husart->TxXferCount > 0U)
{
husart->TxXferCount--;
if(husart->Init.WordLength == USART_WORDLENGTH_9B)
{
/* Wait for TC flag in order to write data in DR */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -452,16 +460,16 @@ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxDa
WRITE_REG(husart->Instance->DR, (*tmp & (uint16_t)0x01FF));
if(husart->Init.Parity == USART_PARITY_NONE)
{
- pTxData += 2;
+ pTxData += 2U;
}
else
{
- pTxData += 1;
+ pTxData += 1U;
}
}
else
{
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -469,8 +477,8 @@ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxDa
}
}
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, Timeout) != HAL_OK)
- {
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
+ {
return HAL_TIMEOUT;
}
@@ -488,8 +496,8 @@ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxDa
}
/**
- * @brief Full-Duplex Receive an amount of data in blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Receive an amount of data in blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pRxData: Pointer to data buffer
* @param Size: Amount of data to be received
@@ -498,59 +506,62 @@ HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxDa
*/
HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
{
- uint16_t* tmp=0;
+ uint16_t* tmp;
+ uint32_t tickstart = 0U;
if(husart->State == HAL_USART_STATE_READY)
{
- if((pRxData == NULL) || (Size == 0))
+ if((pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
-
/* Process Locked */
__HAL_LOCK(husart);
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
+ /* Init tickstart for timeout managment */
+ tickstart = HAL_GetTick();
+
husart->RxXferSize = Size;
husart->RxXferCount = Size;
/* Check the remain data to be received */
- while(husart->RxXferCount > 0)
+ while(husart->RxXferCount > 0U)
{
husart->RxXferCount--;
if(husart->Init.WordLength == USART_WORDLENGTH_9B)
{
/* Wait until TXE flag is set to send dummy byte in order to generate the clock for the slave to send data */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
- {
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
+ {
return HAL_TIMEOUT;
}
/* Send dummy byte in order to generate clock */
WRITE_REG(husart->Instance->DR, (DUMMY_DATA & (uint16_t)0x01FF));
-
+
/* Wait for RXNE Flag */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
- {
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
+ {
return HAL_TIMEOUT;
}
tmp = (uint16_t*) pRxData ;
if(husart->Init.Parity == USART_PARITY_NONE)
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
- pRxData +=2;
+ pRxData +=2U;
}
else
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x00FF);
- pRxData +=1;
+ pRxData +=1U;
}
}
else
{
/* Wait until TXE flag is set to send dummy byte in order to generate the clock for the slave to send data */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
- {
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
+ {
return HAL_TIMEOUT;
}
@@ -558,7 +569,7 @@ HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxDat
WRITE_REG(husart->Instance->DR, (DUMMY_DATA & (uint16_t)0x00FF));
/* Wait until RXNE flag is set to receive the byte */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -590,22 +601,23 @@ HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxDat
}
/**
- * @brief Full-Duplex Send receive an amount of data in full-duplex mode (blocking mode).
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Send receive an amount of data in full-duplex mode (blocking mode).
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data transmitted buffer
- * @param pRxData: Pointer to data received buffer
+ * @param pRxData: Pointer to data received buffer
* @param Size: Amount of data to be sent
* @param Timeout: Timeout duration
* @retval HAL status
*/
HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
{
- uint16_t* tmp=0;
+ uint16_t* tmp;
+ uint32_t tickstart = 0U;
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -615,20 +627,23 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
+ /* Init tickstart for timeout managment */
+ tickstart = HAL_GetTick();
+
husart->RxXferSize = Size;
husart->TxXferSize = Size;
husart->TxXferCount = Size;
husart->RxXferCount = Size;
/* Check the remain data to be received */
- while(husart->TxXferCount > 0)
+ while(husart->TxXferCount > 0U)
{
husart->TxXferCount--;
husart->RxXferCount--;
if(husart->Init.WordLength == USART_WORDLENGTH_9B)
{
/* Wait for TC flag in order to write data in DR */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -636,15 +651,15 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t
WRITE_REG(husart->Instance->DR, (*tmp & (uint16_t)0x01FF));
if(husart->Init.Parity == USART_PARITY_NONE)
{
- pTxData += 2;
+ pTxData += 2U;
}
else
{
- pTxData += 1;
+ pTxData += 1U;
}
-
+
/* Wait for RXNE Flag */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -652,25 +667,25 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t
if(husart->Init.Parity == USART_PARITY_NONE)
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
- pRxData += 2;
+ pRxData += 2U;
}
else
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x00FF);
- pRxData += 1;
+ pRxData += 1U;
}
- }
+ }
else
{
/* Wait for TC flag in order to write data in DR */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
WRITE_REG(husart->Instance->DR, (*pTxData++ & (uint8_t)0x00FF));
/* Wait for RXNE Flag */
- if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
+ if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
@@ -701,8 +716,8 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t
}
/**
- * @brief Simplex Send an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Simplex Send an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data buffer
* @param Size: Amount of data to be sent
@@ -711,13 +726,13 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t
*/
HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
{
+ /* Check that a Tx process is not already ongoing */
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
-
/* Process Locked */
__HAL_LOCK(husart);
@@ -728,7 +743,7 @@ HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pT
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX;
- /* The USART Error Interrupts: (Frame error, Noise error, Overrun error)
+ /* The USART Error Interrupts: (Frame error, Noise error, Overrun error)
are not managed by the USART transmit process to avoid the overrun interrupt
when the USART mode is configured for transmit and receive "USART_MODE_TX_RX"
to benefit for the frame error and noise interrupts the USART mode should be
@@ -751,9 +766,9 @@ HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pT
}
/**
- * @brief Simplex Receive an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
- * the configuration information for the specified USART module.
+ * @brief Simplex Receive an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
+ * the configuration information for the specified USART module.
* @param pRxData: Pointer to data buffer
* @param Size: Amount of data to be received
* @retval HAL status
@@ -762,7 +777,7 @@ HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRx
{
if(husart->State == HAL_USART_STATE_READY)
{
- if((pRxData == NULL) || (Size == 0))
+ if((pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -800,11 +815,11 @@ HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRx
}
/**
- * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data transmitted buffer
- * @param pRxData: Pointer to data received buffer
+ * @param pRxData: Pointer to data received buffer
* @param Size: Amount of data to be received
* @retval HAL status
*/
@@ -812,7 +827,7 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint
{
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -848,13 +863,13 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint
}
else
{
- return HAL_BUSY;
+ return HAL_BUSY;
}
}
/**
- * @brief Simplex Send an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Simplex Send an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data buffer
* @param Size: Amount of data to be sent
@@ -862,16 +877,16 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint
*/
HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
{
- uint32_t *tmp=0;
+ uint32_t *tmp;
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
/* Process Locked */
- __HAL_LOCK(husart);
+ __HAL_LOCK(husart);
husart->pTxBuffPtr = pTxData;
husart->TxXferSize = Size;
@@ -889,6 +904,9 @@ HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *p
/* Set the DMA error callback */
husart->hdmatx->XferErrorCallback = USART_DMAError;
+ /* Set the DMA abort callback */
+ husart->hdmatx->XferAbortCallback = NULL;
+
/* Enable the USART transmit DMA channel */
tmp = (uint32_t*)&pTxData;
HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->DR, Size);
@@ -896,13 +914,13 @@ HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *p
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_USART_CLEAR_FLAG(husart, USART_FLAG_TC);
- /* Enable the DMA transfer for transmit request by setting the DMAT bit
- in the USART CR3 register */
- SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
-
/* Process Unlocked */
__HAL_UNLOCK(husart);
+ /* Enable the DMA transfer for transmit request by setting the DMAT bit
+ in the USART CR3 register */
+ SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
+
return HAL_OK;
}
else
@@ -912,8 +930,8 @@ HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *p
}
/**
- * @brief Full-Duplex Receive an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Receive an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pRxData: Pointer to data buffer
* @param Size: Amount of data to be received
@@ -923,11 +941,11 @@ HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *p
*/
HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
{
- uint32_t *tmp=0;
-
+ uint32_t *tmp;
+
if(husart->State == HAL_USART_STATE_READY)
{
- if((pRxData == NULL) || (Size == 0))
+ if((pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -952,20 +970,42 @@ HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pR
/* Set the USART DMA Rx transfer error callback */
husart->hdmarx->XferErrorCallback = USART_DMAError;
+ /* Set the DMA abort callback */
+ husart->hdmarx->XferAbortCallback = NULL;
+
+ /* Set the USART Tx DMA transfer complete callback as NULL because the communication closing
+ is performed in DMA reception complete callback */
+ husart->hdmatx->XferHalfCpltCallback = NULL;
+ husart->hdmatx->XferCpltCallback = NULL;
+
+ /* Set the DMA error callback */
+ husart->hdmatx->XferErrorCallback = USART_DMAError;
+
+ /* Set the DMA AbortCpltCallback */
+ husart->hdmatx->XferAbortCallback = NULL;
+
/* Enable the USART receive DMA channel */
tmp = (uint32_t*)&pRxData;
HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->DR, *(uint32_t*)tmp, Size);
/* Enable the USART transmit DMA channel: the transmit channel is used in order
- to generate in the non-blocking mode the clock to the slave device,
+ to generate in the non-blocking mode the clock to the slave device,
this mode isn't a simplex receive mode but a full-duplex receive one */
HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->DR, Size);
- /* Clear the Overrun flag just before enabling the DMA Rx request: mandatory for the second transfer
- when using the USART in circular mode */
+ /* Clear the Overrun flag just before enabling the DMA Rx request: mandatory for the second transfer */
__HAL_USART_CLEAR_OREFLAG(husart);
-
- /* Enable the DMA transfer for the receiver request by setting the DMAR bit
+
+ /* Process Unlocked */
+ __HAL_UNLOCK(husart);
+
+ /* Enable the USART Parity Error Interrupt */
+ SET_BIT(husart->Instance->CR1, USART_CR1_PEIE);
+
+ /* Enable the USART Error Interrupt: (Frame error, noise error, overrun error) */
+ SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
+ /* Enable the DMA transfer for the receiver request by setting the DMAR bit
in the USART CR3 register */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAR);
@@ -973,9 +1013,6 @@ HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pR
in the USART CR3 register */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
- /* Process Unlocked */
- __HAL_UNLOCK(husart);
-
return HAL_OK;
}
else
@@ -985,22 +1022,22 @@ HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pR
}
/**
- * @brief Full-Duplex Transmit Receive an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Transmit Receive an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param pTxData: Pointer to data transmitted buffer
- * @param pRxData: Pointer to data received buffer
+ * @param pRxData: Pointer to data received buffer
* @param Size: Amount of data to be received
* @note When the USART parity is enabled (PCE = 1) the data received contain the parity bit.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
{
- uint32_t *tmp=0;
+ uint32_t *tmp;
if(husart->State == HAL_USART_STATE_READY)
{
- if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
+ if((pTxData == NULL) || (pRxData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
@@ -1033,6 +1070,9 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uin
/* Set the USART DMA Rx transfer error callback */
husart->hdmarx->XferErrorCallback = USART_DMAError;
+ /* Set the DMA abort callback */
+ husart->hdmarx->XferAbortCallback = NULL;
+
/* Enable the USART receive DMA channel */
tmp = (uint32_t*)&pRxData;
HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->DR, *(uint32_t*)tmp, Size);
@@ -1040,14 +1080,23 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uin
/* Enable the USART transmit DMA channel */
tmp = (uint32_t*)&pTxData;
HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->DR, Size);
-
+
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_USART_CLEAR_FLAG(husart, USART_FLAG_TC);
/* Clear the Overrun flag: mandatory for the second transfer in circular mode */
__HAL_USART_CLEAR_OREFLAG(husart);
-
- /* Enable the DMA transfer for the receiver request by setting the DMAR bit
+
+ /* Process Unlocked */
+ __HAL_UNLOCK(husart);
+
+ /* Enable the USART Parity Error Interrupt */
+ SET_BIT(husart->Instance->CR1, USART_CR1_PEIE);
+
+ /* Enable the USART Error Interrupt: (Frame error, noise error, overrun error) */
+ SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
+ /* Enable the DMA transfer for the receiver request by setting the DMAR bit
in the USART CR3 register */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAR);
@@ -1055,9 +1104,6 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uin
in the USART CR3 register */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
- /* Process Unlocked */
- __HAL_UNLOCK(husart);
-
return HAL_OK;
}
else
@@ -1068,7 +1114,7 @@ HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uin
/**
* @brief Pauses the DMA Transfer.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
@@ -1076,19 +1122,19 @@ HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart)
{
/* Process Locked */
__HAL_LOCK(husart);
-
+
/* Disable the USART DMA Tx request */
- CLEAR_BIT(husart->Instance->CR3, (uint32_t)(USART_CR3_DMAT));
-
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
+
/* Process Unlocked */
__HAL_UNLOCK(husart);
- return HAL_OK;
+ return HAL_OK;
}
/**
* @brief Resumes the DMA Transfer.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
@@ -1096,10 +1142,10 @@ HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart)
{
/* Process Locked */
__HAL_LOCK(husart);
-
+
/* Enable the USART DMA Tx request */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
-
+
/* Process Unlocked */
__HAL_UNLOCK(husart);
@@ -1108,107 +1154,364 @@ HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart)
/**
* @brief Stops the DMA Transfer.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart)
{
+ uint32_t dmarequest = 0x00U;
/* The Lock is not implemented on this API to allow the user application
to call the HAL USART API under callbacks HAL_USART_TxCpltCallback() / HAL_USART_RxCpltCallback():
when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
and the correspond call back is executed HAL_USART_TxCpltCallback() / HAL_USART_RxCpltCallback()
*/
- /* Abort the USART DMA Tx channel */
- if(husart->hdmatx != NULL)
+ /* Stop USART DMA Tx request if ongoing */
+ dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT);
+ if((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest)
{
- HAL_DMA_Abort(husart->hdmatx);
- }
- /* Abort the USART DMA Rx channel */
- if(husart->hdmarx != NULL)
- {
- HAL_DMA_Abort(husart->hdmarx);
+ USART_EndTxTransfer(husart);
+
+ /* Abort the USART DMA Tx channel */
+ if(husart->hdmatx != NULL)
+ {
+ HAL_DMA_Abort(husart->hdmatx);
+ }
+
+ /* Disable the USART Tx DMA request */
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
}
-
- /* Disable the USART Tx/Rx DMA requests */
- CLEAR_BIT(husart->Instance->CR3, (USART_CR3_DMAT | USART_CR3_DMAR));
- husart->State = HAL_USART_STATE_READY;
+ /* Stop USART DMA Rx request if ongoing */
+ dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
+ if((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest)
+ {
+ USART_EndRxTransfer(husart);
+
+ /* Abort the USART DMA Rx channel */
+ if(husart->hdmarx != NULL)
+ {
+ HAL_DMA_Abort(husart->hdmarx);
+ }
+
+ /* Disable the USART Rx DMA request */
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
+ }
return HAL_OK;
}
/**
- * @brief This function handles USART interrupt request.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
- * the configuration information for the specified USART module.
- * @retval None
- */
-void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
+ * @brief Abort ongoing transfer (blocking mode).
+ * @param husart USART handle.
+ * @note This procedure could be used for aborting any ongoing transfer (either Tx or Rx,
+ * as described by TransferType parameter) started in Interrupt or DMA mode.
+ * This procedure performs following operations :
+ * - Disable PPP Interrupts (depending of transfer direction)
+ * - Disable the DMA transfer in the peripheral register (if enabled)
+ * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
+ * - Set handle State to READY
+ * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
+ * @retval HAL status
+*/
+HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart)
{
- uint32_t tmp_flag = 0, tmp_it_source = 0;
-
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_PE);
- tmp_it_source = __HAL_USART_GET_IT_SOURCE(husart, USART_IT_PE);
- /* USART parity error interrupt occurred -----------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
+ CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
+ /* Disable the USART DMA Tx request if enabled */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
{
- husart->ErrorCode |= HAL_USART_ERROR_PE;
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
+
+ /* Abort the USART DMA Tx channel : use blocking DMA Abort API (no callback) */
+ if(husart->hdmatx != NULL)
+ {
+ /* Set the USART DMA Abort callback to Null.
+ No call back execution at end of DMA abort procedure */
+ husart->hdmatx->XferAbortCallback = NULL;
+
+ HAL_DMA_Abort(husart->hdmatx);
+ }
}
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_FE);
- tmp_it_source = __HAL_USART_GET_IT_SOURCE(husart, USART_IT_ERR);
- /* USART frame error interrupt occurred ------------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ /* Disable the USART DMA Rx request if enabled */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
- husart->ErrorCode |= HAL_USART_ERROR_FE;
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
+
+ /* Abort the USART DMA Rx channel : use blocking DMA Abort API (no callback) */
+ if(husart->hdmarx != NULL)
+ {
+ /* Set the USART DMA Abort callback to Null.
+ No call back execution at end of DMA abort procedure */
+ husart->hdmarx->XferAbortCallback = NULL;
+
+ HAL_DMA_Abort(husart->hdmarx);
+ }
}
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_NE);
- /* USART noise error interrupt occurred ------------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ /* Reset Tx and Rx transfer counters */
+ husart->TxXferCount = 0x00U;
+ husart->RxXferCount = 0x00U;
+
+ /* Restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
+
+ /* Reset Handle ErrorCode to No Error */
+ husart->ErrorCode = HAL_USART_ERROR_NONE;
+
+ return HAL_OK;
+}
+
+/**
+ * @brief Abort ongoing transfer (Interrupt mode).
+ * @param husart USART handle.
+ * @note This procedure could be used for aborting any ongoing transfer (either Tx or Rx,
+ * as described by TransferType parameter) started in Interrupt or DMA mode.
+ * This procedure performs following operations :
+ * - Disable PPP Interrupts (depending of transfer direction)
+ * - Disable the DMA transfer in the peripheral register (if enabled)
+ * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
+ * - Set handle State to READY
+ * - At abort completion, call user abort complete callback
+ * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
+ * considered as completed only when user abort complete callback is executed (not when exiting function).
+ * @retval HAL status
+*/
+HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart)
+{
+ uint32_t AbortCplt = 0x01U;
+
+ /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
+ CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
+ /* If DMA Tx and/or DMA Rx Handles are associated to USART Handle, DMA Abort complete callbacks should be initialised
+ before any call to DMA Abort functions */
+ /* DMA Tx Handle is valid */
+ if(husart->hdmatx != NULL)
{
- husart->ErrorCode |= HAL_USART_ERROR_NE;
+ /* Set DMA Abort Complete callback if USART DMA Tx request if enabled.
+ Otherwise, set it to NULL */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
+ {
+ husart->hdmatx->XferAbortCallback = USART_DMATxAbortCallback;
+ }
+ else
+ {
+ husart->hdmatx->XferAbortCallback = NULL;
+ }
+ }
+ /* DMA Rx Handle is valid */
+ if(husart->hdmarx != NULL)
+ {
+ /* Set DMA Abort Complete callback if USART DMA Rx request if enabled.
+ Otherwise, set it to NULL */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
+ {
+ husart->hdmarx->XferAbortCallback = USART_DMARxAbortCallback;
+ }
+ else
+ {
+ husart->hdmarx->XferAbortCallback = NULL;
+ }
+ }
+
+ /* Disable the USART DMA Tx request if enabled */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
+ {
+ /* Disable DMA Tx at USART level */
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
+
+ /* Abort the USART DMA Tx channel : use non blocking DMA Abort API (callback) */
+ if(husart->hdmatx != NULL)
+ {
+ /* USART Tx DMA Abort callback has already been initialised :
+ will lead to call HAL_USART_AbortCpltCallback() at end of DMA abort procedure */
+
+ /* Abort DMA TX */
+ if(HAL_DMA_Abort_IT(husart->hdmatx) != HAL_OK)
+ {
+ husart->hdmatx->XferAbortCallback = NULL;
+ }
+ else
+ {
+ AbortCplt = 0x00U;
+ }
+ }
}
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_ORE);
- /* USART Over-Run interrupt occurred ---------------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ /* Disable the USART DMA Rx request if enabled */
+ if(HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
- husart->ErrorCode |= HAL_USART_ERROR_ORE;
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
+
+ /* Abort the USART DMA Rx channel : use non blocking DMA Abort API (callback) */
+ if(husart->hdmarx != NULL)
+ {
+ /* USART Rx DMA Abort callback has already been initialised :
+ will lead to call HAL_USART_AbortCpltCallback() at end of DMA abort procedure */
+
+ /* Abort DMA RX */
+ if(HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK)
+ {
+ husart->hdmarx->XferAbortCallback = NULL;
+ AbortCplt = 0x01U;
+ }
+ else
+ {
+ AbortCplt = 0x00U;
+ }
+ }
}
- if(husart->ErrorCode != HAL_USART_ERROR_NONE)
+ /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
+ if(AbortCplt == 0x01U)
{
- /* Clear all the error flag at once */
- __HAL_USART_CLEAR_PEFLAG(husart);
+ /* Reset Tx and Rx transfer counters */
+ husart->TxXferCount = 0x00U;
+ husart->RxXferCount = 0x00U;
- /* Set the USART state ready to be able to start again the process */
- husart->State = HAL_USART_STATE_READY;
-
- HAL_USART_ErrorCallback(husart);
+ /* Reset errorCode */
+ husart->ErrorCode = HAL_USART_ERROR_NONE;
+
+ /* Restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
+
+ /* As no DMA to be aborted, call directly user Abort complete callback */
+ HAL_USART_AbortCpltCallback(husart);
}
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_RXNE);
- tmp_it_source = __HAL_USART_GET_IT_SOURCE(husart, USART_IT_RXNE);
- /* USART in mode Receiver --------------------------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ return HAL_OK;
+}
+
+/**
+ * @brief This function handles USART interrupt request.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
+ * the configuration information for the specified USART module.
+ * @retval None
+ */
+void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
+{
+ uint32_t isrflags = READ_REG(husart->Instance->SR);
+ uint32_t cr1its = READ_REG(husart->Instance->CR1);
+ uint32_t cr3its = READ_REG(husart->Instance->CR3);
+ uint32_t errorflags = 0x00U;
+ uint32_t dmarequest = 0x00U;
+
+ /* If no error occurs */
+ errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
+ if(errorflags == RESET)
{
- if(husart->State == HAL_USART_STATE_BUSY_RX)
+ /* USART in mode Receiver -------------------------------------------------*/
+ if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
+ {
+ if(husart->State == HAL_USART_STATE_BUSY_RX)
+ {
+ USART_Receive_IT(husart);
+ }
+ else
+ {
+ USART_TransmitReceive_IT(husart);
+ }
+ return;
+ }
+ }
+ /* If some errors occur */
+ if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
+ {
+ /* USART parity error interrupt occurred ----------------------------------*/
+ if(((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
{
- USART_Receive_IT(husart);
+ husart->ErrorCode |= HAL_USART_ERROR_PE;
}
- else
+
+ /* USART noise error interrupt occurred --------------------------------*/
+ if(((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
- USART_TransmitReceive_IT(husart);
+ husart->ErrorCode |= HAL_USART_ERROR_NE;
}
+
+ /* USART frame error interrupt occurred --------------------------------*/
+ if(((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
+ {
+ husart->ErrorCode |= HAL_USART_ERROR_FE;
+ }
+
+ /* USART Over-Run interrupt occurred -----------------------------------*/
+ if(((isrflags & USART_SR_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
+ {
+ husart->ErrorCode |= HAL_USART_ERROR_ORE;
+ }
+
+ if(husart->ErrorCode != HAL_USART_ERROR_NONE)
+ {
+ /* USART in mode Receiver -----------------------------------------------*/
+ if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
+ {
+ if(husart->State == HAL_USART_STATE_BUSY_RX)
+ {
+ USART_Receive_IT(husart);
+ }
+ else
+ {
+ USART_TransmitReceive_IT(husart);
+ }
+ }
+ /* If Overrun error occurs, or if any error occurs in DMA mode reception,
+ consider error as blocking */
+ dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
+ if(((husart->ErrorCode & HAL_USART_ERROR_ORE) != RESET) || dmarequest)
+ {
+ /* Set the USART state ready to be able to start again the process,
+ Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
+ USART_EndRxTransfer(husart);
+
+ /* Disable the USART DMA Rx request if enabled */
+ if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
+ {
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
+
+ /* Abort the USART DMA Rx channel */
+ if(husart->hdmarx != NULL)
+ {
+ /* Set the USART DMA Abort callback :
+ will lead to call HAL_USART_ErrorCallback() at end of DMA abort procedure */
+ husart->hdmarx->XferAbortCallback = USART_DMAAbortOnError;
+
+ if(HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK)
+ {
+ /* Call Directly XferAbortCallback function in case of error */
+ husart->hdmarx->XferAbortCallback(husart->hdmarx);
+ }
+ }
+ else
+ {
+ /* Call user error callback */
+ HAL_USART_ErrorCallback(husart);
+ }
+ }
+ else
+ {
+ /* Call user error callback */
+ HAL_USART_ErrorCallback(husart);
+ }
+ }
+ else
+ {
+ /* Call user error callback */
+ HAL_USART_ErrorCallback(husart);
+ husart->ErrorCode = HAL_USART_ERROR_NONE;
+ }
+ }
+ return;
}
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_TXE);
- tmp_it_source = __HAL_USART_GET_IT_SOURCE(husart, USART_IT_TXE);
/* USART in mode Transmitter -----------------------------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+ if(((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
{
if(husart->State == HAL_USART_STATE_BUSY_TX)
{
@@ -1218,52 +1521,50 @@ void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
{
USART_TransmitReceive_IT(husart);
}
+ return;
}
-
- tmp_flag = __HAL_USART_GET_FLAG(husart, USART_FLAG_TC);
- tmp_it_source = __HAL_USART_GET_IT_SOURCE(husart, USART_IT_TC);
- /* USART in mode Transmitter (transmission end) -----------------------------*/
- if((tmp_flag != RESET) && (tmp_it_source != RESET))
+
+ /* USART in mode Transmitter (transmission end) ----------------------------*/
+ if(((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
USART_EndTransmit_IT(husart);
- }
-
+ return;
+ }
}
-
/**
* @brief Tx Transfer completed callbacks.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
- __weak void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart)
+__weak void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_TxCpltCallback can be implemented in the user file
+ the HAL_USART_TxCpltCallback could be implemented in the user file
*/
}
/**
* @brief Tx Half Transfer completed callbacks.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
- __weak void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart)
+__weak void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_TxHalfCpltCallback can be implemented in the user file
+ the HAL_USART_TxHalfCpltCallback could be implemented in the user file
*/
}
/**
* @brief Rx Transfer completed callbacks.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
@@ -1272,13 +1573,13 @@ __weak void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart)
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_RxCpltCallback can be implemented in the user file
+ the HAL_USART_RxCpltCallback could be implemented in the user file
*/
}
/**
* @brief Rx Half Transfer completed callbacks.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
@@ -1287,13 +1588,13 @@ __weak void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart)
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_RxHalfCpltCallback can be implemented in the user file
+ the HAL_USART_RxHalfCpltCallback could be implemented in the user file
*/
}
/**
* @brief Tx/Rx Transfers completed callback for the non-blocking process.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
@@ -1302,51 +1603,66 @@ __weak void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart)
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_TxRxCpltCallback can be implemented in the user file
+ the HAL_USART_TxRxCpltCallback could be implemented in the user file
*/
}
/**
* @brief USART error callbacks.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/
- __weak void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart)
+__weak void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(husart);
/* NOTE: This function should not be modified, when the callback is needed,
- the HAL_USART_ErrorCallback can be implemented in the user file
- */
+ the HAL_USART_ErrorCallback could be implemented in the user file
+ */
+}
+
+/**
+ * @brief USART Abort Complete callback.
+ * @param husart USART handle.
+ * @retval None
+ */
+__weak void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart)
+{
+ /* Prevent unused argument(s) compilation warning */
+ UNUSED(husart);
+
+ /* NOTE : This function should not be modified, when the callback is needed,
+ the HAL_USART_AbortCpltCallback can be implemented in the user file.
+ */
}
/**
* @}
*/
-/** @defgroup USART_Exported_Functions_Group3 Peripheral State and Errors functions
- * @brief USART State and Errors functions
+/** @defgroup USART_Exported_Functions_Group3 Peripheral State and Errors functions
+ * @brief USART State and Errors functions
*
-@verbatim
+@verbatim
==============================================================================
##### Peripheral State and Errors functions #####
- ==============================================================================
+ ==============================================================================
[..]
- This subsection provides a set of functions allowing to return the State of
+ This subsection provides a set of functions allowing to return the State of
USART communication
process, return Peripheral Errors occurred during communication process
- (+) HAL_USART_GetState() API can be helpful to check in run-time the state
+ (+) HAL_USART_GetState() API can be helpful to check in run-time the state
of the USART peripheral.
- (+) HAL_USART_GetError() check in run-time errors that could be occurred during
- communication.
+ (+) HAL_USART_GetError() check in run-time errors that could be occurred during
+ communication.
@endverbatim
* @{
*/
/**
* @brief Returns the USART state.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL state
*/
@@ -1379,7 +1695,8 @@ uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart)
* @{
*/
/**
- * @brief DMA USART transmit process complete callback.
+ * @brief DMA USART transmit process complete callback.
+ * @param hdma: DMA handle
* @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
@@ -1387,19 +1704,17 @@ uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart)
static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
-
/* DMA Normal mode */
- if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
+ if(HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC))
{
- husart->TxXferCount = 0;
-
+ husart->TxXferCount = 0U;
if(husart->State == HAL_USART_STATE_BUSY_TX)
{
/* Disable the DMA transfer for transmit request by resetting the DMAT bit
in the USART CR3 register */
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
- /* Enable the USART Transmit Complete Interrupt */
+ /* Enable the USART Transmit Complete Interrupt */
__HAL_USART_ENABLE_IT(husart, USART_IT_TC);
}
}
@@ -1414,8 +1729,8 @@ static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
}
/**
- * @brief DMA USART transmit process half complete callback
- * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
+ * @brief DMA USART transmit process half complete callback
+ * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
@@ -1427,32 +1742,35 @@ static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
}
/**
- * @brief DMA USART receive process complete callback.
- * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
- * the configuration information for the specified DMA module.
+ * @brief DMA USART receive process complete callback.
+ * @param hdma: DMA handle
* @retval None
*/
static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
-
/* DMA Normal mode */
- if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
+ if(HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC))
{
- husart->RxXferCount = 0;
+ husart->RxXferCount = 0x00U;
+
+ /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
if(husart->State == HAL_USART_STATE_BUSY_RX)
{
- /* Disable the DMA transfer for the receiver requests by setting the DMAR bit
+ /* Disable the DMA transfer for the Transmit/Receiver requests by setting the DMAT/DMAR bit
in the USART CR3 register */
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
husart->State= HAL_USART_STATE_READY;
HAL_USART_RxCpltCallback(husart);
}
- /* the usart state is HAL_USART_STATE_BUSY_TX_RX*/
+ /* The USART state is HAL_USART_STATE_BUSY_TX_RX */
else
{
- /* Disable the DMA transfer for the Transmit/receiver requests by setting the DMAT/DMAR bit
+ /* Disable the DMA transfer for the Transmit/receiver requests by setting the DMAT/DMAR bit
in the USART CR3 register */
CLEAR_BIT(husart->Instance->CR3, (USART_CR3_DMAT | USART_CR3_DMAR));
@@ -1467,7 +1785,7 @@ static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
HAL_USART_RxCpltCallback(husart);
}
- /* the usart state is HAL_USART_STATE_BUSY_TX_RX*/
+ /* The USART state is HAL_USART_STATE_BUSY_TX_RX */
else
{
HAL_USART_TxRxCpltCallback(husart);
@@ -1476,8 +1794,8 @@ static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
}
/**
- * @brief DMA USART receive process half complete callback
- * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
+ * @brief DMA USART receive process half complete callback
+ * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
* the configuration information for the specified DMA module.
* @retval None
*/
@@ -1485,108 +1803,208 @@ static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef* husart = (USART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
- HAL_USART_RxHalfCpltCallback(husart);
+ HAL_USART_RxHalfCpltCallback(husart);
}
/**
- * @brief DMA USART communication error callback.
- * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
- * the configuration information for the specified DMA module.
+ * @brief DMA USART communication error callback.
+ * @param hdma: DMA handle
* @retval None
*/
-static void USART_DMAError(DMA_HandleTypeDef *hdma)
+static void USART_DMAError(DMA_HandleTypeDef *hdma)
{
+ uint32_t dmarequest = 0x00U;
USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+ husart->RxXferCount = 0x00U;
+ husart->TxXferCount = 0x00U;
+
+ /* Stop USART DMA Tx request if ongoing */
+ dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT);
+ if((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest)
+ {
+ USART_EndTxTransfer(husart);
+ }
+
+ /* Stop USART DMA Rx request if ongoing */
+ dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
+ if((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest)
+ {
+ USART_EndRxTransfer(husart);
+ }
- husart->RxXferCount = 0;
- husart->TxXferCount = 0;
husart->ErrorCode |= HAL_USART_ERROR_DMA;
husart->State= HAL_USART_STATE_READY;
-
+
HAL_USART_ErrorCallback(husart);
}
/**
* @brief This function handles USART Communication Timeout.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @param Flag: specifies the USART flag to check.
* @param Status: The new Flag status (SET or RESET).
- * @param Timeout: Timeout duration
+ * @param Tickstart: Tick start value.
+ * @param Timeout: Timeout duration.
* @retval HAL status
*/
-static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
+static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
{
- uint32_t tickstart = 0;
-
- /* Get tick */
- tickstart = HAL_GetTick();
-
/* Wait until flag is set */
- if(Status == RESET)
+ while((__HAL_USART_GET_FLAG(husart, Flag) ? SET : RESET) == Status)
{
- while(__HAL_USART_GET_FLAG(husart, Flag) == RESET)
+ /* Check for the Timeout */
+ if(Timeout != HAL_MAX_DELAY)
{
- /* Check for the Timeout */
- if(Timeout != HAL_MAX_DELAY)
+ if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
{
- if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
- {
/* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
__HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
__HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
__HAL_USART_DISABLE_IT(husart, USART_IT_PE);
__HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
- husart->State= HAL_USART_STATE_READY;
+ husart->State= HAL_USART_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(husart);
+ /* Process Unlocked */
+ __HAL_UNLOCK(husart);
- return HAL_TIMEOUT;
- }
+ return HAL_TIMEOUT;
}
}
}
- else
+ return HAL_OK;
+}
+
+/**
+ * @brief End ongoing Tx transfer on USART peripheral (following error detection or Transmit completion).
+ * @param husart: USART handle.
+ * @retval None
+ */
+static void USART_EndTxTransfer(USART_HandleTypeDef *husart)
+{
+ /* Disable TXEIE and TCIE interrupts */
+ CLEAR_BIT(husart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
+
+ /* At end of Tx process, restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
+}
+
+/**
+ * @brief End ongoing Rx transfer on USART peripheral (following error detection or Reception completion).
+ * @param husart: USART handle.
+ * @retval None
+ */
+static void USART_EndRxTransfer(USART_HandleTypeDef *husart)
+{
+ /* Disable RXNE, PE and ERR interrupts */
+ CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
+
+ /* At end of Rx process, restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
+}
+
+/**
+ * @brief DMA USART communication abort callback, when initiated by HAL services on Error
+ * (To be called at end of DMA Abort procedure following error occurrence).
+ * @param hdma DMA handle.
+ * @retval None
+ */
+static void USART_DMAAbortOnError(DMA_HandleTypeDef *hdma)
+{
+ USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+ husart->RxXferCount = 0x00U;
+ husart->TxXferCount = 0x00U;
+
+ HAL_USART_ErrorCallback(husart);
+}
+
+/**
+ * @brief DMA USART Tx communication abort callback, when initiated by user
+ * (To be called at end of DMA Tx Abort procedure following user abort request).
+ * @note When this callback is executed, User Abort complete call back is called only if no
+ * Abort still ongoing for Rx DMA Handle.
+ * @param hdma DMA handle.
+ * @retval None
+ */
+static void USART_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
+{
+ USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+
+ husart->hdmatx->XferAbortCallback = NULL;
+
+ /* Check if an Abort process is still ongoing */
+ if(husart->hdmarx != NULL)
{
- while(__HAL_USART_GET_FLAG(husart, Flag) != RESET)
+ if(husart->hdmarx->XferAbortCallback != NULL)
{
- /* Check for the Timeout */
- if(Timeout != HAL_MAX_DELAY)
- {
- if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
- {
- /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
- __HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
- __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
- __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
- __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
+ return;
+ }
+ }
+
+ /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
+ husart->TxXferCount = 0x00U;
+ husart->RxXferCount = 0x00U;
- husart->State= HAL_USART_STATE_READY;
+ /* Reset errorCode */
+ husart->ErrorCode = HAL_USART_ERROR_NONE;
- /* Process Unlocked */
- __HAL_UNLOCK(husart);
+ /* Restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
- return HAL_TIMEOUT;
- }
- }
+ /* Call user Abort complete callback */
+ HAL_USART_AbortCpltCallback(husart);
+}
+
+/**
+ * @brief DMA USART Rx communication abort callback, when initiated by user
+ * (To be called at end of DMA Rx Abort procedure following user abort request).
+ * @note When this callback is executed, User Abort complete call back is called only if no
+ * Abort still ongoing for Tx DMA Handle.
+ * @param hdma DMA handle.
+ * @retval None
+ */
+static void USART_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
+{
+ USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
+
+ husart->hdmarx->XferAbortCallback = NULL;
+
+ /* Check if an Abort process is still ongoing */
+ if(husart->hdmatx != NULL)
+ {
+ if(husart->hdmatx->XferAbortCallback != NULL)
+ {
+ return;
}
}
- return HAL_OK;
+
+ /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
+ husart->TxXferCount = 0x00U;
+ husart->RxXferCount = 0x00U;
+
+ /* Reset errorCode */
+ husart->ErrorCode = HAL_USART_ERROR_NONE;
+
+ /* Restore husart->State to Ready */
+ husart->State = HAL_USART_STATE_READY;
+
+ /* Call user Abort complete callback */
+ HAL_USART_AbortCpltCallback(husart);
}
/**
- * @brief Simplex Send an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Simplex Send an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
* @note The USART errors are not managed to avoid the overrun error.
*/
static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
{
- uint16_t* tmp=0;
-
+ uint16_t* tmp;
+
if(husart->State == HAL_USART_STATE_BUSY_TX)
{
if(husart->Init.WordLength == USART_WORDLENGTH_9B)
@@ -1595,24 +2013,24 @@ static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
WRITE_REG(husart->Instance->DR, (uint16_t)(*tmp & (uint16_t)0x01FF));
if(husart->Init.Parity == USART_PARITY_NONE)
{
- husart->pTxBuffPtr += 2;
+ husart->pTxBuffPtr += 2U;
}
else
{
- husart->pTxBuffPtr += 1;
+ husart->pTxBuffPtr += 1U;
}
- }
+ }
else
- {
+ {
WRITE_REG(husart->Instance->DR, (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)0x00FF));
}
-
- if(--husart->TxXferCount == 0)
+
+ if(--husart->TxXferCount == 0U)
{
/* Disable the USART Transmit data register empty Interrupt */
__HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
- /* Enable the USART Transmit Complete Interrupt */
+ /* Enable the USART Transmit Complete Interrupt */
__HAL_USART_ENABLE_IT(husart, USART_IT_TC);
}
return HAL_OK;
@@ -1623,7 +2041,6 @@ static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
}
}
-
/**
* @brief Wraps up transmission in non blocking mode.
* @param husart: pointer to a USART_HandleTypeDef structure that contains
@@ -1632,29 +2049,28 @@ static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
*/
static HAL_StatusTypeDef USART_EndTransmit_IT(USART_HandleTypeDef *husart)
{
- /* Disable the USART Transmit Complete Interrupt */
+ /* Disable the USART Transmit Complete Interrupt */
__HAL_USART_DISABLE_IT(husart, USART_IT_TC);
-
+
/* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
__HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
-
+
husart->State = HAL_USART_STATE_READY;
-
+
HAL_USART_TxCpltCallback(husart);
-
+
return HAL_OK;
}
-
/**
- * @brief Simplex Receive an amount of data in non-blocking mode.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Simplex Receive an amount of data in non-blocking mode.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart)
{
- uint16_t* tmp=0;
+ uint16_t* tmp;
if(husart->State == HAL_USART_STATE_BUSY_RX)
{
if(husart->Init.WordLength == USART_WORDLENGTH_9B)
@@ -1663,19 +2079,19 @@ static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart)
if(husart->Init.Parity == USART_PARITY_NONE)
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
- husart->pRxBuffPtr += 2;
+ husart->pRxBuffPtr += 2U;
}
else
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x00FF);
- husart->pRxBuffPtr += 1;
+ husart->pRxBuffPtr += 1U;
}
- if(--husart->RxXferCount != 0x00)
+ if(--husart->RxXferCount != 0x00U)
{
/* Send dummy byte in order to generate the clock for the slave to send the next data */
WRITE_REG(husart->Instance->DR, (DUMMY_DATA & (uint16_t)0x01FF));
}
- }
+ }
else
{
if(husart->Init.Parity == USART_PARITY_NONE)
@@ -1687,50 +2103,50 @@ static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart)
*husart->pRxBuffPtr++ = (uint8_t)(husart->Instance->DR & (uint8_t)0x007F);
}
- if(--husart->RxXferCount != 0x00)
+ if(--husart->RxXferCount != 0x00U)
{
/* Send dummy byte in order to generate the clock for the slave to send the next data */
WRITE_REG(husart->Instance->DR, (DUMMY_DATA & (uint16_t)0x00FF));
}
}
- if(husart->RxXferCount == 0)
+ if(husart->RxXferCount == 0U)
{
/* Disable the USART RXNE Interrupt */
- __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
/* Disable the USART Parity Error Interrupt */
- __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
/* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
- __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
HAL_USART_RxCpltCallback(husart);
-
+
return HAL_OK;
}
return HAL_OK;
}
else
{
- return HAL_BUSY;
+ return HAL_BUSY;
}
}
/**
- * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval HAL status
*/
static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
{
- uint16_t* tmp=0;
+ uint16_t* tmp;
if(husart->State == HAL_USART_STATE_BUSY_TX_RX)
{
- if(husart->TxXferCount != 0x00)
+ if(husart->TxXferCount != 0x00U)
{
if(__HAL_USART_GET_FLAG(husart, USART_FLAG_TXE) != RESET)
{
@@ -1740,13 +2156,13 @@ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
WRITE_REG(husart->Instance->DR, (uint16_t)(*tmp & (uint16_t)0x01FF));
if(husart->Init.Parity == USART_PARITY_NONE)
{
- husart->pTxBuffPtr += 2;
+ husart->pTxBuffPtr += 2U;
}
else
{
- husart->pTxBuffPtr += 1;
+ husart->pTxBuffPtr += 1U;
}
- }
+ }
else
{
WRITE_REG(husart->Instance->DR, (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)0x00FF));
@@ -1754,14 +2170,14 @@ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
husart->TxXferCount--;
/* Check the latest data transmitted */
- if(husart->TxXferCount == 0)
+ if(husart->TxXferCount == 0U)
{
- __HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
}
}
}
- if(husart->RxXferCount != 0x00)
+ if(husart->RxXferCount != 0x00U)
{
if(__HAL_USART_GET_FLAG(husart, USART_FLAG_RXNE) != RESET)
{
@@ -1771,14 +2187,14 @@ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
if(husart->Init.Parity == USART_PARITY_NONE)
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
- husart->pRxBuffPtr += 2;
+ husart->pRxBuffPtr += 2U;
}
else
{
*tmp = (uint16_t)(husart->Instance->DR & (uint16_t)0x00FF);
- husart->pRxBuffPtr += 1;
+ husart->pRxBuffPtr += 1U;
}
- }
+ }
else
{
if(husart->Init.Parity == USART_PARITY_NONE)
@@ -1795,15 +2211,16 @@ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
}
/* Check the latest data received */
- if(husart->RxXferCount == 0)
+ if(husart->RxXferCount == 0U)
{
- __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
+ /* Disable the USART RXNE Interrupt */
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
/* Disable the USART Parity Error Interrupt */
- __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
+ CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
/* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
- __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
+ CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
@@ -1816,13 +2233,13 @@ static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
}
else
{
- return HAL_BUSY;
+ return HAL_BUSY;
}
}
/**
- * @brief Configures the USART peripheral.
- * @param husart: Pointer to a USART_HandleTypeDef structure that contains
+ * @brief Configures the USART pferipheral.
+ * @param husart: pointer to a USART_HandleTypeDef structure that contains
* the configuration information for the specified USART module.
* @retval None
*/