Michael Heidinger

KDS Kinetis DMA Example

Discussion created by Michael Heidinger on May 2, 2016

Dear all,

as I had a hard time figuering the DMA out, i created a simple example, showing a simple copy example for the DMA with error checking maybe somebody will find this useful.

uint8_t source[]={0,1,2,3,4,5,6,7,8,9}; uint8_t dest[10];  void dma_idiotentest(void){     SIM->SCGC6|=SIM_SCGC6_DMAMUX0_MASK;     SIM->SCGC7|=SIM_SCGC7_DMA_MASK;      DMAMUX0->CHCFG[1]=0; //set to zero during configuration      //Enable request signal for channel 1     DMA0->ERQ=DMA_ERQ_ERQ1_MASK;      //Set memory address     DMA0->TCD[1].SADDR=(uint32_t) &source;     DMA0->TCD[1].DADDR=(uint32_t) &dest;      //Offset for source and destination     DMA0->TCD[1].SOFF=1; //We increment the address by one, after each cycle     DMA0->TCD[1].DOFF=1;      //Source and destination data transfer size     DMA0->TCD[1].ATTR=DMA_ATTR_SSIZE(0)|DMA_ATTR_DSIZE(0);       DMA0->TCD[1].NBYTES_MLNO=10;      DMA0->TCD[1].CITER_ELINKNO=DMA_CITER_ELINKNO_CITER(1);     DMA0->TCD[1].BITER_ELINKNO=DMA_BITER_ELINKNO_BITER(1);      DMAMUX0->CHCFG[1]=DMAMUX_CHCFG_ENBL_MASK|DMAMUX_CHCFG_TRIG_MASK | DMAMUX_CHCFG_SOURCE(58); //always enabled      DMA0->TCD[1].CSR=DMA_CSR_DREQ_MASK | DMA_CSR_START_MASK;      if(DMA0->ES){         //Page 396         if(DMA0->ES & (1<<0)) {             //Destination Bus error             redLedOn();         }         if(DMA0->ES & (1<<1)) {             //Source Bus error             redLedOn();         }         if(DMA0->ES & (1<<2)) {             //Scatter/Gather Configuration Error             redLedOn();         }         if(DMA0->ES & (1<<3)) {             //NBYTES/CITER configuration Error             redLedOn();         }         if(DMA0->ES & (1<<4)) {             //Destination Offset error             redLedOn();         }         if(DMA0->ES & (1<<5)) {             //Destination Address Error             redLedOn();         }         if(DMA0->ES & (1<<6)) {             //Source offset error             redLedOn();         }         if(DMA0->ES & (1<<7)) {             //Source address error             redLedOn();         }     }else{         redLedOff();     } }


This example is based on the pretty old "Using the DMA module in Kinetis devices.