[HAL][UART] Remove __HAL_LOCK() and __HAL_UNLOCK() invocation from Tx and Rx APIs
Rationale: To avoid any dead lock in case of a concurrent access if both DMA Tx and IT Rx are simultaneously used, for instance.
diff --git a/Src/stm32f4xx_hal_uart.c b/Src/stm32f4xx_hal_uart.c
index 043bf7a..e2af538 100644
--- a/Src/stm32f4xx_hal_uart.c
+++ b/Src/stm32f4xx_hal_uart.c
@@ -1152,9 +1152,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
@@ -1176,9 +1173,6 @@
pdata16bits = NULL;
}
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
while (huart->TxXferCount > 0U)
{
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
@@ -1240,9 +1234,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
@@ -1265,9 +1256,6 @@
pdata16bits = NULL;
}
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
/* Check the remain data to be received */
while (huart->RxXferCount > 0U)
{
@@ -1327,9 +1315,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
huart->pTxBuffPtr = pData;
huart->TxXferSize = Size;
huart->TxXferCount = Size;
@@ -1337,9 +1322,6 @@
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
/* Enable the UART Transmit data register empty Interrupt */
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
@@ -1372,9 +1354,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
/* Set Reception type to Standard reception */
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
@@ -1409,9 +1388,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
huart->pTxBuffPtr = pData;
huart->TxXferSize = Size;
huart->TxXferCount = Size;
@@ -1438,9 +1414,6 @@
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC);
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
/* Enable the DMA transfer for transmit request by setting the DMAT bit
in the UART CR3 register */
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAT);
@@ -1475,9 +1448,6 @@
return HAL_ERROR;
}
- /* Process Locked */
- __HAL_LOCK(huart);
-
/* Set Reception type to Standard reception */
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
@@ -1499,9 +1469,6 @@
{
uint32_t dmarequest = 0x00U;
- /* Process Locked */
- __HAL_LOCK(huart);
-
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
{
@@ -1520,9 +1487,6 @@
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
}
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
return HAL_OK;
}
@@ -1534,8 +1498,6 @@
*/
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
{
- /* Process Locked */
- __HAL_LOCK(huart);
if (huart->gState == HAL_UART_STATE_BUSY_TX)
{
@@ -1559,9 +1521,6 @@
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
}
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
return HAL_OK;
}
@@ -1641,8 +1600,6 @@
return HAL_ERROR;
}
- __HAL_LOCK(huart);
-
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
@@ -1666,8 +1623,6 @@
pdata16bits = NULL;
}
- __HAL_UNLOCK(huart);
-
/* Initialize output number of received elements */
*RxLen = 0U;
@@ -1767,8 +1722,6 @@
return HAL_ERROR;
}
- __HAL_LOCK(huart);
-
/* Set Reception type to reception till IDLE Event*/
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
huart->RxEventType = HAL_UART_RXEVENT_TC;
@@ -1829,8 +1782,6 @@
return HAL_ERROR;
}
- __HAL_LOCK(huart);
-
/* Set Reception type to reception till IDLE Event*/
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
huart->RxEventType = HAL_UART_RXEVENT_TC;
@@ -3279,9 +3230,6 @@
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
if (huart->Init.Parity != UART_PARITY_NONE)
{
/* Enable the UART Parity Error Interrupt */
@@ -3337,9 +3285,6 @@
/* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
__HAL_UART_CLEAR_OREFLAG(huart);
- /* Process Unlocked */
- __HAL_UNLOCK(huart);
-
if (huart->Init.Parity != UART_PARITY_NONE)
{
/* Enable the UART Parity Error Interrupt */