cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5G9 ADC weird DMA issue. Broken HAL driver?

HTD
Senior III

I have a STM32U5G9 based board. I use 2 ADCs, ADC1 and ADC2 in independent mode.

I need to measure changing voltages with a lot digital noise filtering. I achieve this by setting ADC to sample the signal to a memory buffer via DMA, then averaging the noise, and if the average shows significant difference from the previous run - a notification is sent to the program to react.

The basic idea is simple - read data from ADC continuously, so - I used circular buffer.

After fixing the last HAL package issue with removed `HAL_PWREx_EnableVddA()` call (I added the call, it's necessary for the ADC to work), I managed to have my setup up and running.

However, the problem starts when I stop the conversion, and then want to start it up again. So:

 
`HAL_ADC_Start_DMA` call - passes with `HAL_OK`.
 
`HAL_ADC_Stop_DMA` call - passes with `HAL_OK`.
 
But then again `HAL_ADC_Start_DMA` call - fails with `HAL_ERROR`, and as I figured out, internally `ADC_Enable` function fails with a time out. That just tells me nothing. I read STM32 forum thread about very similar issue that turned out to be VddA missing. The problem I get is identical behavior, but the VddA is OK, and the problem is triggered not at the first ADC start, but after the ADC is restarted. BTW, I start, stop, then start again it manually. There is plenty of time between those operations.
 
What I already tried was completely deinitializing the ADC1 with `HAL_ADC_DeInit` after stopping and reinitializing it with `HAL_ADC_Init` before starting again. It didn't help. I tried to use `HAL_ADCEx_RegularStop_DMA` instead of `HAL_ADC_Stop_DMA`, I even tried to use both. Nothing helps. When I try to stop continuous conversion, the ADC cannot be enabled again, the only way to make it work ever again is to power-cycle the MCU or use the reset button.
 
That is a very serious problem to me, because my device's new version uses only one ADC with changing regular conversion group to measure 2 different voltages. The point is - I don't need to have it done simultaneously, I use one at a time, so I really need only one ADC with 2 inputs. However, I have different sampling rates, filtering and buffer sizes for the signals, so in order to switch my measurements I need to stop ADC, change regular conversion group setup, switch the buffer and start the ADC circular DMA again. However, currently I see I can only start my ADC only once in the application life time, it doesn't start after being stopped.
 
Please help me. I don't know what to do next with this issue.
4 REPLIES 4
Saket_Om
ST Employee

Hello @HTD 

According to the reference manual (RM0456) the software is allowed to set ADEN only when all bits of ADC_CR registers are 0 (ADCAL = 0, JADSTART = 0, ADSTART = 0, ADSTP = 0, ADDIS = 0 and ADEN = 0) except for bit ADVREGEN which must be 1 (and the software must have wait for the startup time of the voltage regulator)

Saket_Om_0-1723192738795.png

Please check if these conditions are ok on your setup before calling again HAL_ADC_Start_DMA.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Ooopsie, I misread the register value. But it's not this:

HTD_0-1723201264061.png

As you see - the second pass (failed) passes through this check, so the CR state is valid.

It breaks later:

HTD_1-1723201398841.png

Line 4347 - just ADC_FLAG_RDY is not getting set in time.

Naturally, I checked what happens if I increase the timeout limit to 2 seconds, but obviously the ADC_FLAG_RDY doesn't get set at all, even one eternity later.

LCE
Principal

So the HAL driver starts ADC calibration, but it doesn't wait for it to finish?

HTD
Senior III

@LCE wrote:

So the HAL driver starts ADC calibration, but it doesn't wait for it to finish?


My bad, I misread the bit position, it's not a calibration issue. Please check my edited reply, when I provide more details from the debugger.