在stm32f1xx_hal_uart.c文件下修改
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Receives an amount of data in non blocking mode
* @param huart: Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @retval HAL status
*/
//---------------------------------------------------------------------------------
uint16_t flag,Rx_Size;
//---------------------------------------------------------------------------------
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
{
uint16_t* tmp;
uint32_t tmp_state = 0;
tmp_state = huart->State;
if((tmp_state == HAL_UART_STATE_BUSY_RX) || (tmp_state == 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);
//--------------------------------STA-------------------------------------------------
if(flag == 100)
{
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x05)Rx_Size=1;
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x06)Rx_Size=0;
flag = 101;
}
else if(flag < 100) Rx_Size =0;
if(huart->RxXferCount ==15)
{
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x1A) flag += 10;
else Rx_Size =255;
}
if(huart->RxXferCount ==14)
{
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x5A) flag += 20;
else Rx_Size =255;
}
if(huart->RxXferCount ==11)
{
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x04) flag += 30;
else Rx_Size =255;
}
if(huart->RxXferCount ==9)
{
if(((uint8_t)(huart->Instance->DR & (uint8_t)0x00FF))==0x00) flag += 40;
else Rx_Size =255;
}
//---------------------------------END------------------------------------------------
}
else
{
*huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
}
}
if(--huart->RxXferCount == Rx_Size || Rx_Size == 255)//-------------------------
{
__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;
}
//---------------------------------------------------------------------------------
flag = 0; ////////////////
Rx_Size = 0; //////////////
//---------------------------------------------------------------------------------
HAL_UART_RxCpltCallback(huart);
return HAL_OK;
}
return HAL_OK;
}
else
{
return HAL_BUSY;
}
}
|