I am using the CortexM4 coprocesor on the STM32MP157F-DK2 to measure multiple ADC channels and update a control loop based on the values. I have set up ADC1 using the DMA2 in circular mode to read channels IN1, IN2, and IN4. I have a buffer set up in which I place the values of the ADC. I also have a timer running so that upon the timer event, the ADC conversion is trigger. ADC1 is set up so that IN1, IN2, and IN4 have rank 1, rank2, and rank3 respectively. The problem I am facing is that each time I restart the DMA(firmware restart), it changes the index of the DMA buffer for each ADC channel. So for example, during testing, I have IN1 connected to 3.3V, IN2 connected to 0V and IN4 connected to 1.65V.
The first time I stop the DMA and read the buffer I see these values.
This makes sense because the first channel should be highest, second channel should be around 0, and third channel should be about half the first channel. However, after running my code and stop/start the DMA multiple times, I can see that the buffer shows the following:
Now, the IN2 value seems to be in the  index spot of the buffer, IN4 in the  index spot, and IN1 in the  index spot.
I have to stop the DMA every time I stop the firmware/coprocesor M4 from the embeddedLinux cortexA7.
How do I specify the index of each ADC channel in the DMA buffer so that it is consistent each time? Or at least how can I keep it from changing? I would like to be able to stop the firmware and relaunch it without this issue.
Is the DMA interrupt not synchronized with the DMA buffer? Perhaps if the ADC is synchronized with the DMA buffer then it might be possible to use the DMA full or half full interrupt to synchronize the data.
I think I'm synchronizing the DMA with the ADC through the HAL_ADC_Start_DMA() function. The problem with the indexing its only when I restart the firmware. Once the firmware it is launched, the indexing is constant but different from the previous firmware.