配置:
void MF_DMA_Channel3_Init(void)
{
FL_DMA_InitTypeDef DMA_InitStruct;
DMA_InitStruct.periphAddress = FL_DMA_PERIPHERAL_FUNCTION4;
DMA_InitStruct.direction = FL_DMA_DIR_RAM_TO_PERIPHERAL;
DMA_InitStruct.memoryAddressIncMode = FL_DMA_MEMORY_INC_MODE_INCREASE;
DMA_InitStruct.flashAddressIncMode = FL_DMA_CH7_FLASH_INC_MODE_INCREASE;
DMA_InitStruct.dataSize = FL_DMA_BANDWIDTH_8B;
DMA_InitStruct.priority = FL_DMA_PRIORITY_HIGH;
DMA_InitStruct.circMode = FL_DISABLE;
FL_DMA_Init(DMA, &DMA_InitStruct, FL_DMA_CHANNEL_3);
}
void MF_UART4_Init(void)
{
FL_GPIO_InitTypeDef GPIO_InitStruct;
FL_UART_InitTypeDef UART4_InitStruct;
/* PA0 UART4_RX */
GPIO_InitStruct.pin = FL_GPIO_PIN_0;
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = FL_DISABLE;
GPIO_InitStruct.remapPin = FL_DISABLE;
FL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* PA1 UART4_TX */
GPIO_InitStruct.pin = FL_GPIO_PIN_1;
GPIO_InitStruct.mode = FL_GPIO_MODE_DIGITAL;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = FL_DISABLE;
GPIO_InitStruct.remapPin = FL_DISABLE;
FL_GPIO_Init(GPIOA, &GPIO_InitStruct);
UART4_InitStruct.clockSrc = NULL;
UART4_InitStruct.baudRate = 115200;
UART4_InitStruct.dataWidth = FL_UART_DATA_WIDTH_8B;
UART4_InitStruct.stopBits = FL_UART_STOP_BIT_WIDTH_1B;
UART4_InitStruct.parity = FL_UART_PARITY_NONE;
UART4_InitStruct.transferDirection = FL_UART_DIRECTION_TX_RX;
FL_UART_Init(UART4, &UART4_InitStruct);
}
发送函数:
u8 Uart4_TX(uint8_t *buffer, uint32_t length)
{
FL_DMA_Enable(DMA);
FL_DMA_ConfigTypeDef DMA_ConfigStruct = {0};
DMA_ConfigStruct.memoryAddress = (uint32_t)buffer;
DMA_ConfigStruct.transmissionCount = length - 1;
FL_DMA_StartTransmission(DMA, &DMA_ConfigStruct, FL_DMA_CHANNEL_3);
FL_UART_EnableTX(UART4);
// 等待最后一字节数据发送完成
while(FL_UART_IsActiveFlag_TXShiftBuffEmpty(UART4) == FL_RESET) {};
FL_UART_ClearFlag_TXShiftBuffEmpty(UART4);
return true;
}