From d52a412f4c5d9e5cb968826728cf554942497fdd Mon Sep 17 00:00:00 2001 From: zhouchuanfu <353896039@qq.com> Date: Fri, 3 May 2019 20:52:31 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=B2=E5=8F=A3DMA?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HAL_Drivers/config/f4/dma_config.h | 39 +- .../HAL_Drivers/config/f4/uart_config.h | 182 +++++--- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 412 +++++++++++++----- bsp/stm32/libraries/HAL_Drivers/drv_usart.h | 9 +- .../stm32f407-atk-explorer/board/Kconfig | 66 +++ components/drivers/serial/serial.c | 1 + 6 files changed, 540 insertions(+), 169 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f4/dma_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f4/dma_config.h index 8083c77826..86a2c9380b 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f4/dma_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f4/dma_config.h @@ -64,6 +64,12 @@ extern "C" { #define SPI2_RX_DMA_INSTANCE DMA1_Stream3 #define SPI2_RX_DMA_CHANNEL DMA_CHANNEL_0 #define SPI2_RX_DMA_IRQ DMA1_Stream3_IRQn +#elif defined(BSP_UART3_TX_USING_DMA) && !defined(UART3_TX_DMA_INSTANCE) +#define UART3_DMA_TX_IRQHandler DMA1_Stream3_IRQHandler +#define UART3_TX_DMA_RCC RCC_AHB1ENR_DMA1EN +#define UART3_TX_DMA_INSTANCE DMA1_Stream3 +#define UART3_TX_DMA_CHANNEL DMA_CHANNEL_4 +#define UART3_TX_DMA_IRQ DMA1_Stream3_IRQn #endif /* DMA1 stream4 */ @@ -73,6 +79,12 @@ extern "C" { #define SPI2_TX_DMA_INSTANCE DMA1_Stream4 #define SPI2_TX_DMA_CHANNEL DMA_CHANNEL_0 #define SPI2_TX_DMA_IRQ DMA1_Stream4_IRQn +#elif defined(BSP_UART4_TX_USING_DMA) && !defined(UART4_TX_DMA_INSTANCE) +#define UART4_DMA_TX_IRQHandler DMA1_Stream4_IRQHandler +#define UART4_TX_DMA_RCC RCC_AHB1ENR_DMA1EN +#define UART4_TX_DMA_INSTANCE DMA1_Stream4 +#define UART4_TX_DMA_CHANNEL DMA_CHANNEL_4 +#define UART4_TX_DMA_IRQ DMA1_Stream4_IRQn #endif /* DMA1 stream5 */ @@ -91,6 +103,13 @@ extern "C" { #endif /* DMA1 stream6 */ +#if defined(BSP_UART2_TX_USING_DMA) && !defined(UART2_TX_DMA_INSTANCE) +#define UART2_DMA_TX_IRQHandler DMA1_Stream6_IRQHandler +#define UART2_TX_DMA_RCC RCC_AHB1ENR_DMA1EN +#define UART2_TX_DMA_INSTANCE DMA1_Stream6 +#define UART2_TX_DMA_CHANNEL DMA_CHANNEL_4 +#define UART2_TX_DMA_IRQ DMA1_Stream6_IRQn +#endif /* DMA1 stream7 */ #if defined(BSP_SPI3_TX_USING_DMA) && !defined(SPI3_TX_DMA_INSTANCE) @@ -99,6 +118,12 @@ extern "C" { #define SPI3_TX_DMA_INSTANCE DMA1_Stream7 #define SPI3_TX_DMA_CHANNEL DMA_CHANNEL_0 #define SPI3_TX_DMA_IRQ DMA1_Stream7_IRQn +#elif defined(BSP_UART5_TX_USING_DMA) && !defined(UART5_TX_DMA_INSTANCE) +#define UART5_DMA_TX_IRQHandler DMA1_Stream7_IRQHandler +#define UART5_TX_DMA_RCC RCC_AHB1ENR_DMA1EN +#define UART5_TX_DMA_INSTANCE DMA1_Stream7 +#define UART5_TX_DMA_CHANNEL DMA_CHANNEL_4 +#define UART5_TX_DMA_IRQ DMA1_Stream7_IRQn #endif /* DMA2 stream0 */ @@ -148,7 +173,6 @@ extern "C" { /* DMA2 stream3 */ #if defined(BSP_SPI5_RX_USING_DMA) && !defined(SPI5_RX_DMA_INSTANCE) - #define SPI5_DMA_RX_IRQHandler DMA2_Stream3_IRQHandler #define SPI5_RX_DMA_RCC RCC_AHB1ENR_DMA2EN #define SPI5_RX_DMA_INSTANCE DMA2_Stream3 @@ -211,9 +235,22 @@ extern "C" { #define SPI5_TX_DMA_INSTANCE DMA2_Stream6 #define SPI5_TX_DMA_CHANNEL DMA_CHANNEL_7 #define SPI5_TX_DMA_IRQ DMA2_Stream6_IRQn +#elif defined(BSP_UART6_TX_USING_DMA) && !defined(UART6_TX_DMA_INSTANCE) +#define UART6_DMA_TX_IRQHandler DMA2_Stream6_IRQHandler +#define UART6_TX_DMA_RCC RCC_AHB1ENR_DMA2EN +#define UART6_TX_DMA_INSTANCE DMA2_Stream6 +#define UART6_TX_DMA_CHANNEL DMA_CHANNEL_5 +#define UART6_TX_DMA_IRQ DMA2_Stream6_IRQn #endif /* DMA2 stream7 */ +#if defined(BSP_UART1_TX_USING_DMA) && !defined(UART1_TX_DMA_INSTANCE) +#define UART1_DMA_TX_IRQHandler DMA2_Stream7_IRQHandler +#define UART1_TX_DMA_RCC RCC_AHB1ENR_DMA2EN +#define UART1_TX_DMA_INSTANCE DMA2_Stream7 +#define UART1_TX_DMA_CHANNEL DMA_CHANNEL_4 +#define UART1_TX_DMA_IRQ DMA2_Stream7_IRQn +#endif #ifdef __cplusplus } diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f4/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f4/uart_config.h index 50a7f50b84..6d8655fc2e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f4/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f4/uart_config.h @@ -27,20 +27,32 @@ extern "C" { .irq_type = USART1_IRQn, \ } #endif /* UART1_CONFIG */ -#endif /* BSP_USING_UART1 */ - + #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ - { \ - .Instance = UART1_RX_DMA_INSTANCE, \ - .channel = UART1_RX_DMA_CHANNEL, \ - .dma_rcc = UART1_RX_DMA_RCC, \ - .dma_irq = UART1_RX_DMA_IRQ, \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ + { \ + .Instance = UART1_RX_DMA_INSTANCE, \ + .channel = UART1_RX_DMA_CHANNEL, \ + .dma_rcc = UART1_RX_DMA_RCC, \ + .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ +#if defined(BSP_UART1_TX_USING_DMA) +#ifndef UART1_DMA_TX_CONFIG +#define UART1_DMA_TX_CONFIG \ + { \ + .Instance = UART1_TX_DMA_INSTANCE, \ + .channel = UART1_TX_DMA_CHANNEL, \ + .dma_rcc = UART1_TX_DMA_RCC, \ + .dma_irq = UART1_TX_DMA_IRQ, \ + } +#endif /* UART1_DMA_TX_CONFIG */ +#endif /* BSP_UART1_TX_USING_DMA */ +#endif /* BSP_USING_UART1 */ + #if defined(BSP_USING_UART2) #ifndef UART2_CONFIG #define UART2_CONFIG \ @@ -50,19 +62,31 @@ extern "C" { .irq_type = USART2_IRQn, \ } #endif /* UART2_CONFIG */ -#endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ - { \ - .Instance = UART2_RX_DMA_INSTANCE, \ - .channel = UART2_RX_DMA_CHANNEL, \ - .dma_rcc = UART2_RX_DMA_RCC, \ - .dma_irq = UART2_RX_DMA_IRQ, \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ + { \ + .Instance = UART2_RX_DMA_INSTANCE, \ + .channel = UART2_RX_DMA_CHANNEL, \ + .dma_rcc = UART2_RX_DMA_RCC, \ + .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ + +#if defined(BSP_UART2_TX_USING_DMA) +#ifndef UART2_DMA_TX_CONFIG +#define UART2_DMA_TX_CONFIG \ + { \ + .Instance = UART2_TX_DMA_INSTANCE, \ + .channel = UART2_TX_DMA_CHANNEL, \ + .dma_rcc = UART2_TX_DMA_RCC, \ + .dma_irq = UART2_TX_DMA_IRQ, \ + } +#endif /* UART2_DMA_TX_CONFIG */ +#endif /* BSP_UART2_TX_USING_DMA */ +#endif /* BSP_USING_UART2 */ #if defined(BSP_USING_UART3) #ifndef UART3_CONFIG @@ -73,19 +97,31 @@ extern "C" { .irq_type = USART3_IRQn, \ } #endif /* UART3_CONFIG */ -#endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ - { \ - .Instance = UART3_RX_DMA_INSTANCE, \ - .channel = UART3_RX_DMA_CHANNEL, \ - .dma_rcc = UART3_RX_DMA_RCC, \ - .dma_irq = UART3_RX_DMA_IRQ, \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ + { \ + .Instance = UART3_RX_DMA_INSTANCE, \ + .channel = UART3_RX_DMA_CHANNEL, \ + .dma_rcc = UART3_RX_DMA_RCC, \ + .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ + +#if defined(BSP_UART3_TX_USING_DMA) +#ifndef UART3_DMA_TX_CONFIG +#define UART3_DMA_TX_CONFIG \ + { \ + .Instance = UART3_TX_DMA_INSTANCE, \ + .channel = UART3_TX_DMA_CHANNEL, \ + .dma_rcc = UART3_TX_DMA_RCC, \ + .dma_irq = UART3_TX_DMA_IRQ, \ + } +#endif /* UART3_DMA_TX_CONFIG */ +#endif /* BSP_UART3_TX_USING_DMA */ +#endif /* BSP_USING_UART3 */ #if defined(BSP_USING_UART4) #ifndef UART4_CONFIG @@ -96,20 +132,32 @@ extern "C" { .irq_type = UART4_IRQn, \ } #endif /* UART4_CONFIG */ -#endif /* BSP_USING_UART4 */ #if defined(BSP_UART4_RX_USING_DMA) -#ifndef UART4_DMA_CONFIG -#define UART4_DMA_CONFIG \ - { \ - .Instance = UART4_RX_DMA_INSTANCE, \ - .channel = UART4_RX_DMA_CHANNEL, \ - .dma_rcc = UART4_RX_DMA_RCC, \ - .dma_irq = UART4_RX_DMA_IRQ, \ +#ifndef UART4_DMA_RX_CONFIG +#define UART4_DMA_RX_CONFIG \ + { \ + .Instance = UART4_RX_DMA_INSTANCE, \ + .channel = UART4_RX_DMA_CHANNEL, \ + .dma_rcc = UART4_RX_DMA_RCC, \ + .dma_irq = UART4_RX_DMA_IRQ, \ } -#endif /* UART4_DMA_CONFIG */ +#endif /* UART4_DMA_RX_CONFIG */ #endif /* BSP_UART4_RX_USING_DMA */ +#if defined(BSP_UART4_TX_USING_DMA) +#ifndef UART4_DMA_TX_CONFIG +#define UART4_DMA_TX_CONFIG \ + { \ + .Instance = UART4_TX_DMA_INSTANCE, \ + .channel = UART4_TX_DMA_CHANNEL, \ + .dma_rcc = UART4_TX_DMA_RCC, \ + .dma_irq = UART4_TX_DMA_IRQ, \ + } +#endif /* UART4_DMA_TX_CONFIG */ +#endif /* BSP_UART4_RX_USING_DMA */ +#endif /* BSP_USING_UART4 */ + #if defined(BSP_USING_UART5) #ifndef UART5_CONFIG #define UART5_CONFIG \ @@ -119,19 +167,31 @@ extern "C" { .irq_type = UART5_IRQn, \ } #endif /* UART5_CONFIG */ -#endif /* BSP_USING_UART5 */ #if defined(BSP_UART5_RX_USING_DMA) -#ifndef UART5_DMA_CONFIG -#define UART5_DMA_CONFIG \ - { \ - .Instance = UART5_RX_DMA_INSTANCE, \ - .channel = UART5_RX_DMA_CHANNEL, \ - .dma_rcc = UART5_RX_DMA_RCC, \ - .dma_irq = UART5_RX_DMA_IRQ, \ +#ifndef UART5_DMA_RX_CONFIG +#define UART5_DMA_RX_CONFIG \ + { \ + .Instance = UART5_RX_DMA_INSTANCE, \ + .channel = UART5_RX_DMA_CHANNEL, \ + .dma_rcc = UART5_RX_DMA_RCC, \ + .dma_irq = UART5_RX_DMA_IRQ, \ } -#endif /* UART5_DMA_CONFIG */ +#endif /* UART5_DMA_RX_CONFIG */ #endif /* BSP_UART5_RX_USING_DMA */ + +#if defined(BSP_UART5_TX_USING_DMA) +#ifndef UART5_DMA_TX_CONFIG +#define UART5_DMA_TX_CONFIG \ + { \ + .Instance = UART5_TX_DMA_INSTANCE, \ + .channel = UART5_TX_DMA_CHANNEL, \ + .dma_rcc = UART5_TX_DMA_RCC, \ + .dma_irq = UART5_TX_DMA_IRQ, \ + } +#endif /* UART5_DMA_TX_CONFIG */ +#endif /* BSP_UART5_TX_USING_DMA */ +#endif /* BSP_USING_UART5 */ #if defined(BSP_USING_UART6) #ifndef UART6_CONFIG @@ -142,19 +202,31 @@ extern "C" { .irq_type = USART6_IRQn, \ } #endif /* UART6_CONFIG */ -#endif /* BSP_USING_UART6 */ #if defined(BSP_UART6_RX_USING_DMA) -#ifndef UART6_DMA_CONFIG -#define UART6_DMA_CONFIG \ - { \ - .Instance = UART6_RX_DMA_INSTANCE, \ - .channel = UART6_RX_DMA_CHANNEL, \ - .dma_rcc = UART6_RX_DMA_RCC, \ - .dma_irq = UART6_RX_DMA_IRQ, \ +#ifndef UART6_DMA_RX_CONFIG +#define UART6_DMA_RX_CONFIG \ + { \ + .Instance = UART6_RX_DMA_INSTANCE, \ + .channel = UART6_RX_DMA_CHANNEL, \ + .dma_rcc = UART6_RX_DMA_RCC, \ + .dma_irq = UART6_RX_DMA_IRQ, \ } -#endif /* UART6_DMA_CONFIG */ +#endif /* UART6_DMA_RX_CONFIG */ #endif /* BSP_UART6_RX_USING_DMA */ + +#if defined(BSP_UART6_TX_USING_DMA) +#ifndef UART6_DMA_TX_CONFIG +#define UART6_DMA_TX_CONFIG \ + { \ + .Instance = UART6_TX_DMA_INSTANCE, \ + .channel = UART6_TX_DMA_CHANNEL, \ + .dma_rcc = UART6_TX_DMA_RCC, \ + .dma_irq = UART6_TX_DMA_IRQ, \ + } +#endif /* UART6_DMA_TX_CONFIG */ +#endif /* BSP_UART6_TX_USING_DMA */ +#endif /* BSP_USING_UART6 */ #ifdef __cplusplus } diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index a1379f8a01..ff438e2554 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -7,7 +7,7 @@ * Date Author Notes * 2018-10-30 SummerGift first version */ - + #include "board.h" #include "drv_usart.h" #include "drv_config.h" @@ -20,12 +20,12 @@ #if !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2) && !defined(BSP_USING_UART3) \ && !defined(BSP_USING_UART4) && !defined(BSP_USING_UART5) && !defined(BSP_USING_UART6) && !defined(BSP_USING_LPUART1) -#error "Please define at least one BSP_USING_UARTx" -/* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */ + #error "Please define at least one BSP_USING_UARTx" + /* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */ #endif #ifdef RT_SERIAL_USING_DMA -static void stm32_dma_config(struct rt_serial_device *serial); + static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag); #endif enum @@ -56,25 +56,25 @@ enum static struct stm32_uart_config uart_config[] = { #ifdef BSP_USING_UART1 - UART1_CONFIG, + UART1_CONFIG, #endif #ifdef BSP_USING_UART2 - UART2_CONFIG, + UART2_CONFIG, #endif #ifdef BSP_USING_UART3 - UART3_CONFIG, + UART3_CONFIG, #endif #ifdef BSP_USING_UART4 - UART4_CONFIG, + UART4_CONFIG, #endif #ifdef BSP_USING_UART5 - UART5_CONFIG, + UART5_CONFIG, #endif #ifdef BSP_USING_UART6 - UART6_CONFIG, + UART6_CONFIG, #endif #ifdef BSP_USING_LPUART1 - LPUART1_CONFIG, + LPUART1_CONFIG, #endif }; @@ -147,7 +147,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar #ifdef RT_SERIAL_USING_DMA rt_ubase_t ctrl_arg = (rt_ubase_t)arg; #endif - + RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); @@ -171,10 +171,7 @@ static rt_err_t stm32_control(struct rt_serial_device *serial, int cmd, void *ar #ifdef RT_SERIAL_USING_DMA case RT_DEVICE_CTRL_CONFIG: - if (ctrl_arg == RT_DEVICE_FLAG_DMA_RX) - { - stm32_dma_config(serial); - } + stm32_dma_config(serial, ctrl_arg); break; #endif } @@ -219,12 +216,37 @@ static int stm32_getc(struct rt_serial_device *serial) return ch; } +static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction) +{ + struct stm32_uart *uart; + RT_ASSERT(serial != RT_NULL); + uart = (struct stm32_uart *)(serial->parent.user_data); + RT_ASSERT(uart != RT_NULL); + if (size == 0) + { + return 0; + } + if (RT_SERIAL_DMA_TX == direction) + { + if (HAL_UART_Transmit_DMA(&uart->handle, buf, size) == HAL_OK) + { + return size; + } + else + { + return 0; + } + } + return 0; +} + static const struct rt_uart_ops stm32_uart_ops = { .configure = stm32_configure, .control = stm32_control, .putc = stm32_putc, .getc = stm32_getc, + .dma_transmit = stm32_dma_transmit }; /** @@ -239,26 +261,26 @@ static void uart_isr(struct rt_serial_device *serial) rt_size_t recv_total_index, recv_len; rt_base_t level; #endif - + RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); /* UART in mode Receiver -------------------------------------------------*/ - if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) && - (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET)) + if ((__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_RXNE) != RESET) + && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_RXNE) != RESET)) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); } #ifdef RT_SERIAL_USING_DMA - else if ((uart->uart_dma_flag) && (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_IDLE) != RESET) && - (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET)) + else if ((uart->uart_dma_flag) && (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_IDLE) != RESET) + && (__HAL_UART_GET_IT_SOURCE(&(uart->handle), UART_IT_IDLE) != RESET)) { level = rt_hw_interrupt_disable(); - recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma.handle)); - recv_len = recv_total_index - uart->dma.last_index; - uart->dma.last_index = recv_total_index; + recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma_rx.handle)); + recv_len = recv_total_index - uart->dma_rx.last_index; + uart->dma_rx.last_index = recv_total_index; rt_hw_interrupt_enable(level); if (recv_len) @@ -267,6 +289,17 @@ static void uart_isr(struct rt_serial_device *serial) } __HAL_UART_CLEAR_IDLEFLAG(&uart->handle); } + else if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) != RESET) + { + if ((serial->parent.open_flag & RT_DEVICE_FLAG_DMA_TX) != 0) + { + HAL_UART_IRQHandler(&(uart->handle)); + } + else + { + UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC); + } + } #endif else { @@ -319,7 +352,7 @@ void USART1_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[UART1_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -329,12 +362,24 @@ void UART1_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART1_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART1_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART1_RX_USING_DMA) */ +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART1_TX_USING_DMA) +void UART1_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART1_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART1_TX_USING_DMA) */ #endif /* BSP_USING_UART1 */ #if defined(BSP_USING_UART2) @@ -354,12 +399,24 @@ void UART2_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART2_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART2_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART2_RX_USING_DMA) */ +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART2_TX_USING_DMA) +void UART2_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART2_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART2_TX_USING_DMA) */ #endif /* BSP_USING_UART2 */ #if defined(BSP_USING_UART3) @@ -369,7 +426,7 @@ void USART3_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[UART3_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -379,12 +436,24 @@ void UART3_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART3_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART3_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(BSP_UART_USING_DMA_RX) && defined(BSP_UART3_RX_USING_DMA) */ +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART3_TX_USING_DMA) +void UART3_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART3_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(BSP_UART_USING_DMA_TX) && defined(BSP_UART3_TX_USING_DMA) */ #endif /* BSP_USING_UART3*/ #if defined(BSP_USING_UART4) @@ -394,7 +463,7 @@ void UART4_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[UART4_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -404,12 +473,25 @@ void UART4_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART4_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART4_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(BSP_UART_USING_DMA_RX) && defined(BSP_UART4_RX_USING_DMA) */ + +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART4_TX_USING_DMA) +void UART4_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART4_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(BSP_UART_USING_DMA_TX) && defined(BSP_UART4_TX_USING_DMA) */ #endif /* BSP_USING_UART4*/ #if defined(BSP_USING_UART5) @@ -419,7 +501,7 @@ void UART5_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[UART5_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -429,12 +511,24 @@ void UART5_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART5_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART5_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART5_RX_USING_DMA) */ +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART5_TX_USING_DMA) +void UART5_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART5_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART5_TX_USING_DMA) */ #endif /* BSP_USING_UART5*/ #if defined(BSP_USING_UART6) @@ -444,7 +538,7 @@ void USART6_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[UART6_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -454,12 +548,24 @@ void UART6_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[UART6_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[UART6_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); } #endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART6_RX_USING_DMA) */ +#if defined(RT_SERIAL_USING_DMA) && defined(BSP_UART6_TX_USING_DMA) +void UART6_DMA_TX_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + HAL_DMA_IRQHandler(&uart_obj[UART6_INDEX].dma_tx.handle); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif /* defined(RT_SERIAL_USING_DMA) && defined(BSP_UART6_TX_USING_DMA) */ #endif /* BSP_USING_UART6*/ #if defined(BSP_USING_LPUART1) @@ -469,7 +575,7 @@ void LPUART1_IRQHandler(void) rt_interrupt_enter(); uart_isr(&(uart_obj[LPUART1_INDEX].serial)); - + /* leave interrupt */ rt_interrupt_leave(); } @@ -479,7 +585,7 @@ void LPUART1_DMA_RX_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - HAL_DMA_IRQHandler(&uart_obj[LPUART1_INDEX].dma.handle); + HAL_DMA_IRQHandler(&uart_obj[LPUART1_INDEX].dma_rx.handle); /* leave interrupt */ rt_interrupt_leave(); @@ -488,19 +594,31 @@ void LPUART1_DMA_RX_IRQHandler(void) #endif /* BSP_USING_LPUART1*/ #ifdef RT_SERIAL_USING_DMA -static void stm32_dma_config(struct rt_serial_device *serial) +static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) { RT_ASSERT(serial != RT_NULL); struct stm32_uart *uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); struct rt_serial_rx_fifo *rx_fifo; - + DMA_HandleTypeDef *DMA_Handle; + struct dma_config *dma_config; + + if (RT_DEVICE_FLAG_DMA_RX == flag) + { + DMA_Handle = &uart->dma_rx.handle; + dma_config = uart->config->dma_rx; + } + else if (RT_DEVICE_FLAG_DMA_TX == flag) + { + DMA_Handle = &uart->dma_tx.handle; + dma_config = uart->config->dma_tx; + } LOG_D("%s dma config start", uart->config->name); { - rt_uint32_t tmpreg= 0x00U; + rt_uint32_t tmpreg = 0x00U; #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) \ - || defined(SOC_SERIES_STM32L0) + || defined(SOC_SERIES_STM32L0) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); tmpreg = READ_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); @@ -508,61 +626,88 @@ static void stm32_dma_config(struct rt_serial_device *serial) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ SET_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); tmpreg = READ_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); -#endif +#endif UNUSED(tmpreg); /* To avoid compiler warnings */ } - __HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma.handle); + if (RT_DEVICE_FLAG_DMA_RX == flag) + { + __HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma_rx.handle); + } + else if (RT_DEVICE_FLAG_DMA_TX == flag) + { + __HAL_LINKDMA(&(uart->handle), hdmatx, uart->dma_tx.handle); + } #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0) - uart->dma.handle.Instance = uart->config->dma_rx->Instance; + DMA_Handle->Instance = dma_config->Instance; #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) - uart->dma.handle.Instance = uart->config->dma_rx->Instance; - uart->dma.handle.Init.Channel = uart->config->dma_rx->channel; + DMA_Handle->Instance = dma_config->Instance; + DMA_Handle->Init.Channel = dma_config->channel; #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) - uart->dma.handle.Instance = uart->config->dma_rx->Instance; - uart->dma.handle.Init.Request = uart->config->dma_rx->request; + DMA_Handle->Instance = dma_config->Instance; + DMA_Handle->Init.Request = dma_config->request; #endif - uart->dma.handle.Init.Direction = DMA_PERIPH_TO_MEMORY; - uart->dma.handle.Init.PeriphInc = DMA_PINC_DISABLE; - uart->dma.handle.Init.MemInc = DMA_MINC_ENABLE; - uart->dma.handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - uart->dma.handle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - uart->dma.handle.Init.Mode = DMA_CIRCULAR; - uart->dma.handle.Init.Priority = DMA_PRIORITY_MEDIUM; + DMA_Handle->Init.PeriphInc = DMA_PINC_DISABLE; + DMA_Handle->Init.MemInc = DMA_MINC_ENABLE; + DMA_Handle->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + DMA_Handle->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + if (RT_DEVICE_FLAG_DMA_RX == flag) + { + DMA_Handle->Init.Direction = DMA_PERIPH_TO_MEMORY; + DMA_Handle->Init.Mode = DMA_CIRCULAR; + } + else if (RT_DEVICE_FLAG_DMA_TX == flag) + { + DMA_Handle->Init.Direction = DMA_MEMORY_TO_PERIPH; + DMA_Handle->Init.Mode = DMA_NORMAL; + } + DMA_Handle->Init.Priority = DMA_PRIORITY_MEDIUM; #if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) - uart->dma.handle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + DMA_Handle->Init.FIFOMode = DMA_FIFOMODE_DISABLE; #endif - if (HAL_DMA_DeInit(&(uart->dma.handle)) != HAL_OK) + if (HAL_DMA_DeInit(DMA_Handle) != HAL_OK) { RT_ASSERT(0); } - if (HAL_DMA_Init(&(uart->dma.handle)) != HAL_OK) + if (HAL_DMA_Init(DMA_Handle) != HAL_OK) { RT_ASSERT(0); } - rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; - - /* Start DMA transfer */ - if (HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz) != HAL_OK) - { - /* Transfer error in reception process */ - RT_ASSERT(0); - } - /* enable interrupt */ - __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE); - - /* enable rx irq */ - HAL_NVIC_SetPriority(uart->config->dma_rx->dma_irq, 0, 0); - HAL_NVIC_EnableIRQ(uart->config->dma_rx->dma_irq); - + if (flag == RT_DEVICE_FLAG_DMA_RX) + { + rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx; + /* Start DMA transfer */ + if (HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz) != HAL_OK) + { + /* Transfer error in reception process */ + RT_ASSERT(0); + } + CLEAR_BIT(uart->handle.Instance->CR3, USART_CR3_EIE); + __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE); + } + else if (flag == RT_DEVICE_FLAG_DMA_TX) + { + __HAL_UART_CLEAR_FLAG(&(uart->handle), UART_FLAG_TC); + while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET) + { + ; + } + __HAL_UART_CLEAR_FLAG(&(uart->handle), UART_FLAG_TC); + __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_TC); + } + + /* enable irq */ + HAL_NVIC_SetPriority(dma_config->dma_irq, 0, 0); + HAL_NVIC_EnableIRQ(dma_config->dma_irq); + HAL_NVIC_SetPriority(uart->config->irq_type, 1, 0); HAL_NVIC_EnableIRQ(uart->config->irq_type); - - LOG_D("%s dma RX instance: %x", uart->config->name, uart->dma.handle.Instance); + + LOG_D("%s dma %s instance: %x", uart->config->name, flag == RT_DEVICE_FLAG_DMA_RX ? "RX" : "TX", DMA_Handle->Instance); LOG_D("%s dma config done", uart->config->name); } @@ -601,8 +746,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) level = rt_hw_interrupt_disable(); - recv_len = serial->config.bufsz - uart->dma.last_index; - uart->dma.last_index = 0; + recv_len = serial->config.bufsz - uart->dma_rx.last_index; + uart->dma_rx.last_index = 0; rt_hw_interrupt_enable(level); if (recv_len) @@ -610,44 +755,99 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8)); } } +void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) +{ + struct stm32_uart *uart; + RT_ASSERT(huart != NULL); + uart = (struct stm32_uart *)huart; + rt_hw_serial_isr(&uart->serial, RT_SERIAL_EVENT_TX_DMADONE); +} #endif /* RT_SERIAL_USING_DMA */ static void stm32_uart_get_dma_config(void) { +#ifdef BSP_USING_UART1 + uart_obj[UART1_INDEX].uart_dma_flag = 0; #ifdef BSP_UART1_RX_USING_DMA - uart_obj[UART1_INDEX].uart_dma_flag = 1; - static struct dma_config uart1_dma_rx = UART1_DMA_CONFIG; + uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart1_dma_rx = UART1_DMA_RX_CONFIG; uart_config[UART1_INDEX].dma_rx = &uart1_dma_rx; #endif +#ifdef BSP_UART1_TX_USING_DMA + uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart1_dma_tx = UART1_DMA_TX_CONFIG; + uart_config[UART1_INDEX].dma_tx = &uart1_dma_tx; +#endif +#endif + +#ifdef BSP_USING_UART2 + uart_obj[UART2_INDEX].uart_dma_flag = 0; #ifdef BSP_UART2_RX_USING_DMA - uart_obj[UART2_INDEX].uart_dma_flag = 1; - static struct dma_config uart2_dma_rx = UART2_DMA_CONFIG; + uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart2_dma_rx = UART2_DMA_RX_CONFIG; uart_config[UART2_INDEX].dma_rx = &uart2_dma_rx; #endif +#ifdef BSP_UART2_TX_USING_DMA + uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart2_dma_tx = UART2_DMA_TX_CONFIG; + uart_config[UART2_INDEX].dma_tx = &uart2_dma_tx; +#endif +#endif + +#ifdef BSP_USING_UART3 + uart_obj[UART3_INDEX].uart_dma_flag = 0; #ifdef BSP_UART3_RX_USING_DMA - uart_obj[UART3_INDEX].uart_dma_flag = 1; - static struct dma_config uart3_dma_rx = UART3_DMA_CONFIG; + uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart3_dma_rx = UART3_DMA_RX_CONFIG; uart_config[UART3_INDEX].dma_rx = &uart3_dma_rx; #endif +#ifdef BSP_UART3_TX_USING_DMA + uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart3_dma_tx = UART3_DMA_TX_CONFIG; + uart_config[UART3_INDEX].dma_tx = &uart3_dma_tx; +#endif +#endif + +#ifdef BSP_USING_UART4 + uart_obj[UART4_INDEX].uart_dma_flag = 0; #ifdef BSP_UART4_RX_USING_DMA - uart_obj[UART4_INDEX].uart_dma_flag = 1; - static struct dma_config uart4_dma_rx = UART4_DMA_CONFIG; + uart_obj[UART4_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart4_dma_rx = UART4_DMA_RX_CONFIG; uart_config[UART4_INDEX].dma_rx = &uart4_dma_rx; #endif +#ifdef BSP_UART4_TX_USING_DMA + uart_obj[UART4_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart4_dma_tx = UART4_DMA_TX_CONFIG; + uart_config[UART4_INDEX].dma_tx = &uart4_dma_tx; +#endif +#endif + +#ifdef BSP_USING_UART5 + uart_obj[UART5_INDEX].uart_dma_flag = 0; #ifdef BSP_UART5_RX_USING_DMA - uart_obj[UART5_INDEX].uart_dma_flag = 1; - static struct dma_config uart5_dma_rx = UART5_DMA_CONFIG; + uart_obj[UART5_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart5_dma_rx = UART5_DMA_RX_CONFIG; uart_config[UART5_INDEX].dma_rx = &uart5_dma_rx; #endif +#ifdef BSP_UART5_TX_USING_DMA + uart_obj[UART5_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart5_dma_tx = UART5_DMA_TX_CONFIG; + uart_config[UART5_INDEX].dma_tx = &uart5_dma_tx; +#endif +#endif + +#ifdef BSP_USING_UART6 + uart_obj[UART6_INDEX].uart_dma_flag = 0; #ifdef BSP_UART6_RX_USING_DMA - uart_obj[UART6_INDEX].uart_dma_flag = 1; - static struct dma_config uart6_dma_rx = UART6_DMA_CONFIG; + uart_obj[UART6_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX; + static struct dma_config uart6_dma_rx = UART6_DMA_RX_CONFIG; uart_config[UART6_INDEX].dma_rx = &uart6_dma_rx; #endif -#ifdef BSP_LPUART1_RX_USING_DMA - uart_obj[LPUART1_INDEX].uart_dma_flag = 1; - static struct dma_config lpuart1_dma_rx = LPUART1_DMA_CONFIG; - uart_config[LPUART1_INDEX].dma_rx = &lpuart1_dma_rx; +#ifdef BSP_UART6_TX_USING_DMA + uart_obj[UART6_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX; + static struct dma_config uart6_dma_tx = UART6_DMA_TX_CONFIG; + uart_config[UART6_INDEX].dma_tx = &uart6_dma_tx; +#endif #endif } @@ -658,29 +858,19 @@ int rt_hw_usart_init(void) rt_err_t result = 0; stm32_uart_get_dma_config(); - + for (int i = 0; i < obj_num; i++) { uart_obj[i].config = &uart_config[i]; uart_obj[i].serial.ops = &stm32_uart_ops; uart_obj[i].serial.config = config; - -#if defined(RT_SERIAL_USING_DMA) - if(uart_obj[i].uart_dma_flag) - { - /* register UART device */ - result = rt_hw_serial_register(&uart_obj[i].serial,uart_obj[i].config->name, - RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX| RT_DEVICE_FLAG_DMA_RX - ,&uart_obj[i]); - } - else -#endif - { - /* register UART device */ - result = rt_hw_serial_register(&uart_obj[i].serial,uart_obj[i].config->name, - RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX - ,&uart_obj[i]); - } + /* register UART device */ + result = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name, + RT_DEVICE_FLAG_RDWR + | RT_DEVICE_FLAG_INT_RX + | RT_DEVICE_FLAG_INT_TX + | uart_obj[i].uart_dma_flag + , &uart_obj[i]); RT_ASSERT(result == RT_EOK); } diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.h b/bsp/stm32/libraries/HAL_Drivers/drv_usart.h index bae3e28f7a..07c505ef8e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.h +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.h @@ -41,6 +41,7 @@ struct stm32_uart_config USART_TypeDef *Instance; IRQn_Type irq_type; struct dma_config *dma_rx; + struct dma_config *dma_tx; }; /* stm32 uart dirver class */ @@ -54,9 +55,13 @@ struct stm32_uart { DMA_HandleTypeDef handle; rt_size_t last_index; - } dma; + } dma_rx; + struct + { + DMA_HandleTypeDef handle; + } dma_tx; #endif - rt_uint8_t uart_dma_flag; + rt_uint16_t uart_dma_flag; struct rt_serial_device serial; }; diff --git a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig index 650ccf131f..3d252bc69a 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig +++ b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig @@ -83,6 +83,25 @@ menu "On-chip Peripheral Drivers" depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA default n + config BSP_UART1_TX_USING_DMA + bool "Enable UART1 TX DMA" + depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA + default n + + config BSP_USING_UART2 + bool "Enable UART2" + default n + + config BSP_UART2_RX_USING_DMA + bool "Enable UART2 RX DMA" + depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA + default n + + config BSP_UART2_TX_USING_DMA + bool "Enable UART2 TX DMA" + depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA + default n + config BSP_USING_UART3 bool "Enable UART3" default n @@ -90,6 +109,53 @@ menu "On-chip Peripheral Drivers" config BSP_UART3_RX_USING_DMA bool "Enable UART3 RX DMA" depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA + default n + + config BSP_UART3_TX_USING_DMA + bool "Enable UART3 TX DMA" + depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA + default n + + config BSP_USING_UART4 + bool "Enable UART4" + default n + + config BSP_UART4_RX_USING_DMA + bool "Enable UART4 RX DMA" + depends on BSP_USING_UART4 && RT_SERIAL_USING_DMA + default n + + config BSP_UART4_TX_USING_DMA + bool "Enable UART4 TX DMA" + depends on BSP_USING_UART4 && RT_SERIAL_USING_DMA + default n + + config BSP_USING_UART5 + bool "Enable UART5" + default n + + config BSP_UART5_RX_USING_DMA + bool "Enable UART5 RX DMA" + depends on BSP_USING_UART5 && RT_SERIAL_USING_DMA + default n + + config BSP_UART5_TX_USING_DMA + bool "Enable UART5 TX DMA" + depends on BSP_USING_UART5 && RT_SERIAL_USING_DMA + default n + + config BSP_USING_UART6 + bool "Enable UART6" + default n + + config BSP_UART6_RX_USING_DMA + bool "Enable UART6 RX DMA" + depends on BSP_USING_UART6 && RT_SERIAL_USING_DMA + default n + + config BSP_UART6_TX_USING_DMA + bool "Enable UART6 TX DMA" + depends on BSP_USING_UART6 && RT_SERIAL_USING_DMA default n endif diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index d4cf35414c..cacaf1c9ac 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -675,6 +675,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag) serial->serial_tx = tx_dma; dev->open_flag |= RT_DEVICE_FLAG_DMA_TX; + serial->ops->control(serial, RT_DEVICE_CTRL_CONFIG, (void *)RT_DEVICE_FLAG_DMA_TX); } #endif /* RT_SERIAL_USING_DMA */ else From b844496ac9459a16044abe13785b355853526304 Mon Sep 17 00:00:00 2001 From: zhouchuanfu <353896039@qq.com> Date: Sat, 4 May 2019 18:44:36 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0F1=E7=B3=BB=E5=88=97?= =?UTF-8?q?=E7=9A=84uart=E7=9A=84dma=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HAL_Drivers/config/f1/dma_config.h | 28 +++++++ .../HAL_Drivers/config/f1/uart_config.h | 76 +++++++++++++++---- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f1/dma_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f1/dma_config.h index 9f4b4c725d..20205c43d7 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f1/dma_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f1/dma_config.h @@ -25,6 +25,11 @@ extern "C" { #define SPI1_RX_DMA_RCC RCC_AHBENR_DMA1EN #define SPI1_RX_DMA_INSTANCE DMA1_Channel2 #define SPI1_RX_DMA_IRQ DMA1_Channel2_IRQn +#elif defined(BSP_UART3_TX_USING_DMA) && !defined(UART3_TX_DMA_INSTANCE) +#define UART3_DMA_TX_IRQHandler DMA1_Channel2_IRQHandler +#define UART3_TX_DMA_RCC RCC_AHBENR_DMA1EN +#define UART3_TX_DMA_INSTANCE DMA1_Channel2 +#define UART3_TX_DMA_IRQ DMA1_Channel2_IRQn #endif /* DMA1 channel3 */ @@ -46,6 +51,11 @@ extern "C" { #define SPI2_RX_DMA_RCC RCC_AHBENR_DMA1EN #define SPI2_RX_DMA_INSTANCE DMA1_Channel4 #define SPI2_RX_DMA_IRQ DMA1_Channel4_IRQn +#elif defined(BSP_UART1_TX_USING_DMA) && !defined(UART1_TX_DMA_INSTANCE) +#define UART1_DMA_TX_IRQHandler DMA1_Channel4_IRQHandler +#define UART1_TX_DMA_RCC RCC_AHBENR_DMA1EN +#define UART1_TX_DMA_INSTANCE DMA1_Channel4 +#define UART1_TX_DMA_IRQ DMA1_Channel4_IRQn #endif /* DMA1 channel5 */ @@ -71,6 +81,12 @@ extern "C" { #endif /* DMA1 channel7 */ +#if defined(BSP_UART2_TX_USING_DMA) && !defined(UART2_TX_DMA_INSTANCE) +#define UART2_DMA_TX_IRQHandler DMA1_Channel7_IRQHandler +#define UART2_TX_DMA_RCC RCC_AHBENR_DMA1EN +#define UART2_TX_DMA_INSTANCE DMA1_Channel7 +#define UART2_TX_DMA_IRQ DMA1_Channel7_IRQn +#endif /* DMA2 channel1 */ #if defined(BSP_SPI3_RX_USING_DMA) && !defined(SPI3_RX_DMA_INSTANCE) @@ -89,8 +105,20 @@ extern "C" { #endif /* DMA2 channel3 */ +#if defined(BSP_UART4_RX_USING_DMA) && !defined(UART4_RX_DMA_INSTANCE) +#define UART4_DMA_RX_IRQHandler DMA2_Channel3_IRQHandler +#define UART4_RX_DMA_RCC RCC_AHBENR_DMA2EN +#define UART4_RX_DMA_INSTANCE DMA2_Channel3 +#define UART4_RX_DMA_IRQ DMA2_Channel3_IRQn +#endif /* DMA2 channel4 */ /* DMA2 channel5 */ +#if defined(BSP_UART4_TX_USING_DMA) && !defined(UART4_TX_DMA_INSTANCE) +#define UART4_DMA_TX_IRQHandler DMA2_Channel4_5_IRQHandler +#define UART4_TX_DMA_RCC RCC_AHBENR_DMA2EN +#define UART4_TX_DMA_INSTANCE DMA2_Channel5 +#define UART4_TX_DMA_IRQ DMA2_Channel4_5_IRQn +#endif #ifdef __cplusplus } diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h index 24c8ae2a72..b6f9576fde 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h @@ -28,19 +28,30 @@ extern "C" { .irq_type = USART1_IRQn, \ } #endif /* UART1_CONFIG */ -#endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ +#if defined(BSP_UART1_TX_USING_DMA) +#ifndef UART1_DMA_TX_CONFIG +#define UART1_DMA_TX_CONFIG \ + { \ + .Instance = UART1_TX_DMA_INSTANCE, \ + .dma_rcc = UART1_TX_DMA_RCC, \ + .dma_irq = UART1_TX_DMA_IRQ, \ + } +#endif /* UART1_DMA_TX_CONFIG */ +#endif /* BSP_UART1_TX_USING_DMA */ +#endif /* BSP_USING_UART1 */ + #if defined(BSP_USING_UART2) #ifndef UART2_CONFIG #define UART2_CONFIG \ @@ -50,19 +61,30 @@ extern "C" { .irq_type = USART2_IRQn, \ } #endif /* UART2_CONFIG */ -#endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ +#if defined(BSP_UART2_TX_USING_DMA) +#ifndef UART2_DMA_TX_CONFIG +#define UART2_DMA_TX_CONFIG \ + { \ + .Instance = UART2_TX_DMA_INSTANCE, \ + .dma_rcc = UART2_TX_DMA_RCC, \ + .dma_irq = UART2_TX_DMA_IRQ, \ + } +#endif /* UART2_DMA_TX_CONFIG */ +#endif /* BSP_UART2_TX_USING_DMA */ +#endif /* BSP_USING_UART2 */ + #if defined(BSP_USING_UART3) #ifndef UART3_CONFIG #define UART3_CONFIG \ @@ -72,19 +94,30 @@ extern "C" { .irq_type = USART3_IRQn, \ } #endif /* UART3_CONFIG */ -#endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ { \ .Instance = UART3_RX_DMA_INSTANCE, \ .dma_rcc = UART3_RX_DMA_RCC, \ .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ +#if defined(BSP_UART3_TX_USING_DMA) +#ifndef UART3_DMA_TX_CONFIG +#define UART3_DMA_TX_CONFIG \ + { \ + .Instance = UART3_TX_DMA_INSTANCE, \ + .dma_rcc = UART3_TX_DMA_RCC, \ + .dma_irq = UART3_TX_DMA_IRQ, \ + } +#endif /* UART3_DMA_TX_CONFIG */ +#endif /* BSP_UART3_TX_USING_DMA */ +#endif /* BSP_USING_UART3 */ + #if defined(BSP_USING_UART4) #ifndef UART4_CONFIG #define UART4_CONFIG \ @@ -94,19 +127,30 @@ extern "C" { .irq_type = UART4_IRQn, \ } #endif /* UART4_CONFIG */ -#endif /* BSP_USING_UART4 */ #if defined(BSP_UART4_RX_USING_DMA) -#ifndef UART4_DMA_CONFIG -#define UART4_DMA_CONFIG \ +#ifndef UART4_DMA_RX_CONFIG +#define UART4_DMA_RX_CONFIG \ { \ .Instance = UART4_RX_DMA_INSTANCE, \ .dma_rcc = UART4_RX_DMA_RCC, \ .dma_irq = UART4_RX_DMA_IRQ, \ } -#endif /* UART4_DMA_CONFIG */ +#endif /* UART4_DMA_RX_CONFIG */ #endif /* BSP_UART4_RX_USING_DMA */ +#if defined(BSP_UART4_TX_USING_DMA) +#ifndef UART4_DMA_TX_CONFIG +#define UART4_DMA_TX_CONFIG \ + { \ + .Instance = UART4_TX_DMA_INSTANCE, \ + .dma_rcc = UART4_TX_DMA_RCC, \ + .dma_irq = UART4_TX_DMA_IRQ, \ + } +#endif /* UART4_DMA_TX_CONFIG */ +#endif /* BSP_UART4_TX_USING_DMA */ +#endif /* BSP_USING_UART4 */ + #if defined(BSP_USING_UART5) #ifndef UART5_CONFIG #define UART5_CONFIG \ From 6ebb2c75d956449fa535481c42933bdb94b691c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Fri, 17 May 2019 23:23:14 +0800 Subject: [PATCH 03/11] Update drv_usart.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加部分空行 --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index ff438e2554..7bf0c73912 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -222,10 +222,12 @@ static rt_size_t stm32_dma_transmit(struct rt_serial_device *serial, rt_uint8_t RT_ASSERT(serial != RT_NULL); uart = (struct stm32_uart *)(serial->parent.user_data); RT_ASSERT(uart != RT_NULL); + if (size == 0) { return 0; } + if (RT_SERIAL_DMA_TX == direction) { if (HAL_UART_Transmit_DMA(&uart->handle, buf, size) == HAL_OK) @@ -652,6 +654,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) DMA_Handle->Init.MemInc = DMA_MINC_ENABLE; DMA_Handle->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; DMA_Handle->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + if (RT_DEVICE_FLAG_DMA_RX == flag) { DMA_Handle->Init.Direction = DMA_PERIPH_TO_MEMORY; @@ -662,6 +665,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) DMA_Handle->Init.Direction = DMA_MEMORY_TO_PERIPH; DMA_Handle->Init.Mode = DMA_NORMAL; } + DMA_Handle->Init.Priority = DMA_PRIORITY_MEDIUM; #if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) DMA_Handle->Init.FIFOMode = DMA_FIFOMODE_DISABLE; From 81ff374aed5a0a65f0e12ea9e8f0ca92d957ac31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Sun, 19 May 2019 22:26:56 +0800 Subject: [PATCH 04/11] Update drv_usart.c --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index 3d85f3e3a4..95ff652a81 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -359,20 +359,20 @@ static void dma_isr(struct rt_serial_device *serial) uart = (struct stm32_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); - if ((__HAL_DMA_GET_IT_SOURCE(&(uart->dma.handle), DMA_IT_TC) != RESET) || - (__HAL_DMA_GET_IT_SOURCE(&(uart->dma.handle), DMA_IT_HT) != 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)) { level = rt_hw_interrupt_disable(); - recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma.handle)); + recv_total_index = serial->config.bufsz - __HAL_DMA_GET_COUNTER(&(uart->dma_rx.handle)); if (recv_total_index == 0) { - recv_len = serial->config.bufsz - uart->dma.last_index; + recv_len = serial->config.bufsz - uart->dma_rx.last_index; } else { - recv_len = recv_total_index - uart->dma.last_index; + recv_len = recv_total_index - uart->dma_rx.last_index; } - uart->dma.last_index = recv_total_index; + uart->dma_rx.last_index = recv_total_index; rt_hw_interrupt_enable(level); if (recv_len) From 030b365333c74209e2c1a80954ac0166811d7f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Mon, 20 May 2019 09:47:36 +0800 Subject: [PATCH 05/11] Update drv_usart.c --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index 95ff652a81..2950266b3c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -635,11 +635,11 @@ void LPUART1_DMA_RX_IRQHandler(void) static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) { RT_ASSERT(serial != RT_NULL); - struct stm32_uart *uart = (struct stm32_uart *)serial->parent.user_data; - RT_ASSERT(uart != RT_NULL); struct rt_serial_rx_fifo *rx_fifo DMA_HandleTypeDef *DMA_Handle; struct dma_config *dma_config; + struct stm32_uart *uart = (struct stm32_uart *)serial->parent.user_data; + RT_ASSERT(uart != RT_NULL); if (RT_DEVICE_FLAG_DMA_RX == flag) { From 893bb729071c8af9bfba2df5c7c1daed57afa448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Mon, 20 May 2019 10:21:00 +0800 Subject: [PATCH 06/11] Update drv_usart.c --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index 2950266b3c..039d008341 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -634,11 +634,13 @@ void LPUART1_DMA_RX_IRQHandler(void) #ifdef RT_SERIAL_USING_DMA static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) { - RT_ASSERT(serial != RT_NULL); struct rt_serial_rx_fifo *rx_fifo DMA_HandleTypeDef *DMA_Handle; struct dma_config *dma_config; - struct stm32_uart *uart = (struct stm32_uart *)serial->parent.user_data; + struct stm32_uart *uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct stm32_uart *)serial->parent.user_data; RT_ASSERT(uart != RT_NULL); if (RT_DEVICE_FLAG_DMA_RX == flag) From 56e83fe735b82e35e69cd69321ed375f420163d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Mon, 20 May 2019 10:44:08 +0800 Subject: [PATCH 07/11] Update drv_usart.c --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index 039d008341..b07ed98c1c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -634,7 +634,7 @@ void LPUART1_DMA_RX_IRQHandler(void) #ifdef RT_SERIAL_USING_DMA static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) { - struct rt_serial_rx_fifo *rx_fifo + struct rt_serial_rx_fifo *rx_fifo; DMA_HandleTypeDef *DMA_Handle; struct dma_config *dma_config; struct stm32_uart *uart; From 1e10891f372c0c28e15c59a28eb3b5da8e23b96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Wed, 22 May 2019 09:48:13 +0800 Subject: [PATCH 08/11] Update drv_usart.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复dma_config里面rcc的bug。 --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index b07ed98c1c..bc6dfd0d95 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -660,12 +660,12 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) \ || defined(SOC_SERIES_STM32L0) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ - SET_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); - tmpreg = READ_BIT(RCC->AHBENR, uart->config->dma_rx->dma_rcc); + SET_BIT(RCC->AHBENR, dma_config->dma_rcc); + tmpreg = READ_BIT(RCC->AHBENR, dma_config->dma_rcc); #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4) /* enable DMA clock && Delay after an RCC peripheral clock enabling*/ - SET_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); - tmpreg = READ_BIT(RCC->AHB1ENR, uart->config->dma_rx->dma_rcc); + SET_BIT(RCC->AHB1ENR, dma_config->dma_rcc); + tmpreg = READ_BIT(RCC->AHB1ENR, dma_config->dma_rcc); #endif UNUSED(tmpreg); /* To avoid compiler warnings */ } From d548215a3b86a84968c3e2071374b545ebd825d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BC=A0=E7=A6=8F?= <46174387+zhouchuanfu@users.noreply.github.com> Date: Wed, 22 May 2019 14:53:49 +0800 Subject: [PATCH 09/11] Update drv_usart.c --- bsp/stm32/libraries/HAL_Drivers/drv_usart.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c index bc6dfd0d95..caf5dfac0a 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usart.c @@ -731,17 +731,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag) CLEAR_BIT(uart->handle.Instance->CR3, USART_CR3_EIE); __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE); } - else if (flag == RT_DEVICE_FLAG_DMA_TX) - { - __HAL_UART_CLEAR_FLAG(&(uart->handle), UART_FLAG_TC); - while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET) - { - ; - } - __HAL_UART_CLEAR_FLAG(&(uart->handle), UART_FLAG_TC); - __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_TC); - } - + /* enable irq */ HAL_NVIC_SetPriority(dma_config->dma_irq, 0, 0); HAL_NVIC_EnableIRQ(dma_config->dma_irq); From d82c90dc9a856afd2e0ba5801cd130768490b34f Mon Sep 17 00:00:00 2001 From: whj4674672 Date: Fri, 24 May 2019 18:08:31 +0800 Subject: [PATCH 10/11] =?UTF-8?q?[stm32][stm32h7]=E4=BF=AE=E5=A4=8DH7=20sp?= =?UTF-8?q?i=E4=BE=9D=E8=B5=96=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/STM32H7xx_HAL/SConscript | 4 +- .../board/CubeMX_Config/CubeMX_Config.ioc | 59 +++++++++---------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/bsp/stm32/libraries/STM32H7xx_HAL/SConscript b/bsp/stm32/libraries/STM32H7xx_HAL/SConscript index 6fffec9894..6ae0aaca4d 100644 --- a/bsp/stm32/libraries/STM32H7xx_HAL/SConscript +++ b/bsp/stm32/libraries/STM32H7xx_HAL/SConscript @@ -40,8 +40,8 @@ if GetDepend(['RT_USING_I2C']): src += ['STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c'] if GetDepend(['RT_USING_SPI']): - src += ['STM32F7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c'] - src += ['STM32F7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c'] + src += ['STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c'] + src += ['STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c'] if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']): src += ['STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pccard.c'] diff --git a/bsp/stm32/stm32h743-atk-apollo/board/CubeMX_Config/CubeMX_Config.ioc b/bsp/stm32/stm32h743-atk-apollo/board/CubeMX_Config/CubeMX_Config.ioc index 9c48fdb7bb..826c3dd665 100644 --- a/bsp/stm32/stm32h743-atk-apollo/board/CubeMX_Config/CubeMX_Config.ioc +++ b/bsp/stm32/stm32h743-atk-apollo/board/CubeMX_Config/CubeMX_Config.ioc @@ -71,37 +71,35 @@ Mcu.Pin43=PG7 Mcu.Pin44=PG8 Mcu.Pin45=PA9 Mcu.Pin46=PA10 -Mcu.Pin47=PA13 (JTMS/SWDIO) -Mcu.Pin48=PH13 -Mcu.Pin49=PH14 +Mcu.Pin47=PH13 +Mcu.Pin48=PH14 +Mcu.Pin49=PH15 Mcu.Pin5=PF3 -Mcu.Pin50=PH15 -Mcu.Pin51=PI0 -Mcu.Pin52=PI1 -Mcu.Pin53=PI2 -Mcu.Pin54=PA14 (JTCK/SWCLK) -Mcu.Pin55=PD0 -Mcu.Pin56=PD1 -Mcu.Pin57=PG11 -Mcu.Pin58=PG15 -Mcu.Pin59=PE0 +Mcu.Pin50=PI0 +Mcu.Pin51=PI1 +Mcu.Pin52=PI2 +Mcu.Pin53=PD0 +Mcu.Pin54=PD1 +Mcu.Pin55=PG11 +Mcu.Pin56=PG15 +Mcu.Pin57=PE0 +Mcu.Pin58=PE1 +Mcu.Pin59=PI4 Mcu.Pin6=PF4 -Mcu.Pin60=PE1 -Mcu.Pin61=PI4 -Mcu.Pin62=PI5 -Mcu.Pin63=PI6 -Mcu.Pin64=PI7 -Mcu.Pin65=VP_DMA2D_VS_DMA2D -Mcu.Pin66=VP_SYS_VS_Systick +Mcu.Pin60=PI5 +Mcu.Pin61=PI6 +Mcu.Pin62=PI7 +Mcu.Pin63=VP_DMA2D_VS_DMA2D +Mcu.Pin64=VP_SYS_VS_Systick Mcu.Pin7=PF5 Mcu.Pin8=PF10 Mcu.Pin9=PH0-OSC_IN (PH0) -Mcu.PinsNb=67 +Mcu.PinsNb=65 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32H743IITx -MxCube.Version=5.0.1 -MxDb.Version=DB.5.0.1 +MxCube.Version=5.2.0 +MxDb.Version=DB.5.0.20 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false @@ -116,10 +114,6 @@ NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false PA10.Locked=true PA10.Mode=Asynchronous PA10.Signal=USART1_RX -PA13\ (JTMS/SWDIO).Mode=Serial_Wire -PA13\ (JTMS/SWDIO).Signal=SYS_JTMS-SWDIO -PA14\ (JTCK/SWCLK).Mode=Serial_Wire -PA14\ (JTCK/SWCLK).Signal=SYS_JTCK-SWCLK PA9.Locked=true PA9.Mode=Asynchronous PA9.Signal=USART1_TX @@ -128,7 +122,7 @@ PC2_C.Mode=SdramChipSelect1_1 PC2_C.Signal=FMC_SDNE0 PC3_C.Mode=SdramChipSelect1_1 PC3_C.Signal=FMC_SDCKE0 -PCC.Checker=false +PCC.Checker=true PCC.Line=STM32H743/753 PCC.MCU=STM32H743IITx PCC.PartNumber=STM32H743IITx @@ -232,7 +226,7 @@ PI7.Signal=LTDC_B7 PI9.Mode=RGB565 PI9.Signal=LTDC_VSYNC PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=false +ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false ProjectManager.CompilerOptimize=6 ProjectManager.ComputerToolchain=false @@ -241,7 +235,7 @@ ProjectManager.CustomerFirmwarePackage= ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32H743IITx -ProjectManager.FirmwarePackage=STM32Cube FW_H7 V1.3.2 +ProjectManager.FirmwarePackage=STM32Cube FW_H7 V1.4.0 ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 @@ -304,7 +298,7 @@ RCC.HRTIMFreq_Value=200000000 RCC.HSE_VALUE=25000000 RCC.I2C123Freq_Value=100000000 RCC.I2C4Freq_Value=100000000 -RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CPU2Freq_Value,CPU2SystikFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVM3,DIVN1,DIVN3,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,HSE_VALUE,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLSourceVirtual,QSPIFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value +RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CPU2Freq_Value,CPU2SystikFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVM3,DIVN1,DIVN3,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,HSE_VALUE,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLSourceVirtual,PWR_Regulator_Voltage_Scale,QSPIFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value RCC.LPTIM1Freq_Value=100000000 RCC.LPTIM2Freq_Value=100000000 RCC.LPTIM345Freq_Value=100000000 @@ -313,6 +307,7 @@ RCC.LTDCFreq_Value=9090909.090909092 RCC.MCO1PinFreq_Value=64000000 RCC.MCO2PinFreq_Value=400000000 RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE +RCC.PWR_Regulator_Voltage_Scale=PWR_REGULATOR_VOLTAGE_SCALE1 RCC.QSPIFreq_Value=200000000 RCC.RNGFreq_Value=48000000 RCC.RTCFreq_Value=32000 @@ -330,7 +325,7 @@ RCC.SYSCLKFreq_VALUE=400000000 RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.Tim1OutputFreq_Value=200000000 RCC.Tim2OutputFreq_Value=200000000 -RCC.TraceFreq_Value=400000000 +RCC.TraceFreq_Value=64000000 RCC.USART16Freq_Value=100000000 RCC.USART234578Freq_Value=100000000 RCC.USBFreq_Value=400000000 From 9e260109483ed2d410f12c46e119f5b21c842d0d Mon Sep 17 00:00:00 2001 From: SummerGift Date: Fri, 24 May 2019 20:52:58 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91?= =?UTF-8?q?=E7=94=B1=E4=BA=8E=E6=B7=BB=E5=8A=A0=E4=B8=B2=E5=8F=A3=20DMA=20?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=AF=B9=E4=B8=B2=E5=8F=A3=20DMA=20=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E9=85=8D=E7=BD=AE=E9=80=A0=E6=88=90=E7=9A=84=E5=BD=B1?= =?UTF-8?q?=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HAL_Drivers/config/f0/uart_config.h | 12 ++++---- .../HAL_Drivers/config/f1/uart_config.h | 6 ++-- .../HAL_Drivers/config/f7/uart_config.h | 30 +++++++++---------- .../HAL_Drivers/config/g0/uart_config.h | 30 +++++++++---------- .../HAL_Drivers/config/h7/uart_config.h | 30 +++++++++---------- .../HAL_Drivers/config/l0/uart_config.h | 12 ++++---- .../HAL_Drivers/config/l4/uart_config.h | 18 +++++------ 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f0/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f0/uart_config.h index 04b3be7557..ea5e767aed 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f0/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f0/uart_config.h @@ -29,14 +29,14 @@ extern "C" { #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -51,14 +51,14 @@ extern "C" { #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h index b6f9576fde..a08196e996 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f1/uart_config.h @@ -163,12 +163,12 @@ extern "C" { #endif /* BSP_USING_UART5 */ #if defined(BSP_UART5_RX_USING_DMA) -#ifndef UART5_DMA_CONFIG -#define UART5_DMA_CONFIG \ +#ifndef UART5_DMA_RX_CONFIG +#define UART5_DMA_RX_CONFIG \ { \ .Instance = DMA_NOT_AVAILABLE, \ } -#endif /* UART5_DMA_CONFIG */ +#endif /* UART5_DMA_RX_CONFIG */ #endif /* BSP_UART5_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f7/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f7/uart_config.h index 7e4c87a61e..2fefa1344c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f7/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f7/uart_config.h @@ -30,15 +30,15 @@ extern "C" { #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .channel = UART1_RX_DMA_CHANNEL, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -53,15 +53,15 @@ extern "C" { #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .channel = UART2_RX_DMA_CHANNEL, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #if defined(BSP_USING_UART3) @@ -76,15 +76,15 @@ extern "C" { #endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ { \ .Instance = UART3_RX_DMA_INSTANCE, \ .channel = UART3_RX_DMA_CHANNEL, \ .dma_rcc = UART3_RX_DMA_RCC, \ .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ #if defined(BSP_USING_UART4) @@ -99,15 +99,15 @@ extern "C" { #endif /* BSP_USING_UART4 */ #if defined(BSP_UART4_RX_USING_DMA) -#ifndef UART4_DMA_CONFIG -#define UART4_DMA_CONFIG \ +#ifndef UART4_DMA_RX_CONFIG +#define UART4_DMA_RX_CONFIG \ { \ .Instance = UART4_RX_DMA_INSTANCE, \ .channel = UART4_RX_DMA_CHANNEL, \ .dma_rcc = UART4_RX_DMA_RCC, \ .dma_irq = UART4_RX_DMA_IRQ, \ } -#endif /* UART4_DMA_CONFIG */ +#endif /* UART4_DMA_RX_CONFIG */ #endif /* BSP_UART4_RX_USING_DMA */ #if defined(BSP_USING_UART5) @@ -122,15 +122,15 @@ extern "C" { #endif /* BSP_USING_UART5 */ #if defined(BSP_UART5_RX_USING_DMA) -#ifndef UART5_DMA_CONFIG -#define UART5_DMA_CONFIG \ +#ifndef UART5_DMA_RX_CONFIG +#define UART5_DMA_RX_CONFIG \ { \ .Instance = UART5_RX_DMA_INSTANCE, \ .channel = UART5_RX_DMA_CHANNEL, \ .dma_rcc = UART5_RX_DMA_RCC, \ .dma_irq = UART5_RX_DMA_IRQ, \ } -#endif /* UART5_DMA_CONFIG */ +#endif /* UART5_DMA_RX_CONFIG */ #endif /* BSP_UART5_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/g0/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/g0/uart_config.h index a3019f5dec..f38baf0b63 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/g0/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/g0/uart_config.h @@ -48,15 +48,15 @@ #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .request = UART1_RX_DMA_REQUEST, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -71,15 +71,15 @@ #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .request = UART2_RX_DMA_REQUEST, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #if defined(BSP_USING_UART3) @@ -103,15 +103,15 @@ #endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ { \ .Instance = UART3_RX_DMA_INSTANCE, \ .request = UART3_RX_DMA_REQUEST, \ .dma_rcc = UART3_RX_DMA_RCC, \ .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ #if defined(BSP_USING_UART4) @@ -135,15 +135,15 @@ #endif /* BSP_USING_UART4 */ #if defined(BSP_UART4_RX_USING_DMA) -#ifndef UART4_DMA_CONFIG -#define UART4_DMA_CONFIG \ +#ifndef UART4_DMA_RX_CONFIG +#define UART4_DMA_RX_CONFIG \ { \ .Instance = UART4_RX_DMA_INSTANCE, \ .request = UART4_RX_DMA_REQUEST, \ .dma_rcc = UART4_RX_DMA_RCC, \ .dma_irq = UART4_RX_DMA_IRQ, \ } -#endif /* UART4_DMA_CONFIG */ +#endif /* UART4_DMA_RX_CONFIG */ #endif /* BSP_UART4_RX_USING_DMA */ #if defined(BSP_USING_UART5) @@ -158,12 +158,12 @@ #endif /* BSP_USING_UART5 */ #if defined(BSP_UART5_RX_USING_DMA) -#ifndef UART5_DMA_CONFIG -#define UART5_DMA_CONFIG \ +#ifndef UART5_DMA_RX_CONFIG +#define UART5_DMA_RX_CONFIG \ { \ .Instance = DMA_NOT_AVAILABLE, \ } -#endif /* UART5_DMA_CONFIG */ +#endif /* UART5_DMA_RX_CONFIG */ #endif /* BSP_UART5_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/h7/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/h7/uart_config.h index 7e4c87a61e..2fefa1344c 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/h7/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/h7/uart_config.h @@ -30,15 +30,15 @@ extern "C" { #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .channel = UART1_RX_DMA_CHANNEL, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -53,15 +53,15 @@ extern "C" { #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .channel = UART2_RX_DMA_CHANNEL, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #if defined(BSP_USING_UART3) @@ -76,15 +76,15 @@ extern "C" { #endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ { \ .Instance = UART3_RX_DMA_INSTANCE, \ .channel = UART3_RX_DMA_CHANNEL, \ .dma_rcc = UART3_RX_DMA_RCC, \ .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ #if defined(BSP_USING_UART4) @@ -99,15 +99,15 @@ extern "C" { #endif /* BSP_USING_UART4 */ #if defined(BSP_UART4_RX_USING_DMA) -#ifndef UART4_DMA_CONFIG -#define UART4_DMA_CONFIG \ +#ifndef UART4_DMA_RX_CONFIG +#define UART4_DMA_RX_CONFIG \ { \ .Instance = UART4_RX_DMA_INSTANCE, \ .channel = UART4_RX_DMA_CHANNEL, \ .dma_rcc = UART4_RX_DMA_RCC, \ .dma_irq = UART4_RX_DMA_IRQ, \ } -#endif /* UART4_DMA_CONFIG */ +#endif /* UART4_DMA_RX_CONFIG */ #endif /* BSP_UART4_RX_USING_DMA */ #if defined(BSP_USING_UART5) @@ -122,15 +122,15 @@ extern "C" { #endif /* BSP_USING_UART5 */ #if defined(BSP_UART5_RX_USING_DMA) -#ifndef UART5_DMA_CONFIG -#define UART5_DMA_CONFIG \ +#ifndef UART5_DMA_RX_CONFIG +#define UART5_DMA_RX_CONFIG \ { \ .Instance = UART5_RX_DMA_INSTANCE, \ .channel = UART5_RX_DMA_CHANNEL, \ .dma_rcc = UART5_RX_DMA_RCC, \ .dma_irq = UART5_RX_DMA_IRQ, \ } -#endif /* UART5_DMA_CONFIG */ +#endif /* UART5_DMA_RX_CONFIG */ #endif /* BSP_UART5_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/l0/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/l0/uart_config.h index 04b3be7557..ea5e767aed 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/l0/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/l0/uart_config.h @@ -29,14 +29,14 @@ extern "C" { #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -51,14 +51,14 @@ extern "C" { #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/config/l4/uart_config.h b/bsp/stm32/libraries/HAL_Drivers/config/l4/uart_config.h index 71d61065c9..d6f972e7d9 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/l4/uart_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/l4/uart_config.h @@ -51,15 +51,15 @@ extern "C" { #endif /* BSP_USING_UART1 */ #if defined(BSP_UART1_RX_USING_DMA) -#ifndef UART1_DMA_CONFIG -#define UART1_DMA_CONFIG \ +#ifndef UART1_DMA_RX_CONFIG +#define UART1_DMA_RX_CONFIG \ { \ .Instance = UART1_RX_DMA_INSTANCE, \ .request = UART1_RX_DMA_REQUEST, \ .dma_rcc = UART1_RX_DMA_RCC, \ .dma_irq = UART1_RX_DMA_IRQ, \ } -#endif /* UART1_DMA_CONFIG */ +#endif /* UART1_DMA_RX_CONFIG */ #endif /* BSP_UART1_RX_USING_DMA */ #if defined(BSP_USING_UART2) @@ -74,15 +74,15 @@ extern "C" { #endif /* BSP_USING_UART2 */ #if defined(BSP_UART2_RX_USING_DMA) -#ifndef UART2_DMA_CONFIG -#define UART2_DMA_CONFIG \ +#ifndef UART2_DMA_RX_CONFIG +#define UART2_DMA_RX_CONFIG \ { \ .Instance = UART2_RX_DMA_INSTANCE, \ .request = UART2_RX_DMA_REQUEST, \ .dma_rcc = UART2_RX_DMA_RCC, \ .dma_irq = UART2_RX_DMA_IRQ, \ } -#endif /* UART2_DMA_CONFIG */ +#endif /* UART2_DMA_RX_CONFIG */ #endif /* BSP_UART2_RX_USING_DMA */ #if defined(BSP_USING_UART3) @@ -97,15 +97,15 @@ extern "C" { #endif /* BSP_USING_UART3 */ #if defined(BSP_UART3_RX_USING_DMA) -#ifndef UART3_DMA_CONFIG -#define UART3_DMA_CONFIG \ +#ifndef UART3_DMA_RX_CONFIG +#define UART3_DMA_RX_CONFIG \ { \ .Instance = UART3_RX_DMA_INSTANCE, \ .request = UART3_RX_DMA_REQUEST, \ .dma_rcc = UART3_RX_DMA_RCC, \ .dma_irq = UART3_RX_DMA_IRQ, \ } -#endif /* UART3_DMA_CONFIG */ +#endif /* UART3_DMA_RX_CONFIG */ #endif /* BSP_UART3_RX_USING_DMA */ #ifdef __cplusplus