Author Topic: DMA ram to ram  (Read 2647 times)

0 Members and 1 Guest are viewing this topic.

Offline NihiTopic starter

  • Newbie
  • Posts: 4
  • Country: dk
DMA ram to ram
« on: September 08, 2015, 08:59:35 pm »
Hello everyone,

I am trying the dma_led_pattern example on pic32mz ef sk Evaluation board. What it does is basically to load the bytes from the array to the port H every time the Timer goes overflow.
It works fine.
Now, I want to load this source-array into another Array instead of PORTH but while debugging I can't see any data in the destination array.
Here the code that shows what I am trying to accomplish.

Original working code:
Code: [Select]
const unsigned char LED_pattern[]=
{
0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x02,
0x04, 0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01,
0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x01, 0x01
};

#include "framework/system/dma/sys_dma_static.h"

void SYS_DMA_Channel0TransferAdd(void)
{
   
   /* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
   PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);
   PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATH);

   /* Set the source and destination sizes */
   PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);
   PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 2);

   /* Set the number of bytes per transfer */
   PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);
}


my code:
Code: [Select]
const unsigned char LED_pattern[]=
{
0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x02,
0x04, 0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01,
0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x01, 0x01
};

#include "framework/system/dma/sys_dma_static.h"

volatile uint16_t LATHbuffer[24];

void SYS_DMA_Channel0TransferAdd(void)
{
   
   /* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
   PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);
   PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATHbuffer[0]);

   /* Set the source and destination sizes */
   PLIB_DMA_ChannelXSourceSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);
   PLIB_DMA_ChannelXDestinationSizeSet(DMA_ID_0, DMA_CHANNEL_0, 24);

   /* Set the number of bytes per transfer */
   PLIB_DMA_ChannelXCellSizeSet(DMA_ID_0, DMA_CHANNEL_0, 1);
}




The LATHbuffer is always empty showing 0x00.
What am I doing wrong?
I appreciate any help. Thank you in advance.
« Last Edit: September 08, 2015, 09:02:07 pm by Nihi »
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: DMA ram to ram
« Reply #1 on: September 09, 2015, 02:45:05 am »
Try adding a memcmp to verify the contents of the buffer. IIRC MPLAB X has some problems with refreshing memory contents.

Offline NihiTopic starter

  • Newbie
  • Posts: 4
  • Country: dk
Re: DMA ram to ram
« Reply #2 on: September 09, 2015, 06:46:15 am »

Thank you for the Suggestion.
I tried to check in the main Loop if the content of the destination buffer is ever > 0.
But not luck.
I am able to see the port H register changing but my buffer is not.
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: DMA ram to ram
« Reply #3 on: September 09, 2015, 09:48:06 am »
...
Code: [Select]
const unsigned char LED_pattern[]=
{
0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x02,
0x04, 0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01,
0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x01, 0x01
};

#include "framework/system/dma/sys_dma_static.h"

volatile uint16_t LATHbuffer[24];

...   
   /* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
   PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);
   PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATHbuffer[0]);
...
}

I know nothing about PICs or the library they are using, but it strikes me as odd that you are using two ways of specifying the addresses of the arrays involved: a)only using the array name without any [], and b) explicitly using &arrayname[0].  Theoretically both are equivalent, of course, and hsould work, but personally I would stick to one of the two options (the first).

Also, why are the two arrays of different size/type (assuming unsigned char is an 8-bit value on PICs)?
my random ramblings mind-dump.net
 

Offline NihiTopic starter

  • Newbie
  • Posts: 4
  • Country: dk
Re: DMA ram to ram
« Reply #4 on: September 09, 2015, 11:36:01 am »
...
Code: [Select]
const unsigned char LED_pattern[]=
{
0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x02,
0x04, 0x01, 0x02, 0x04, 0x01, 0x02, 0x04, 0x01,
0x02, 0x04, 0x01, 0x02, 0x04, 0x01, 0x01, 0x01
};

#include "framework/system/dma/sys_dma_static.h"

volatile uint16_t LATHbuffer[24];

...   
   /* Set the source and destinaton addresses (addresses are converted from virtual to physical) */
   PLIB_DMA_ChannelXSourceStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)LED_pattern);
   PLIB_DMA_ChannelXDestinationStartAddressSet(DMA_ID_0, DMA_CHANNEL_0, (uint32_t)&LATHbuffer[0]);
...
}

I know nothing about PICs or the library they are using, but it strikes me as odd that you are using two ways of specifying the addresses of the arrays involved: a)only using the array name without any [], and b) explicitly using &arrayname[0].  Theoretically both are equivalent, of course, and hsould work, but personally I would stick to one of the two options (the first).

Also, why are the two arrays of different size/type (assuming unsigned char is an 8-bit value on PICs)?

Thank you Andreas for your remarks.

I know nothing about PICs or the library they are using, but it strikes me as odd that you are using two ways of specifying the addresses of the arrays involved: a)only using the array name without any [], and b) explicitly using &arrayname[0].  Theoretically both are equivalent, of course, and hsould work, but personally I would stick to one of the two options (the first).

--> In either ways with or without & + [ ] I get the same address. I have tried both I got the same result.
I specified the first element of the array because I saw it in another Pic example provided by microchip. 

Also, why are the two arrays of different size/type (assuming unsigned char is an 8-bit value on PICs)?

--> The elements of LED_pattern are 2-byte so I guess is the same if create an array of 16-bit elements. But let me try if keeping the same type it works out.
« Last Edit: September 09, 2015, 11:42:23 am by Nihi »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf