How to debug DMA problems

So in a recent job interview I was asked how I would debug problems involving DMA. For example, if a DMA transfer I had setup was clobbering memory beyond what I had intended. I did some research afterwards and the one technique I seem to have found is using a logic analyzer hooked up to the system bus and having it trigger on a certain address range to see if the DMA controller is accessing beyond what it was intended. Are there any other sort of general techniques that can be used that aren't based on some sort of specialized on-chip debug hardware?

Is there some newsgroup that is better suited for this type of question, like an embedded software group?

Thanks,

Josh

Reply to
joshc
Loading thread data ...

This question probably has to do with the fact that in many architectures the DMA can access the memory only by pages. If the DMA overruns the page border, it will wrap to the beginning of the same page and corrupt it.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

The first thing I would do is scrutinize the documentation for the DMA and understand any quirks. Yes, you can use a logic analyzer (or scope with logic probes) to see the bus activity. You can also do experiments with changing the block length, setup technique, etc. The important point is to be able to change code and see the results quickly.

Software for embedded system IS a major topic in this newgroup.

--
Thad
Reply to
Thad Smith

I realize software is a common topic in this newsgroup, but because of the name it implies a focus on hardware. I'm aware of comp.realtime and comp.programming but wanted to make sure I wasn't missing a more appropriate newsgroup.

Reply to
joshc

And then there are cache coherency issues, where memory ranges used for DMA buffers must be flushed on "transmit" operations and invalidated on "receive" transfers. There are also issues with DMA buffers, cache line boundaries, and the potential for corrupting non-DMA data adjacent to DMA buffers.

--
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
Kennesaw, GA, USA 30144    http://mnmoran.org

"So often times it happens, that we live our lives in chains
  and we never even know we have the key."
The Eagles, "Already Gone"

The Beatles were wrong: 1 & 1 & 1 is 1
Reply to
Michael N. Moran

The question is how do you debug problems involving DMA, not what are the issues. I am well aware of the issues but if you see that a particular DMA transfer is not behaving as expected, how do you start debugging? I have not heard of a single reply to this point yet.

Reply to
joshc

How to debug depends on the issues. If you don't have a cache, then you don't have to worry about debugging cache coherency issues. Many DMA problems aren't even related to the DMA itself, but are just common software bugs that happen to involve some DMA actions. For instance, you could free() a network packet that's still in a queue somewhere, and is later used for some DMA transfer, possibly corrupting something else. Those bugs can be hard to find because the code involving the DMA and the DMA controller itself are working fine, and the actual mistake could have been made a minute earlier. There is not a universal method to catch all bugs involving DMA. It all depends on the way DMA is used in a system.

The last time I debugged some DMA problems, I modified the code that set up the DMA controller to verify the base address/length were both sane, and printed both of them to a remote log. As soon as a problem was detected in the memory contents, I would examine the past DMA transactions involving that particular area of memory. If I suspected a more complex interaction between modules, I would also add appropriate logging in other places.

Reply to
Arlet

... snip ...

You look at the source code, and think hard about corner timing issues. When you form a theory you create a jury rig to test it or to make the fault repeat. Practice cursing.

--
Chuck F (cbfalconer at maineline dot net)
   Available for consulting/temporary embedded and systems.
Reply to
CBFalconer

The first thing to determine is: is it a hardware or software issue ?. If you are bringing up a new piece of hardware for the first time, the hardware dma mechanisms need to be verified using software test harness etc. You use the test harness code to stimulate the hardware using random and other data patterns, together with scope and logic analysers to measure the results. Once you are sure that the hardware works, meets timing constraints etc, only then are you ready to start writng the application code. By this time, you are pretty sure the hardware is ok, so any faults can be found through standard debugging techniques.

DMA is largely a *hardware process* and programming should not be difficult if the hardware works and the programmer has a good understanding of the underlying transfer mechanisms and programming requirements...

Chris

Reply to
ChrisQuayle

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.