提交 fe6cf948 编写于 作者: armink_ztl's avatar armink_ztl

[bsp/stm32] Remove the use of device user data on uart driver.

上级 4d638390
...@@ -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.
先完成此消息的编辑!
想要评论请 注册