[stm32 drv usart] 修复串口发送第一个字节丢失的问题。| Fixed a problem where the first byte of a serial port was lost.

This commit is contained in:
BalanceTWK 2018-12-06 15:04:36 +08:00
parent 73d39e89ec
commit f375486e49
13 changed files with 24 additions and 12 deletions

View File

@ -97,8 +97,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while (!(uart->uart_device->ISR & USART_FLAG_TXE));
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
uart->uart_device->TDR = c;
while (!(uart->uart_device->ISR & USART_FLAG_TC));
return 1;
}

View File

@ -124,6 +124,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
uart->uart_device->DR = c;
while (!(uart->uart_device->SR & USART_FLAG_TC));

View File

@ -113,8 +113,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
struct stm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while (__HAL_UART_GET_FLAG(&uart->huart, UART_FLAG_TXE) == RESET);
__HAL_UART_CLEAR_FLAG(&(uart->huart), UART_FLAG_TC);
uart->huart.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->huart), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -166,8 +166,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while (!(uart->uart_device->SR & USART_FLAG_TXE));
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
uart->uart_device->DR = c;
while (!(uart->uart_device->SR & USART_FLAG_TC));
return 1;
}

View File

@ -155,8 +155,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data;
while((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -122,8 +122,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
struct drv_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data;
while ((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -106,7 +106,7 @@ static int drv_putc(struct rt_serial_device *serial, char c)
struct drv_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data;
while ((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->TDR = c;
return 1;
}

View File

@ -138,8 +138,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while (!(uart->UartHandle.Instance->ISR & UART_FLAG_TXE));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
while((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}

View File

@ -141,8 +141,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
uart = (struct drv_uart *)serial->parent.user_data;
while ((__HAL_UART_GET_FLAG(&uart->UartHandle, UART_FLAG_TXE) == RESET));
__HAL_UART_CLEAR_FLAG(&(uart->UartHandle), UART_FLAG_TC);
uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1;
}