2019-11-08 01:00 PM
NOTE: I have built a test project in STM32CubeIDE to demonstrate this issue (see attached). (Change "POSITION" from 1 to 2 to demonstrate the bug - see line 164 in main.c).
I am reading multiple ADC channels on a custom board with a STM32F030RCT6TR. I have 8 channels defined in my Cube project and am using DMA and the callback function to know when it's finished.
At startup, I call HAL_ADC_Start_DMA() to get things going. Then, in my main loop I look for completion by examining a variable set by the callback function. If the readings are complete, I dump their values out a serial port and then start another conversion with HAL_ADC_Start_DMA().
The weirdness is that if I run these reads as fast as possible, they work OK. However, if I only check them every 500 milliseconds, I see only one read - and the subsequent read never completes.
Any thoughts?
2019-11-13 10:01 AM
A possible breakthrough!
In my step 4 above: My completion callback routine was calling HAL_ADC_Stop_DMA() - and I wasn't sure if that was necessary or not.
Inside this function, there is a call to HAL_DMA_Abort() - which is getting an error (presumably because the DMA operation has completed). This causes the HAL_ADC_STATE_ERROR_DMA bit to be set in the ADC State variable.
This bit is apparently not getting cleared - so when the second ADC/DMA operation completes, the completion interrupt sees this bit is set, calls my Error callback, and never finishes. (Even though the hardware finished OK).
I believe this is a bug in the HAL library (STM32Cube_FW_F0_V1.11.0) - but I'm not entirely sure where the fix should be. For now, I've stopped calling HAL_ADC_Stop_DMA() and that seems to get me past this bug.
P.S.: I'm sampling the ADC values multiple times for each channel - so I've set the configuration to run continuously. This is why I thought I needed the Stop_DMA call.
I'm still not reading the correct ADC values - but that's a problem for another day...
2019-11-15 02:28 PM
In case anyone is reading this, my "last" bug (the DMA not reporting the correct results) is documented in this thread: https://community.st.com/s/question/0D50X0000BbMcnpSQC/dma-adc-doesnt-work
It's a known bug in CubeIDE. The DMA Initialization needs to be done before the DMA Initialization.
2019-11-15 02:55 PM
I posted this earlier, but it didn't seem to take...
My "last" bug has been fixed. It's a CubeIDE bug having to do with the DMA clock not being enabled before the ADC init calls HAL_DMA_Init(). There's a discussion about this bug here: https://community.st.com/s/question/0D50X0000BbMcnpSQC/dma-adc-doesnt-work