Data corruption while reading multiple channels of ADC1 with DMA
I am working on a old code written by someone (without a design document). The application requires reading 13 ADC channels roughly at 8k samples per second. The read values
are written in two buffers in double buffer mode (4096 each).
The ADC is implemented in scan mode with the sequence of channels in ADC_SQRx registers. ADC is configured in 12 bit mode. ADC conversion is triggered by rising
edge of timer2 channel 2 set at a ~8Khz frequency.
DMA is configured peripheral to memory transfer in double buffer mode, with DMA2 Stream0 which can take ADC1 as source.The NDTR register in DMA is written with a value of 4082,
(multiple of 13 channels). DMA stream threshold is set as half full.
I wanted to understand how long does it take the controller to swap memory address at end of each buffer fill. I am reading sine waves on some of the channels and can see some data points being missed when the memory address changes from buffer 1 to buffer 0.
The time period for which data is missed is in range 3-4ms.
I have checked other things which can lead to this issue like - timer trigger not happening properly, FIFO or transfer error, but none of these seem to be an issue.
I wanted to understand if the destination address swap can lead to this issue.
