FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP

dma instability

Altera_Forum
Honored Contributor II
1,837 Views

Hi...i am tring to copy memory from sram to sdram using dma. 

For some reason some of the data dosent transfered... 

Are there any suggestions what to look for to solve this problem? 

Thanks. 

Asaf
0 Kudos
13 Replies
Altera_Forum
Honored Contributor II
322 Views

Try SGDMA - works fine.

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

Might be caused by the cpu reading data from the data cache, and/or writing dirty cache lines back over the copied data.

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

does the sgdma has the same functions

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

how can I fix the dirty cache lines?

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

I'm assuming you are trying to do something like this: 

 

1) Using Nios II to populate some buffer in memory (lets call this buffer A) 

2) DMA data from buffer A to another buffer (lets call this buffer B ) 

3) Using Nios II to read back buffer B 

 

Doing this the data written in# 1 should be the same as the data read back in# 3 but due to the cache this isn't happen. 

 

So for# 1 to be safe you need to ensure the data is not cached and reaches the memory. There are two ways you can do this, A) if you are using pointers remap the pointer to be a cache bypassing pointer, or B ) after you write to the buffer perform a cache flush (just flush the range of address where your buffer resides in memory). When this is done then you can start the DMA. 

 

For# 3 to be safe (just in case you have previously read from the buffer B locations previously) you can do something similar. Either flush those locations before the DMA transfer, or use a cache bypassing pointer to access the data after the DMA transfer. 

 

Depending on your memory latencies and buffer sizes one method will be better than the other. For example if the buffers were on-chip memory using cache bypassing pointers is probably the way to go. If it was SDRAM then flushing ranges of the data cache would probably be better due to the high latency.
0 Kudos
Altera_Forum
Honored Contributor II
322 Views

Thanks..can you please give me an example to do that? 

And about rhe agdma..i couldnt find a memory to memory example. 

Can someone give me an example? 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
322 Views

Thanks...i.used the flush and malloc. 

I can see that the addresses in signal tap. 

Sometimes the address jumps by more then 1..what are the reasons
0 Kudos
Altera_Forum
Honored Contributor II
322 Views

Firstly do tests with on-chip memory and enable memory content editor function. You'll be able to see memory contents live.

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

If you are getting memory with malloc() that is either uncached, or for which you are doing explicit cache operations, you do need to make sure that you only use a cache-aligned part of the buffer. 

The altera function to malloc() uncached data doesn't stop the cache line being shared!
0 Kudos
Altera_Forum
Honored Contributor II
322 Views

If you want to always bypass the cache with the allocated pointers then I recommend using the uncached version of malloc. I forget what it's called but it's most likely "uncache_malloc". If you search through the software handbook you should be able to find it where all the other cache bypassing APIs are located. Using uncache_malloc will ensure that the data cache gets flushed before you attempt to use the pointer to avoid the issue dsl is talking about. The cache/uncache remapping APIs should do the same thing safely for you as well. 

 

*edit* Also do you need to allocate pointers? I usually try to avoid malloc since I don't like debugging stack and heap collisions :)
0 Kudos
Altera_Forum
Honored Contributor II
322 Views

but i used malloc...the problem is with the dma address changing..I can see it with signal tap.

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

I'm not sure if I follow. If you mean that you think cache isn't a problem because you see the DMA addressing incrementing then that's not what we are talking about. We are talking about the data that you are accessing before and after the transfer. If you do not take care of cache coherency of the data then the DMA may not transfer the data you populated in the memory (because it may still be allocated in the cache).

0 Kudos
Altera_Forum
Honored Contributor II
322 Views

so how do i take care of it? 

i tried dcache_malloc, flush the cache before I call DMA...what else can i do?
0 Kudos
Reply