未验证 提交 47fa1d92 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #3095 from armink/fix_serial

Fix serial
...@@ -582,8 +582,7 @@ static rt_err_t imxrt_configure(struct rt_serial_device *serial, struct serial_c ...@@ -582,8 +582,7 @@ static rt_err_t imxrt_configure(struct rt_serial_device *serial, struct serial_c
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL); RT_ASSERT(cfg != RT_NULL);
uart = (struct imxrt_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct imxrt_uart, serial);
RT_ASSERT(uart != RT_NULL);
LPUART_GetDefaultConfig(&config); LPUART_GetDefaultConfig(&config);
config.baudRate_Bps = cfg->baud_rate; config.baudRate_Bps = cfg->baud_rate;
...@@ -635,8 +634,7 @@ static rt_err_t imxrt_control(struct rt_serial_device *serial, int cmd, void *ar ...@@ -635,8 +634,7 @@ static rt_err_t imxrt_control(struct rt_serial_device *serial, int cmd, void *ar
struct imxrt_uart *uart; struct imxrt_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct imxrt_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct imxrt_uart, serial);
RT_ASSERT(uart != RT_NULL);
#if defined(RT_SERIAL_USING_DMA) && defined(BSP_USING_DMA) #if defined(RT_SERIAL_USING_DMA) && defined(BSP_USING_DMA)
rt_ubase_t ctrl_arg = (rt_ubase_t)arg; rt_ubase_t ctrl_arg = (rt_ubase_t)arg;
...@@ -677,8 +675,7 @@ static int imxrt_putc(struct rt_serial_device *serial, char ch) ...@@ -677,8 +675,7 @@ static int imxrt_putc(struct rt_serial_device *serial, char ch)
struct imxrt_uart *uart; struct imxrt_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct imxrt_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct imxrt_uart, serial);
RT_ASSERT(uart != RT_NULL);
LPUART_WriteByte(uart->uart_base, ch); LPUART_WriteByte(uart->uart_base, ch);
while (!(LPUART_GetStatusFlags(uart->uart_base) & kLPUART_TxDataRegEmptyFlag)); while (!(LPUART_GetStatusFlags(uart->uart_base) & kLPUART_TxDataRegEmptyFlag));
...@@ -692,8 +689,7 @@ static int imxrt_getc(struct rt_serial_device *serial) ...@@ -692,8 +689,7 @@ static int imxrt_getc(struct rt_serial_device *serial)
struct imxrt_uart *uart; struct imxrt_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct imxrt_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct imxrt_uart, serial);
RT_ASSERT(uart != RT_NULL);
ch = -1; ch = -1;
if (LPUART_GetStatusFlags(uart->uart_base) & kLPUART_RxDataRegFullFlag) if (LPUART_GetStatusFlags(uart->uart_base) & kLPUART_RxDataRegFullFlag)
...@@ -712,7 +708,7 @@ rt_size_t dma_tx_xfer(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_ ...@@ -712,7 +708,7 @@ rt_size_t dma_tx_xfer(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_
rt_size_t xfer_size = 0; rt_size_t xfer_size = 0;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct imxrt_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct imxrt_uart, serial);
if (0 != size) if (0 != size)
{ {
...@@ -760,7 +756,7 @@ int rt_hw_uart_init(void) ...@@ -760,7 +756,7 @@ int rt_hw_uart_init(void)
uarts[i].serial.ops = &imxrt_uart_ops; uarts[i].serial.ops = &imxrt_uart_ops;
uarts[i].serial.config = config; uarts[i].serial.config = config;
ret = rt_hw_serial_register(&uarts[i].serial, uarts[i].name, flag | uarts[i].dma_flag, (void *)&uarts[i]); ret = rt_hw_serial_register(&uarts[i].serial, uarts[i].name, flag | uarts[i].dma_flag, NULL);
} }
return ret; return ret;
......
...@@ -98,8 +98,8 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c ...@@ -98,8 +98,8 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
struct stm32_uart *uart; struct stm32_uart *uart;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL); RT_ASSERT(cfg != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL); uart = rt_container_of(serial, struct stm32_uart, serial);
uart->handle.Instance = uart->config->Instance; uart->handle.Instance = uart->config->Instance;
uart->handle.Init.BaudRate = cfg->baud_rate; uart->handle.Init.BaudRate = cfg->baud_rate;
...@@ -162,8 +162,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar ...@@ -162,8 +162,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar
#endif #endif
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = (struct stm32_uart *)serial->parent.user_data; uart = rt_container_of(serial, struct stm32_uart, serial);
RT_ASSERT(uart != RT_NULL);
switch (cmd) switch (cmd)
{ {
...@@ -196,7 +195,7 @@ static int stm32_putc(struct rt_serial_device *serial, char c) ...@@ -196,7 +195,7 @@ 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 = rt_container_of(serial, struct stm32_uart, serial);
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC);
#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \ #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7)
...@@ -213,8 +212,7 @@ static int stm32_getc(struct rt_serial_device *serial) ...@@ -213,8 +212,7 @@ static int stm32_getc(struct rt_serial_device *serial)
int ch; int ch;
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 = rt_container_of(serial, struct stm32_uart, serial);
RT_ASSERT(uart != RT_NULL);
ch = -1; ch = -1;
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET)
...@@ -233,8 +231,7 @@ static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t ...@@ -233,8 +231,7 @@ static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t
{ {
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 = rt_container_of(serial, struct stm32_uart, serial);
RT_ASSERT(uart != RT_NULL);
if (size == 0) if (size == 0)
{ {
...@@ -278,9 +275,7 @@ static void uart_isr(struct rt_serial_device *serial) ...@@ -278,9 +275,7 @@ static void uart_isr(struct rt_serial_device *serial)
#endif #endif
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct stm32_uart, serial);
uart = (struct stm32_uart *) serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
/* UART in mode Receiver -------------------------------------------------*/ /* UART in mode Receiver -------------------------------------------------*/
if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) && if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) &&
...@@ -368,9 +363,7 @@ static void dma_isr(struct rt_serial_device *serial) ...@@ -368,9 +363,7 @@ static void dma_isr(struct rt_serial_device *serial)
rt_base_t level; rt_base_t level;
RT_ASSERT(serial != RT_NULL); RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct stm32_uart, serial);
uart = (struct stm32_uart *) serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
if ((__HAL_DMA_GET_IT_SOURCE(&(uart->dma_rx.handle), DMA_IT_TC) != RESET) || if ((__HAL_DMA_GET_IT_SOURCE(&(uart->dma_rx.handle), DMA_IT_TC) != RESET) ||
(__HAL_DMA_GET_IT_SOURCE(&(uart->dma_rx.handle), DMA_IT_HT) != RESET)) (__HAL_DMA_GET_IT_SOURCE(&(uart->dma_rx.handle), DMA_IT_HT) != RESET))
...@@ -727,8 +720,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) ...@@ -727,8 +720,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
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 = rt_container_of(serial, struct stm32_uart, serial);
RT_ASSERT(uart != RT_NULL);
if (RT_DEVICE_FLAG_DMA_RX == flag) if (RT_DEVICE_FLAG_DMA_RX == flag)
{ {
...@@ -989,7 +981,7 @@ int rt_hw_usart_init(void) ...@@ -989,7 +981,7 @@ int rt_hw_usart_init(void)
| RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_TX
| uart_obj[i].uart_dma_flag | uart_obj[i].uart_dma_flag
, &uart_obj[i]); , NULL);
RT_ASSERT(result == RT_EOK); RT_ASSERT(result == RT_EOK);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册