Is there a trade-off for memory to memory DMA transfer when the data size is small?

前端 未结 3 502
小鲜肉
小鲜肉 2021-01-24 11:41

I am learning about the STM32 F4 microcontroller. I\'m trying to find out about limitations for using DMA.

Per my understanding and research, I know that if the data si

相关标签:
3条回答
  • 2021-01-24 11:58

    DMA -CPU puts all its lines at high impedance state

    I do not know where did you take it from - but you should not use this source any more.

    Frequency of the DMA transfers do not matter unless you reach the the BUS throughput. you can transfer one byte per week, month, year, decade ..... and it is absolutely OK.

    In the STM32 microcontrollers it is a very important feature as we can transfer data from/to external devices even if the uC is in low power mode with the core (CPU) sleeping. DMA controller can even wake up the core when some conditions are met.

    0 讨论(0)
  • 2021-01-24 12:04

    The information is right in that using a DMA requires some development work and some runtime to manage the DMA transfer itself (see also a related question here), which may not be worth the benefits of using DMA. That is, for small portions of data one doesn't gain as much performance (or latency) as during big transfers. On embedded systems, DMA controllers (and their channels) are limited resources so it is important to consider which part of the function benefits from such a resource most. Therefore, one would usually prefer using DMA for the data transfers to/from disks (if it is about "payload data" such as large files or video streams) over slow serial connections.

    The information is wrong, however, in that DMA is not worth using on serial interfaces as those only transfer a single bit at a time. Please note that microcontrollers (as your STM32F4) have built-in peripheral components that convert the serial bit-by-bit stream into a byte-by-byte or word-by-word stream, which can easily be tranferred by DMA in a helpful way - especially if the size of the packets is known in advance and software doesn't have to analyse a non-formatted stream. Furthermore, not every serial connection is "slow" at all. If the project uses, e. g., an SPI flash chip, then the SPI serial connection is the one used for data transfer.

    0 讨论(0)
  • 2021-01-24 12:20

    As @Vinci and @P__J__ already pointed out,

    1. A DMA controller works autonomously and doesn't create overhead on the CPU it supplements (at least not by itself). But:

    2. The CPU/software must perform some instructions to configure the DMA and to trigger it or have it triggered by some peripheral. For this, it needs CPU time and program memory space (usually ROM). Besides, it usually needs some additional RAM in variables to manage the software around the DMA.

      Hence, you are right, using a DMA comes with some kinds of overhead.

    And furthermore,

    1. The DMA transfers make use of the memory bus(es) that connect the involved memories/registers/peripherals to the DMA controller. That is, while the DMA controller does its own work, it may cause the CPU which it tries to offload to stall in the meantime, at least for short moments when the data words are transferred (which in turn sum up for longer transfers...).

    On the other hand, a DMA doesn't only help you to reduce the CPU load (regarding total CPU time to implement some feature). If used "in a smart way", it helps you to reduce software latencies to implement different functions because one part of the implementation can be "hidden" behind the DMA-driven data transfer of another part (unless, both rely on the same bus resources - see above...).

    0 讨论(0)
提交回复
热议问题