🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

DMA Controllers, Transfers, and Circular Buffers

Microcontrollers & ARMADC, DMA and SerialđŸŸĸ Free Lesson

DMA Controllers, Transfers, and Circular Buffers

What You'll Learn

  • 1Describe DMA channel and stream configuration
  • 2Set up memory to peripheral and memory to memory transfers
  • 3Implement circular and double buffered modes
  • 4Handle DMA completion and error interrupts

The direct memory access controller moves data between peripherals and memory without the CPU on every byte, which frees the processor for control math. A transfer is described by a source address, a destination address, a count, and a set of increment and width flags, all held in channel registers. Circular mode wraps the count back to zero and keeps running, which is exactly what continuous ADC scans and audio streams need. Done well, DMA removes both the data movement overhead and the overrun bugs that polling creates.

Channels, Requests, and Transfer Descriptors

Some parts give the DMA a fixed set of channels mapped to specific peripherals, while others use a request multiplexer that routes any peripheral request to any stream. A descriptor sets the source and destination addresses, whether each address increments, the data width of each beat, and the total number of beats. Alignment must be respected, because a byte transfer to a halfword aligned address is a fault on many parts.

Priorities decide which stream wins arbitration when several request at once, and the priority should reflect the cost of a delayed beat rather than the peripheral importance. Memory to memory transfers run at full bus bandwidth and are useful for moving frames, relocating tables, or clearing buffers in the background.

Circular Mode and Double Buffering

Circular mode reloads the transfer count automatically when it reaches zero, so the stream runs forever writing into a ring of memory. The half transfer interrupt marks the midpoint, which lets the CPU process the first half of a buffer while DMA fills the second. This ping pong pattern is the standard way to stream audio, serial, or sensor frames without gaps.

Double buffered mode swaps between two target addresses on each transfer complete, giving the CPU a whole buffer at a time and removing the race where DMA overwrites data the CPU has not read yet. The cost is an extra interrupt and careful ownership rules, but the result is a clean producer consumer boundary.

Integration With Peripherals and the CPU

For ADC scans, DMA is triggered by the end of conversion and writes each result into an array, which eliminates overrun completely. For transmit paths such as UART or SPI, DMA refills the peripheral data register from a buffer and pends an interrupt only when the whole frame is out. Coherency matters when the CPU and DMA share cacheable memory, because one side can observe stale data unless caches are cleaned and invalidated around the exchange.

Debugging DMA means checking the enable bit, the remaining count, the channel interrupt flags, and whether the peripheral clock and request are actually asserted. A stream that never starts is almost always a missing request or a misaligned descriptor rather than a silicon fault.

DMA Configuration Fields

FieldPurposeCommon Choice
Source addressWhere data startsPeripheral data register or RAM buffer
Destination addressWhere data landsRAM buffer or peripheral register
Increment flagsWhether addresses advanceOn for buffers, off for registers
Data widthByte, halfword, or word per beatMatch the peripheral register size
Transfer countNumber of beatsReload for circular, stop for one shot
PriorityArbitration between streamsGive urgent streams higher priority

Real-World Examples

  • ADC scan into a buffer — Enable DMA request from the ADC, point it at a result array, and run in circular mode with a half transfer interrupt.
  • UART transmit without blocking — Start a DMA send of the frame, then handle the complete interrupt to chain the next frame.
  • Move a lookup table — Use a memory to memory transfer to copy a table into SRAM once at boot.
  • Audio double buffering — Swap buffer targets on transfer complete so the CPU always has a stable block to filter.

💡Watch the Remaining Count

A DMA stream that appears stuck usually has a remaining count of zero with the enable cleared by hardware, or a peripheral request that never asserts.

Common Mistakes

Mismatching data width and register size

Fix: Byte DMA into a word only register leaves stale bytes in the upper positions.

Sharing cacheable memory without coherency

Fix: Clean the CPU cache before DMA reads and invalidate it before the CPU reads, or data will be stale.

Forgetting to clear status flags first

Fix: Leftover transfer complete flags can pend an interrupt immediately after enabling the stream.

Key Takeaways

  • DMA descriptors define addresses, widths, increments, and beat count.
  • Circular and double buffered modes build gap free data streams.
  • DMA removes overrun in ADC scans and blocking in serial transmit.
  • Cache coherency must be handled when CPU and DMA share memory.

Frequently Asked Questions

Does DMA need interrupts?

No, it can run purely polled, but interrupts are how you know a block is ready without wasting cycles polling.

What is the difference between a channel and a stream?

Terminology varies by vendor; a stream is a DMA path that can be routed to a request, while a channel is a fixed peripheral binding.

How much CPU time does DMA save?

It removes per byte interrupt overhead entirely, leaving only per block processing, which typically cuts interrupt load by an order of magnitude.

Interview Questions

Q1: Describe a circular DMA receive scheme.

DMA writes into a ring buffer with a reload count, pends an interrupt at the half and full points, and the CPU consumes whichever half is not being written.

Q2: How do you debug a DMA transfer that never starts?

Check the peripheral clock, the request enable, the stream enable, address alignment, remaining count, and any pending error flags in order.


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Related Tutorials

Content with similar topics across other courses

Need Expert Microcontrollers & ARM Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement