Re: Why is DMA transferring garbage to first 7 bytes?
2019/07/29 02:03:16
(permalink)
There are two things:
First, the PIC usually uses the cache, while the DMA works with the (uncached) memory directly. So the memory used by DMA and the cache used by the PIC would get out of sync unless you implicitly care about it. Using __attribute__((coherent)) fixes this in an easy way, by moving the data for the PIC into uncached memory.
Second, there was a problem with the compiler. Probably it no longer applies to the latest version, because some stuff got fixed in v1.43. The problem was with the linker or the default linker script. It allowed to place normal cached variables directly next to uncached variables, which where defined with __attribute__((coherent)). And it did even allowed to place them together into the same cache page, which will just cause terrible things, as soon as the cache gets written back to memory. To fix this in an easy way you just make sure that the coherent data always covers the memory of the corresponding cache pages completely. __attribute__((aligned(16))) will do this, as each cache page has 16 bytes. So no cached variable can get placed into the same cache page together with coherent stuff.
I don't have any real experience with DMA so I can't help you, m4l490n. The only thing I noticed, is the coincidence that you use the 7th DMA channel and you have 7 byte offset. But I guess you already checked, that nothing got mixed up in that way.