|
|
@@ -251,6 +251,35 @@ |
|
|
|
* opensource.org/licenses/BSD-3-Clause |
|
|
|
* |
|
|
|
****************************************************************************** |
|
|
|
|
|
|
|
Note, modifications are licensed under: |
|
|
|
* Copyright 2022 John-Mark Gurney. |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* modification, are permitted provided that the following conditions |
|
|
|
* are met: |
|
|
|
* 1. Redistributions of source code must retain the above copyright |
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
|
|
|
* notice, this list of conditions and the following disclaimer in the |
|
|
|
* documentation and/or other materials provided with the distribution. |
|
|
|
* 3. If you are STMicroelectronics N.V., one of it's subsidiaries, a |
|
|
|
* subsidiary of an owner of STMicroelectronics N.V., or an employee, |
|
|
|
* contractor, or agent of any of the preceeding entities, you are not |
|
|
|
* allowed to use this code, in either source or binary forms. |
|
|
|
* |
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
|
|
* SUCH DAMAGE. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
@@ -657,6 +686,19 @@ HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Add |
|
|
|
return HAL_OK; |
|
|
|
} |
|
|
|
|
|
|
|
volatile uint32_t v; |
|
|
|
|
|
|
|
static void |
|
|
|
checkinter(UART_HandleTypeDef *huart) |
|
|
|
{ |
|
|
|
|
|
|
|
#if 1 |
|
|
|
if (huart->ReceptionType == 0 && huart->Instance->CR1 & 0x10) { |
|
|
|
for(;;v++); |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief DeInitializes the UART peripheral. |
|
|
|
* @param huart Pointer to a UART_HandleTypeDef structure that contains |
|
|
@@ -696,6 +738,7 @@ HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart) |
|
|
|
huart->RxState = HAL_UART_STATE_RESET; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
|
|
|
|
checkinter(huart); |
|
|
|
/* Process Unlock */ |
|
|
|
__HAL_UNLOCK(huart); |
|
|
|
|
|
|
@@ -1241,6 +1284,7 @@ HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, ui |
|
|
|
huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
|
|
huart->RxState = HAL_UART_STATE_BUSY_RX; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* Init tickstart for timeout management */ |
|
|
|
tickstart = HAL_GetTick(); |
|
|
@@ -1372,6 +1416,7 @@ HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, |
|
|
|
|
|
|
|
/* Set Reception type to Standard reception */ |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
return(UART_Start_Receive_IT(huart, pData, Size)); |
|
|
|
} |
|
|
@@ -1475,6 +1520,7 @@ HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData |
|
|
|
|
|
|
|
/* Set Reception type to Standard reception */ |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
return(UART_Start_Receive_DMA(huart, pData, Size)); |
|
|
|
} |
|
|
@@ -1935,6 +1981,7 @@ HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart) |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->gState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
return HAL_OK; |
|
|
|
} |
|
|
@@ -2045,6 +2092,7 @@ HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart) |
|
|
|
/* Restore huart->RxState to Ready */ |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
return HAL_OK; |
|
|
|
} |
|
|
@@ -2170,6 +2218,7 @@ HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart) |
|
|
|
huart->gState = HAL_UART_STATE_READY; |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* As no DMA to be aborted, call directly user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -2314,6 +2363,7 @@ HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart) |
|
|
|
/* Restore huart->RxState to Ready */ |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* As no DMA to be aborted, call directly user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -2333,6 +2383,7 @@ HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart) |
|
|
|
/* Restore huart->RxState to Ready */ |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* As no DMA to be aborted, call directly user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -2363,10 +2414,10 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
|
|
|
|
/* If no error occurs */ |
|
|
|
errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); |
|
|
|
if (errorflags == RESET) |
|
|
|
if (errorflags == 0) |
|
|
|
{ |
|
|
|
/* UART in mode Receiver -------------------------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_RXNE) != 0) && ((cr1its & USART_CR1_RXNEIE) != 0)) |
|
|
|
{ |
|
|
|
UART_Receive_IT(huart); |
|
|
|
return; |
|
|
@@ -2374,28 +2425,28 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
} |
|
|
|
|
|
|
|
/* If some errors occur */ |
|
|
|
if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) |
|
|
|
if ((errorflags != 0) && (((cr3its & USART_CR3_EIE) != 0) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != 0))) |
|
|
|
{ |
|
|
|
/* UART parity error interrupt occurred ----------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_PE) != 0) && ((cr1its & USART_CR1_PEIE) != 0)) |
|
|
|
{ |
|
|
|
huart->ErrorCode |= HAL_UART_ERROR_PE; |
|
|
|
} |
|
|
|
|
|
|
|
/* UART noise error interrupt occurred -----------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_NE) != 0) && ((cr3its & USART_CR3_EIE) != 0)) |
|
|
|
{ |
|
|
|
huart->ErrorCode |= HAL_UART_ERROR_NE; |
|
|
|
} |
|
|
|
|
|
|
|
/* UART frame error interrupt occurred -----------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_FE) != 0) && ((cr3its & USART_CR3_EIE) != 0)) |
|
|
|
{ |
|
|
|
huart->ErrorCode |= HAL_UART_ERROR_FE; |
|
|
|
} |
|
|
|
|
|
|
|
/* UART Over-Run interrupt occurred --------------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) |
|
|
|
if (((isrflags & USART_SR_ORE) != 0) && (((cr1its & USART_CR1_RXNEIE) != 0) || ((cr3its & USART_CR3_EIE) != 0))) |
|
|
|
{ |
|
|
|
huart->ErrorCode |= HAL_UART_ERROR_ORE; |
|
|
|
} |
|
|
@@ -2404,7 +2455,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
if (huart->ErrorCode != HAL_UART_ERROR_NONE) |
|
|
|
{ |
|
|
|
/* UART in mode Receiver -----------------------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_RXNE) != 0) && ((cr1its & USART_CR1_RXNEIE) != 0)) |
|
|
|
{ |
|
|
|
UART_Receive_IT(huart); |
|
|
|
} |
|
|
@@ -2412,7 +2463,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
/* If Overrun error occurs, or if any error occurs in DMA mode reception, |
|
|
|
consider error as blocking */ |
|
|
|
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
|
|
|
if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest) |
|
|
|
if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != 0) || dmarequest) |
|
|
|
{ |
|
|
|
/* Blocking error : transfer is aborted |
|
|
|
Set the UART state ready to be able to start again the process, |
|
|
@@ -2517,6 +2568,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
|
|
|
|
CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
|
|
|
|
|
|
|
checkinter(huart); |
|
|
|
/* Last bytes received, so no need as the abort is immediate */ |
|
|
|
(void)HAL_DMA_Abort(huart->hdmarx); |
|
|
|
} |
|
|
@@ -2550,6 +2602,7 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
|
|
|
|
CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
|
|
|
checkinter(huart); |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
|
/*Call registered Rx complete callback*/ |
|
|
|
huart->RxEventCallback(huart, nb_rx_data); |
|
|
@@ -2563,14 +2616,14 @@ void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
|
|
|
} |
|
|
|
|
|
|
|
/* UART in mode Transmitter ------------------------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_TXE) != 0) && ((cr1its & USART_CR1_TXEIE) != 0)) |
|
|
|
{ |
|
|
|
UART_Transmit_IT(huart); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
/* UART in mode Transmitter end --------------------------------------------*/ |
|
|
|
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) |
|
|
|
if (((isrflags & USART_SR_TC) != 0) && ((cr1its & USART_CR1_TCIE) != 0)) |
|
|
|
{ |
|
|
|
UART_EndTransmit_IT(huart); |
|
|
|
return; |
|
|
@@ -3316,6 +3369,7 @@ static void UART_EndRxTransfer(UART_HandleTypeDef *huart) |
|
|
|
/* At end of Rx process, restore huart->RxState to Ready */ |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -3375,6 +3429,7 @@ static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
|
|
|
huart->gState = HAL_UART_STATE_READY; |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* Call user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -3421,6 +3476,7 @@ static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
|
|
|
huart->gState = HAL_UART_STATE_READY; |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* Call user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -3478,6 +3534,7 @@ static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
|
|
|
/* Restore huart->RxState to Ready */ |
|
|
|
huart->RxState = HAL_UART_STATE_READY; |
|
|
|
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
|
|
checkinter(huart); |
|
|
|
|
|
|
|
/* Call user Abort complete callback */ |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
@@ -3615,6 +3672,7 @@ static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) |
|
|
|
/* Disable IDLE interrupt */ |
|
|
|
CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
|
|
|
|
|
|
|
checkinter(huart); |
|
|
|
/* Check if IDLE flag is set */ |
|
|
|
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) |
|
|
|
{ |
|
|
@@ -3622,6 +3680,7 @@ static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) |
|
|
|
__HAL_UART_CLEAR_IDLEFLAG(huart); |
|
|
|
} |
|
|
|
|
|
|
|
checkinter(huart); |
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
|
|
/*Call registered Rx Event callback*/ |
|
|
|
huart->RxEventCallback(huart, huart->RxXferSize); |
|
|
|