以下也是对库函数的改动
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
{
uint16_t* tmp;
uint32_t tmp1 = 0;
tmp1 = huart->State;
if((tmp1 == HAL_UART_STATE_BUSY_RX) || (tmp1 == HAL_UART_STATE_BUSY_TX_RX))
{
if(huart->Init.WordLength == UART_WORDLENGTH_9B)
{
tmp = (uint16_t*) huart->pRxBuffPtr;
if(huart->Init.Parity == UART_PARITY_NONE)
{
*tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
huart->pRxBuffPtr += 2;
}
else
{
*tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
huart->pRxBuffPtr += 1;
}
}
else
{
if(huart->Init.Parity == UART_PARITY_NONE)
{
*huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
}
else
{
*huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
}
}
if(--huart->RxXferCount == 0)
{
// __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
// /* Check if a transmit process is ongoing or not */
// if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
// {
// huart->State = HAL_UART_STATE_BUSY_TX;
// }
// else
// {
// /* Disable the UART Parity Error Interrupt */
// __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
// /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
// __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
// huart->State = HAL_UART_STATE_READY;
// }
// HAL_UART_RxCpltCallback(huart);
/*以上注释掉的为原库代码,以下两行为用户添加的代码,
* 修改后,接受缓存为环形缓存。
*/
huart->RxXferCount = huart->RxXferSize;//用户修改,非原库代码
huart->pRxBuffPtr -= huart->RxXferSize;//用户修改,非原库代码
return HAL_OK;
}
return HAL_OK;
}
else
{
return HAL_BUSY;
}
} |