GreenWaves-Technologies / gap_sdk

SDK for Greenwaves Technologies' GAP8 IoT Application Processor
https://greenwaves-technologies.com/en/gap8-the-internet-of-things-iot-application-processor/
Apache License 2.0
141 stars 78 forks source link

2D DMA transfer expected behaviour #394

Open bpervan opened 1 year ago

bpervan commented 1 year ago

Hi,

I'm doing some experiments which employ a 2d DMA transfer by invoking rt_dma_memcpy_2d. I'm genuinely unsure if I'm missing something or if the result might be wrong. I can't find any example whatsoever which demonstrates the utilization of the 2d DMA transfers in the codebase.

Consider the following minimal example:

Original array (5x3)
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

For the sake of simplicity, the data type of the array elements is uint8. Now, let's assume that I want to copy this array and place it within a larger array (7x5 of uint8) which has previously been memset to 0.

Now, with stride = 5 which is the width of the source matrix, and length = 7 which is the width of the destination matrix, and by offsetting the destination address by 8, I would expect to end up with something like this:

0 0 0 0 0 0 0
0 1 2 3 4 5 0
0 1 2 3 4 5 0
0 1 2 3 4 5 0
0 0 0 0 0 0 0

However, what I end up with is this:

0 0 0 0 0 0 0
0 1 2 3 4 5 1
2 1 2 3 4 5 1
2 1 0 0 0 0 0
0 0 0 0 0 0 0

The API call is: rt_dma_memcpy_2d((unsigned int) l2data, (unsigned int) l1data + 8, 3 * 5 * sizeof(uint8_t), 5, 7, RT_DMA_DIR_EXT2LOC, 0, &L2toL1);

What am I missing here? Might it be that I somehow miscomprehended the idea of 2d DMA transfers? Is it possible to employ 2d DMA transfers to achieve the expected behaviour?

Thanks!