标签/分类 "驱动" 下的文章
stm32 串口DMA配置
一、定义串口DMA缓存 #define UART2_MAX_LENGTH 255 uint8_t aU2DmaRxBuffer[UART2_MAX_LENGTH]; uint8_t aU2DmaTxBuffer[UART2_MAX_LENGTH]; // = "1234"; 二、串口基本初始化 UartHandle[Uart2].Instance = USART2; UartHandle[Uart2].Init.BaudRate = bute; UartHandle[Uart2].Init.WordLength = mx_get_uart_databit(databit); UartHandle[Uart2].Init.StopBits = UART_STOPBITS_1; UartHandle[Uart2].Init.Parity = mx_get_uart_paritybit(parity); UartHandle[Uart2].Init.Mode = UART_MODE_TX_RX; UartHandle[Uart2].Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle[Uart2].Init.OverSampling = UART_OVERSAMPLING_16; UartHandle[Uart2].Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; UartHandle[Uart2].AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&UartHandle[Uart2]) != HAL_OK) { Error_Handler(); } 三、打开串口空闲中断 __HAL_UART_ENABLE_IT(&UartHandle[Uart2], UART_IT_IDLE); 四、DMA初始化 找到 void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)函数,里面实现如下所示: __HAL_RCC_USART2_CLK_ENABLE(); #if UART2_DMA __HAL_RCC_DMA1_CLK_ENABLE(); #endif