From ce6c7c63e53ceee4ddd0dc3699c5337628c57fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BF=97=E4=BC=9F?= Date: Sun, 8 Oct 2023 21:19:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp_usart.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bsp_usart.c diff --git a/bsp_usart.c b/bsp_usart.c new file mode 100644 index 0000000..4602bce --- /dev/null +++ b/bsp_usart.c @@ -0,0 +1,38 @@ +#include "bsp_usart.h" +#include "main.h" + +extern UART_HandleTypeDef huart1; +extern DMA_HandleTypeDef hdma_usart1_tx; +void usart1_tx_dma_init(void) +{ + //enable the DMA transfer for the receiver request + //使能DMA串口接收 + SET_BIT(huart1.Instance->CR3, USART_CR3_DMAT); +} +void usart1_tx_dma_enable(uint8_t *data, uint16_t len) +{ + + //disable DMA + //失效DMA + __HAL_DMA_DISABLE(&hdma_usart1_tx); + while(hdma_usart1_tx.Instance->CR & DMA_SxCR_EN) + { + __HAL_DMA_DISABLE(&hdma_usart1_tx); + } + + //clear flag + //清除标志位 + __HAL_DMA_CLEAR_FLAG(&hdma_usart1_tx, DMA_HISR_TCIF7); + __HAL_DMA_CLEAR_FLAG(&hdma_usart1_tx, DMA_HISR_HTIF7); + + //set data address + //设置数据地址 + hdma_usart1_tx.Instance->M0AR = (uint32_t)(data); + //set data length + //设置数据长度 + hdma_usart1_tx.Instance->NDTR = len; + + //enable DMA + //使能DMA + __HAL_DMA_ENABLE(&hdma_usart1_tx); +}