DMA初始化
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_DMA_SetChannelSelection(DMA1, LL_DMA_STREAM_0, LL_DMA_CHANNEL_4);LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_STREAM_0, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);LL_DMA_SetStreamPriorityLevel(DMA1, LL_DMA_STREAM_0, LL_DMA_PRIORITY_LOW);LL_DMA_SetMode(DMA1, LL_DMA_STREAM_0, LL_DMA_MODE_NORMAL);LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_STREAM_0, LL_DMA_PERIPH_NOINCREMENT);LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_STREAM_0, LL_DMA_MEMORY_INCREMENT);LL_DMA_SetPeriphSize(DMA1, LL_DMA_STREAM_0, LL_DMA_PDATAALIGN_BYTE);LL_DMA_SetMemorySize(DMA1, LL_DMA_STREAM_0, LL_DMA_MDATAALIGN_BYTE);LL_DMA_DisableFifoMode(DMA1, LL_DMA_STREAM_0);LL_DMA_SetPeriphAddress(DMA1, LL_DMA_STREAM_0, LL_USART_DMA_GetRegAddr(UART5));LL_DMA_SetMemoryAddress(DMA1, LL_DMA_STREAM_0, (uint32_t)rx_buffer);LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_0, 32);LL_DMA_SetChannelSelection(DMA1, LL_DMA_STREAM_7, LL_DMA_CHANNEL_4);LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_STREAM_7, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);LL_DMA_SetStreamPriorityLevel(DMA1, LL_DMA_STREAM_7, LL_DMA_PRIORITY_LOW);LL_DMA_SetMode(DMA1, LL_DMA_STREAM_7, LL_DMA_MODE_NORMAL);LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_STREAM_7, LL_DMA_PERIPH_NOINCREMENT);LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_STREAM_7, LL_DMA_MEMORY_INCREMENT);LL_DMA_SetPeriphSize(DMA1, LL_DMA_STREAM_7, LL_DMA_PDATAALIGN_BYTE);LL_DMA_SetMemorySize(DMA1, LL_DMA_STREAM_7, LL_DMA_MDATAALIGN_BYTE);LL_DMA_DisableFifoMode(DMA1, LL_DMA_STREAM_7);LL_DMA_SetPeriphAddress(DMA1, LL_DMA_STREAM_7, LL_USART_DMA_GetRegAddr(UART5));LL_DMA_SetMemoryAddress(DMA1, LL_DMA_STREAM_7, (uint32_t)tx_buffer);LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_7, 32);
串口初始化
USART_InitStruct.BaudRate = 115200;USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;USART_InitStruct.StopBits = LL_USART_STOPBITS_1;USART_InitStruct.Parity = LL_USART_PARITY_NONE;USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;LL_USART_Init(UART5, &USART_InitStruct);LL_USART_ConfigAsyncMode(UART5);LL_USART_Enable(UART5);LL_DMA_EnableStream(DMA1,LL_DMA_STREAM_0); LL_USART_EnableDMAReq_RX(UART5); LL_USART_EnableDMAReq_TX(UART5);
使用方式
for(int i =0;i<32;i++)tx_buffer[i] = i + 2;LL_DMA_EnableStream(DMA1,LL_DMA_STREAM_7); 使能发送