cancel
Showing results for 
Search instead for 
Did you mean: 

DMA double buffer mode, Only 1 callback is called

con3
Senior

Hey everyone,

I'm not sure how this popped up, but I've found something really weird. I have a DMA setup in multibuffer mode. It fills both buffers and works perfectly in that respect. The issue comes in after the buffers are filled. Once buffer 1 is filled, the callback gets called for it, once buffer 2 is filled, no callback is called and the DMA heads back to buffer 1. I'm not sure why this is happening. Here's the relevant portions of code:

static void TransferError(DMA_HandleTypeDef *DmaHandle);
static void TransferComplete1(DMA_HandleTypeDef *DmaHandle);
static void TransferComplete(DMA_HandleTypeDef *DmaHandle);
 
uint32_t aDST_Buffer2[16200] = { 0 };
uint32_t aDST_Buffer1[16200] = { 0 };
 
//DMA Callbacks
	hdma_tim8_ch1_ch2_ch3.XferM1CpltCallback = TransferComplete1;
	hdma_tim8_ch1_ch2_ch3.XferCpltCallback = TransferComplete;
	hdma_tim8_ch1_ch2_ch3.XferErrorCallback = TransferError;
 
//Setup the DMA in Multibuffer mode with GPIOF as the input for the dataset
 
	if (HAL_DMAEx_MultiBufferStart_IT(
			htim8.hdma[TIM_DMA_ID_CC2 | TIM_DMA_ID_CC3], GPIOF_IDR,
			(uint32_t) &aDST_Buffer1, (uint32_t) &aDST_Buffer2, 32400)
			!= HAL_OK) {
		/* Transfer Error */
		Error_Handler();
	}
 
//Enable the DMA and Timer interrupt
 
	__HAL_TIM_ENABLE_DMA(&htim8, TIM_DMA_CC2|TIM_DMA_CC3);
	__HAL_TIM_ENABLE_IT(&htim8, TIM_IT_CC2|TIM_IT_CC3);
 
	HAL_TIM_OC_Start(&htim8, TIM_CHANNEL_2 | TIM_CHANNEL_3);
 
	TIM_CCxChannelCmd(htim8.Instance, TIM_CHANNEL_2 | TIM_CHANNEL_3,
TIM_CCx_ENABLE);
 

I do initialize the callback and link it to the DMA, but it never gets executed. I can see the aDST_Buffer2 is being filled, but TransferComplete1 never gets called. I'm not using data cache or anything like that and I'm working with an stm32f722ze. Has anyone encountered this or is there anyway to go about debugging this? At this point I'm confident that buffer 2's callback never gets called, but besides that the multi-buffer DMA works perfectly.

Thanks in advance for any help. i really appreciate it

2 REPLIES 2
Pevy.Andy
Associate III

Try changing the 32400 in the HAL_DMAEx_MultiBufferStart_IT line. I got caught out by the transfer count not being documented properly.

Try changing the 32400 to 16200 and see if that works...

Andy

Hi @Community member​ ,

Thank you for the advice. Changing it to 16200 causes only half of both buffers to be filled. The weird thing is that both buffers are being filled. I can see they both are filled from beginning to end, but only buffer 1's callback is being called, buffer 2's callback is never called, even though the buffer is filled.

Thank you again for the help