【修改】之前因为修改造成的不兼容问题并添加 DMA 支持

This commit is contained in:
YJIE_1998 2021-08-05 16:00:35 +08:00
parent bfb9fd78a3
commit b5fbaa20b9
4 changed files with 27 additions and 6 deletions

View File

@ -48,6 +48,7 @@ extern "C" {
#include "f3/uart_config.h" #include "f3/uart_config.h"
#include "f3/tim_config.h" #include "f3/tim_config.h"
#include "f3/pwm_config.h" #include "f3/pwm_config.h"
#include "f3/dma_config.h"
#elif defined(SOC_SERIES_STM32F4) #elif defined(SOC_SERIES_STM32F4)
#include "f4/dma_config.h" #include "f4/dma_config.h"
#include "f4/uart_config.h" #include "f4/uart_config.h"

View File

@ -32,7 +32,7 @@ struct dma_config {
rt_uint32_t dma_rcc; rt_uint32_t dma_rcc;
IRQn_Type dma_irq; IRQn_Type dma_irq;
#if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)|| defined(SOC_SERIES_STM32F3)
rt_uint32_t channel; rt_uint32_t channel;
#endif #endif

View File

@ -369,13 +369,22 @@ static void uart_isr(struct rt_serial_device *serial)
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET) if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_PE) != RESET)
{ {
__HAL_UART_CLEAR_PEFLAG(&uart->handle); __HAL_UART_CLEAR_PEFLAG(&uart->handle);
} }
#if !defined(SOC_SERIES_STM32F3) #if !defined(SOC_SERIES_STM32L4) && !defined(SOC_SERIES_STM32WL) && !defined(SOC_SERIES_STM32F7) && !defined(SOC_SERIES_STM32F0) \
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBD) != RESET) && !defined(SOC_SERIES_STM32L0) && !defined(SOC_SERIES_STM32G0) && !defined(SOC_SERIES_STM32H7) \
&& !defined(SOC_SERIES_STM32G4) && !defined(SOC_SERIES_STM32MP1) && !defined(SOC_SERIES_STM32WB)
#ifdef SOC_SERIES_STM32F3
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBDF) != RESET)
{ {
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBDF); UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBDF);
} }
#else
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_LBD) != RESET)
{
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_LBD);
}
#endif #endif
#endif
if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_CTS) != RESET) if (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_CTS) != RESET)
{ {
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_CTS); UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_CTS);
@ -864,7 +873,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
{ {
rt_uint32_t tmpreg = 0x00U; rt_uint32_t tmpreg = 0x00U;
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) \ #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32L0)|| defined(SOC_SERIES_STM32F3)
/* enable DMA clock && Delay after an RCC peripheral clock enabling*/ /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
SET_BIT(RCC->AHBENR, dma_config->dma_rcc); SET_BIT(RCC->AHBENR, dma_config->dma_rcc);
tmpreg = READ_BIT(RCC->AHBENR, dma_config->dma_rcc); tmpreg = READ_BIT(RCC->AHBENR, dma_config->dma_rcc);
@ -898,7 +907,7 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
__HAL_LINKDMA(&(uart->handle), hdmatx, uart->dma_tx.handle); __HAL_LINKDMA(&(uart->handle), hdmatx, uart->dma_tx.handle);
} }
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0) #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0)|| defined(SOC_SERIES_STM32F3)
DMA_Handle->Instance = dma_config->Instance; DMA_Handle->Instance = dma_config->Instance;
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
DMA_Handle->Instance = dma_config->Instance; DMA_Handle->Instance = dma_config->Instance;

View File

@ -26,6 +26,17 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_UART2 config BSP_USING_UART2
bool "Enable UART2" bool "Enable UART2"
default y default y
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
endif endif
endmenu endmenu