Bug in DMA transfers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bug in DMA transfers

1,001 Views
aliasadzadeh
Contributor II

Dear All

I want to put a 4 element int to another 16 element int with DMA,

Here is the code

static uint32_t test_source[4]={1,2,3,4};

static uint32_t test_dest[16]={0};

//DMA

//Enable DMA MUX

SIM->SCGC6 |= SIM_SCGC6_DMAMUX_MASK;

// Disable DMA MUX channel first

DMAMUX0->CHCFG[0] = 0x00;

// Clear pending errors and/or the done bit

if (((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_DONE_MASK) == DMA_DSR_BCR_DONE_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_BES_MASK) == DMA_DSR_BCR_BES_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_BED_MASK) == DMA_DSR_BCR_BED_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_CE_MASK) == DMA_DSR_BCR_CE_MASK))

DMA0->DMA[0].DSR_BCR |= DMA_DSR_BCR_DONE_MASK;

// Set Source Address

  DMA0->DMA[0].SAR = (uint32_t )&test_source;

// Set destination address

  DMA0->DMA[0].DAR = (uint32_t )&test_dest;

  // Set BCR to know how many bytes to transfer

  DMA0->DMA[0].DSR_BCR = DMA_DSR_BCR_BCR(64);

  // Clear Source size and Destination size fields.

  DMA0->DMA[0].DCR &= ~(DMA_DCR_SSIZE_MASK | DMA_DCR_DSIZE_MASK);

// Set DMA as follows:

  // Source size is byte size

  // Destination size is byte size

  // D_REQ cleared automatically by hardware

  // Destination address will be incremented after each transfer

  // Cycle Steal mode

  // External Requests are enabled

  // Asynchronous DMA requests are enabled.

  DMA0->DMA[0].DCR |= (DMA_DCR_SSIZE(0)

  | DMA_DCR_DSIZE(0)

  | DMA_DCR_D_REQ_MASK

  | DMA_DCR_DINC_MASK

  | DMA_DCR_SINC_MASK

  | DMA_DCR_ERQ_MASK

  //| DMA_DCR_CS_MASK

  | DMA_DCR_ERQ_MASK

  | DMA_DCR_EADREQ_MASK

  | DMA_DCR_EINT_MASK

  | DMA_DCR_SMOD(3)

  );

  // Enables the DMA channel and select the DMA Channel Source

  //DMAMUX0->CHCFG[0] = 0x02; // Select UART0 as the Channel Source

  DMAMUX0->CHCFG[0] |= DMAMUX_CHCFG_ENBL_MASK; // Enable the DMA MUX channel

  NVIC_EnableIRQ(DMA0_IRQn);

  DMA0->DMA[0].DCR |= DMA_DCR_START_MASK;

void DMA0_IRQHandler()

{

  // Clear pending errors and/or the done bit

  if (((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_DONE_MASK) == DMA_DSR_BCR_DONE_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_BES_MASK) == DMA_DSR_BCR_BES_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_BED_MASK) == DMA_DSR_BCR_BED_MASK)

  | ((DMA0->DMA[0].DSR_BCR & DMA_DSR_BCR_CE_MASK) == DMA_DSR_BCR_CE_MASK))

  DMA0->DMA[0].DSR_BCR |= DMA_DSR_BCR_DONE_MASK;

  // Set BCR to know how many bytes to transfer

  DMA0->DMA[0].DSR_BCR = DMA_DSR_BCR_BCR(64);

  // Set Source Address (this is the UART0_D register

  DMA0->DMA[0].SAR = (uint32_t )&test_source;

  // Set destination address

  DMA0->DMA[0].DAR = (uint32_t )&test_dest;

}

But After I run the code instead of getting 1,2,3,4,1,2,3,4... in test_dest I will get

1,2,3,4,0,1,2,3,4,0,1,2,3,4,0x02DC6C00,0

what is wrong with this Code?

Labels (1)
0 Kudos
4 Replies

495 Views
Monica
Senior Contributor III

Ali, was this helpful?

Please let us know! :smileywink:

Regards

0 Kudos

495 Views
lothar
Contributor II

Hi

Ali Asadzadeh schrieb:

 

static uint32_t test_source[4]={1,2,3,4};
static uint32_t test_dest[16]={0};

I would write:

  1. static uint32_t test_source[]={1,2,3,4};  // Compiler counts the array size itself
  2. static uint32_t test_dest[16]; // I think they are initialized to 0 anyway and like that you only put the first element to 0


Ali Asadzadeh schrieb:

// Set Source Address
  DMA0->DMA[0].SAR = (uint32_t )&test_source;

Im not sure about this one. Your variable test_source is an array. Therefor in test_source[0] there is a one. But test_source without [] is a pointer, pointing to the first value of your array (*test_source is also = 1). So you probably like to write:

DMA0->DMA[0].DAR = (uint32_t )test_source;

or

DMA0->DMA[0].DAR = (uint32_t )&test_source[0];

At the moment you give an address of a variable in which a address is stored.

Maybe I'm wrong Smiley Wink

greez

0 Kudos

495 Views
JimDon
Senior Contributor III

Just wondering did you mean | or || in your  if statements?

0 Kudos

495 Views
aliasadzadeh
Contributor II

I meant | (or) in my if statement, Do you know what's wrong?

0 Kudos