cancel
Showing results for 
Search instead for 
Did you mean: 

How do I disable or lock the ADC or DMA so I can quickly grab the stored samples in the buffer?

Timothy Smieja
Associate II
Posted on November 06, 2017 at 20:47

I am using the STM32F427 micro and a Keil compiler. I have ADC1 and 2 configured for dual simultaneous mode and scanning through 12 conversions. Three ADC conversions for each of four different dual ADC channel inputs. How do I disable or lock the ADC or DMA so I can quickly grab the data in the buffer and then release it. Do I have to disable all interrupts?

7 REPLIES 7
Posted on November 06, 2017 at 23:48

It is better to have a double sized buffer, circular DMA, and use the DMA HT and TC interrupts to copy the inactive half.

Ideally the halves should hold some multiple of your single set to decimate interrupt loading.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on November 07, 2017 at 05:07

It depends what you want to do, if you don't care losing any sampled data or not.

When you have to read the values, change the DMA writing area temporarily to a dummy RAM array, or better a second identical buffer as Clive said. It's like transporting water with 2 or more buckets from a funtain.

Timothy Smieja
Associate II
Posted on November 07, 2017 at 17:55

Thanks for your input. Can you confirm what I think you are saying?

Currently I am sampling 12 dual mode samples in scan mode with the DMA set to circular. I am also currently transferring the data from the DMA buffer to variables in HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef*).

I believe what you are saying is that I need to double my current DMA buffer and transfer the data from the first half of the DMA buffer into one set of memory locations using the HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef*), then on the next sample transfer the data from the second half of the DMA buffer into another set of memory locations using the HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef*). I assume I would need to toggle a flag to know what data set contains is 'inactive' and the last datasampled, correct?

Also, just by doubling the buffer size does the ADC and DMA know to interrupt at half complete? or is there a config setting I need to set? I did not see anything in cube.

Sincerely,

trs

Posted on November 07, 2017 at 21:23

Usually the half complete is a DMA interrupt possibility.

On some DMA/STM32 there is also double buffer (you can define 2 separate data blocks and hop between one another).

If you want to backup quickly your half buffer, you could also use a DMA memory to memory, however, in the end, pushing around the data still need to be processed on time...

Posted on November 07, 2017 at 21:43

Not touching the HAL stuff, I've demonstrated these techniques using the SPL

The DMA has HT and TC interrupt settings, the IRQ Handler for the DMA then has a window in which the data in the inactive portion of the buffer can be copied out or worked on.

The DMA can be set up once with a buffer/size definition, and it circular mode will just keep rolling around continuously until torn down. The HT (Half-Transfer) IRQ will fire at size/2, and TC (Transfer-Complete) at size.

The ADC is just configured to fire a DMA request to service the EOC (End-of-Conversion) for each sample or pair of samples.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Timothy Smieja
Associate II
Posted on November 08, 2017 at 00:05

So are you saying that I really should be using the DMA HT and TC callback rather than the HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef*) and HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef*) callbacks?

I looked at the DMA functions in stm32f4xx_hal_dma.c and stm32f4xx_hal_dma_ex.c and do not necessarily see where I can catch the HT and TC callbacks. I might be missing it though.

Posted on November 08, 2017 at 01:00

>>

So are you saying that..

I think I'm being fairly explicit about the how the hardware functions, and how the HAL implementation works is something you'll have to own.

The HAL abstracts the snot out of everything, the SPL implementation is relatively simple. You should do a code walk of the HAL ADC library code so you understand the mechanics. You have to call back into the HAL from the DMA IRQ Handler and that calls your callbacks.

https://community.st.com/0D50X00009XkibiSAB

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..