实例1:MDMA_GPDMA_Triggering
例程说明:
串口的接收采用DMA方式,使用DMA1 stream5,接收到数据后,会有一个DMA1 stream5接收标志用来触发MDMA传输,传输到缓冲aMDMA_RxBuffer里面,然后再将其回传。
这个例子应该是MDMA里面最简单的了。
注:由于这个例子开启Cache了,但是aMDMA_RxBuffer是TCM空间,所以发送前,无需做Cache无效化操作。
配置如下:
/*##-1- Enable the MDMA clock ###############################################*/
__HAL_RCC_MDMA_CLK_ENABLE();
/*##-2- Select the MDMA instance to be used : MDMA_Channel0 #################*/
MDMA_Handle.Instance = MDMA_INSTANCE;
/*##-3- Configure the MDMA for block transfer in HW request mode ############*/
/* MDMA HW request is set to DMA1 stream5 Transfer Complete Flag
i.e The MDMA transfer will be triggered by the DMA1 Stream5 Transfer complete flag */
MDMA_Handle.Init.Request = MDMA_HW_REQUEST_TRIGGER;
MDMA_Handle.Init.TransferTriggerMode = MDMA_BLOCK_TRANSFER;
MDMA_Handle.Init.Priority = MDMA_PRIORITY_HIGH;
MDMA_Handle.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
MDMA_Handle.Init.SourceInc = MDMA_SRC_INC_BYTE;
MDMA_Handle.Init.DestinationInc = MDMA_DEST_INC_BYTE;
MDMA_Handle.Init.SourceDataSize = MDMA_SRC_DATASIZE_BYTE;
MDMA_Handle.Init.DestDataSize = MDMA_DEST_DATASIZE_BYTE;
MDMA_Handle.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
MDMA_Handle.Init.SourceBurst = MDMA_SOURCE_BURST_SINGLE;
MDMA_Handle.Init.DestBurst = MDMA_DEST_BURST_SINGLE;
MDMA_Handle.Init.BufferTransferLength = 128;
MDMA_Handle.Init.SourceBlockAddressOffset = 0;
MDMA_Handle.Init.DestBlockAddressOffset = 0;
/*##-4- Initialize the MDMA channel ##########################################*/
hal_status = HAL_MDMA_Init(&MDMA_Handle);
if(hal_status != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-5- Select Callbacks functions called after MDMA Transfer complete and Transfer error */
HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_CPLT_CB_ID, MDMA_TransferCompleteCallback);
HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_ERROR_CB_ID, MDMA_TransferErrorCallback);
/*##-6- Configure NVIC for MDMA transfer complete/error interrupts ##########*/
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriority(MDMA_IRQn, 0, 0);
/* Enable the MDMA channel global Interrupt */
HAL_NVIC_EnableIRQ(MDMA_IRQn);
/*##-7- Start the MDMA transfer process #####################################*/
/* MDMA will transfer content of "aUART_RxBuffer" buffer to "aMDMA_RxBuffer" buffer
knowing that MDMA HW trigger is DMA1 stream 5 which is used for UART reception.
as consequence MDMA transfer will be triggered once the UART received user message to
"aUART_RxBuffer" buffer and the MDMA will transfer it to the "aMDMA_RxBuffer" buffer
*/
hal_status = HAL_MDMA_Start_IT(&MDMA_Handle, (uint32_t)&aUART_RxBuffer,
(uint32_t)&aMDMA_RxBuffer,
RXBUFFERSIZE,
1); |