未验证 提交 94e6c349 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #2039 from balanceTWK/master

[bsp/stm32 uart drivers] 修复串口驱动 | Fixed serial port drivers
...@@ -97,8 +97,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -97,8 +97,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->uart_device->TDR = c;
while (!(uart->uart_device->ISR & USART_FLAG_TC));
return 1; return 1;
} }
......
...@@ -124,6 +124,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -124,6 +124,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; uart = (struct stm32_uart *)serial->parent.user_data;
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
uart->uart_device->DR = c; uart->uart_device->DR = c;
while (!(uart->uart_device->SR & USART_FLAG_TC)); while (!(uart->uart_device->SR & USART_FLAG_TC));
......
...@@ -113,8 +113,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -113,8 +113,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
struct stm32_uart *uart; struct stm32_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->huart.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->huart), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -100,8 +100,6 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c ...@@ -100,8 +100,6 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
/* Enable USART */ /* Enable USART */
USART_Cmd(uart->uart_device, ENABLE); USART_Cmd(uart->uart_device, ENABLE);
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
return RT_EOK; return RT_EOK;
} }
...@@ -159,6 +157,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -159,6 +157,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
} }
else else
{ {
USART_ClearFlag(uart->uart_device,USART_FLAG_TC);
uart->uart_device->DR = c; uart->uart_device->DR = c;
while (!(uart->uart_device->SR & USART_FLAG_TC)); while (!(uart->uart_device->SR & USART_FLAG_TC));
} }
......
...@@ -166,8 +166,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -166,8 +166,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->uart_device->DR = c;
while (!(uart->uart_device->SR & USART_FLAG_TC));
return 1; return 1;
} }
......
...@@ -155,8 +155,9 @@ static int drv_putc(struct rt_serial_device *serial, char c) ...@@ -155,8 +155,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -122,8 +122,9 @@ static int drv_putc(struct rt_serial_device *serial, char c) ...@@ -122,8 +122,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
struct drv_uart *uart; struct drv_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->DR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -106,7 +106,7 @@ static int drv_putc(struct rt_serial_device *serial, char c) ...@@ -106,7 +106,7 @@ static int drv_putc(struct rt_serial_device *serial, char c)
struct drv_uart *uart; struct drv_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct drv_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->TDR = c;
return 1; return 1;
} }
......
...@@ -138,8 +138,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -138,8 +138,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -185,8 +185,9 @@ static int stm32_putc(struct rt_serial_device *serial, char c)
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
...@@ -141,8 +141,9 @@ static int drv_putc(struct rt_serial_device *serial, char c) ...@@ -141,8 +141,9 @@ static int drv_putc(struct rt_serial_device *serial, char c)
uart = (struct drv_uart *)serial->parent.user_data; 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; uart->UartHandle.Instance->TDR = c;
while (__HAL_UART_GET_FLAG(&(uart->UartHandle), UART_FLAG_TC) == RESET);
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册