Skip to main content
Timothy Smieja
Associate II
November 6, 2017
Question

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

  • November 6, 2017
  • 4 replies
  • 2753 views
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?

    This topic has been closed for replies.

    4 replies

    Tesla DeLorean
    Guru
    November 6, 2017
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    S.Ma
    Principal
    November 7, 2017
    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
    November 7, 2017
    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

    S.Ma
    Principal
    November 7, 2017
    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...

    Timothy Smieja
    Associate II
    November 7, 2017
    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.

    Tesla DeLorean
    Guru
    November 8, 2017
    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 VenmoUp vote any posts that you find helpful, it shows what's working..