提交 f375486e 编写于 作者: B BalanceTWK

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

[stm32 drv usart] 修复串口发送第一个字节丢失的问题。| Fixed a problem where the first byte of a serial port was lost.
上级 73d39e89
......@@ -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;
}
......
......@@ -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));
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册