Skip to main content
Visitor II
January 16, 2025
Question

DMA: last written buffer position?

  • January 16, 2025
  • 3 replies
  • 756 views

DMA buffer 32 words, ADS converts 4 channels in scan mode.
So every 8 ADC-starts  DMA will start at buffer[0]  (circular buffer is ticked).
CubeIDE HAL is being used.

How do I find out / look up  the buffer offset most recently written to?

    This topic has been closed for replies.

    3 replies

    Explorer
    January 16, 2025

    Look into DMA registers, there is a counter

    Visitor II
    January 17, 2025

    If you use DMA and the callbacks (for Half or Full) - you should know where you are (which buffer was filled recently).

    Yes, you might be able to read back also DMA registers (e.g. address pointer). Easier is to use callbacks, double buffering and knowing when DMA INT comes which buffer was (completely) written...

    Graduate II
    January 17, 2025

    There is a macro named __HAL_DMA_GET_COUNTER(handle) that returns the number of remaining data bytes in the current DMA Channel transfer.

    PRenn.1Author
    Visitor II
    January 17, 2025

    We need to clarify some vocabulary first:  Do you mean

    the remaining data bytes the currently active DMA transfer still has to copy
    (of a 4 conversions ADC session, 2 conversion still outstanding)

    or

    the remaining data bytes in the assigned DMA destination buffer (in "user" memory)
    before cyclic DMA transfer will wrap back to start of buffer ?

    Explorer
    January 17, 2025

    It's second. Just try, making slow sampling rate (~1 sec) you can observe all processes in details.