cancel
Showing results for 
Search instead for 
Did you mean: 

ADC DMA in double buffer mode and callback

Lecordier.Guy
Associate II

Hello ST team,

my platform: STM32f429

I use ADC with DMA in double buffer mode.

The ADC_ConvCallback is only called when the Memory0 is filled. There is no Callback called when the memory1 is filled.

This due to the hdma->XferM1CpltCallback which is NULL.

I can't use HAL_DMA_RegisterCallback(hdma, HAL_DMA_XFER_M1CPLT_CB_ID, ADC_DMAConvCplt) as ADC_DMAConvCplt() is static

It could be fine to initialize both callback in HAL_ADC_Start_DMA()

    /* Set the DMA transfer complete callback */

   hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;

   hadc->DMA_Handle->XferM1CpltCallback = ADC_DMAConvCplt;

   /* Set the DMA half transfer complete callback */

   hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;

   hadc->DMA_Handle->XferM1HalfCpltCallback = ADC_DMAHalfConvCplt;

Best regards

2 REPLIES 2
S.Ma
Principal

Learnt the hard way that users of the HAL should read the file header explanations before using the non intuitive functions.

I understood that when a peripheral is used along with a DMA, only the peripheral HAL DMA functions should be the focus.

The DMA HAL functions shouldn't be used by user.

RMcCa
Senior II

Easiest thing to do is write your own isr and don't rely on the hal callbacks.

All you need to do is check the current bank (buffer) bit in the dma statis reg in your isr and read from the other. As far as i can tell, this works the same as using 1/2 and full buffer interrupts with a 2x sized buffer, the only difference being that in double buffer mode the buffers don't need to be contiguous.