STM32L151c8t6: Stopping and Starting ADC with DMA with HAL functions screws up channel order when using tickless Idle of FreeRtos.
I use ADC with DMA in cirular scan mode to convert two audio-channels triggered by a timer.
This all works well with expected results and quality most of the time.
For power-saving reasons I have to change the clock tree in runtime. This may screw up channels as dma clock will not be continuous in this case. Therefore I tried to Stop and Start the ADC-DMA-Conversion with HAL functions whenever clock tree has changed.
But I realize that also when no clock tree changes are made. (disabled that code) The stopping and immediate starting of ADC-DMA conversion may lead to mixed up channels (so rank 0 being on pos 1 in mem and rank 1 being on pos 0). In my case this may lead to total malfunction of the device as audio channels are swapped.
However I even don't find a way to detect if that issue happened. There are no Error-IRQ's or something fired neither on DMA nor on ADC. All registers are looking the same as if there was no error.
The only dirty work-around I can imagine for now is to configure the corresponding adc-channels to an output to get two fixed values while starting the adc and first check if the values are in range. If this is not the case one can again restart the adc which would fix the issue with a good propability.
Within further digging in I realized that this only happens if there is a task with a longer delay and no other task running in FreeRTOS, so I belive that there is a relation to the "Tickless Idle" which puts the processor into stop mode via WFI when there is a bigger task delay.
And et voila: If I disable "Tickless Idle" in FreeRtos this issue does not occur.
Unfortunately we need this as we need the power saving here.
Also a complete re-initialization using HAL_ADC_Init and HAL_ADC_DeInit when starting/stopping does not solve the problem.
If already digged the community and google, there are issues of swapped channels but I don't find a bigger correlation to my problem.
So I'm currently out of ideas:
- What may lead to that issue
- How could that issue be detected to fix it by re-initializing the peripherals.
Best Regards
Pascal
