ADC with DMA in circular mode: how do you process the half-full buffer without losing samples?
I am setting up continuous ADC sampling with DMA in circular mode on an STM32, with the half-transfer and transfer-complete callbacks splitting the buffer into two halves for processing. The sampling rate is fairly high, and I am trying to understand the practical limits of this pattern. If the processing in one callback takes longer than the time it takes the DMA to fill the next half, samples get overwritten, but how do people normally detect that this has happened in production code? Do you rely on the DMA overrun flag, keep a timestamp or counter in each callback to spot a missed half, or simply size the buffer so the worst-case processing time always fits? I would also like to know whether there is a recommended way to double-buffer with two separate arrays instead of one circular buffer, and whether that makes overrun detection any easier. Any examples of how you have structured this in a real project would be very helpful.
