According to documentation, many of STM32's supports DMA in Double-Buffer (or also known as Multi-Buffer) mode. In HAL, there are two functions for this feature: HAL_DMAEx_MultiBufferStart
and HAL_DMAEx_MultiBufferStart_IT
in stm32xxxx_hal_adc_ex
file. But in any SDK (H7, F7, F4 etc.), there are not single example of usage of those two functions. How to get this double-buffering DMA working together with ADC?
1 Answers
I never used the functions you mentioned for double buffer technique. I simply create a buffer, which has double the size of a "normal" buffer and use the DMA Callback functions HAL_ADC_ConvCpltCallback and HAL_ADC_ConvHalfCpltCallback for the decision which half of the buffer needs to be processed.
On an "HAL_ADC_ConvCpltCallback" Interrupt the upper half of the Double Buffer is processed while the ADC is writing its data in the lower half and vice versa ...
So: if I want e.g. to process my data in blocks of 100 samples, I create a buffer with 200 samples
uint32_t ADC_DMABuffer[ADC_DMABufferSize * 2];
and start the ADC with
HAL_ADC_Start_DMA(&hadc1, ADC_DMABuffer, ((uint32_t)(ADC_DMABufferSize * 2))); // Double Buffer
For processing the data in the lower half the start pointer is
ADC_DMABuffer[0]
for the upper half the start pointer is
ADC_DMABuffer[ADC_DMABufferSize]
and the count of data, that need to be processed is of course "ADC_DMABufferSize" ...