AnsweredAssumed Answered

K80 DMA

Question asked by Grzegorz Mikitiuk on Jul 18, 2018
Latest reply on Aug 4, 2018 by Grzegorz Mikitiuk

Hello,

I never used DMA before but i'm struggling with one thing. I got simple code which should copy one array to another with DMA, trigerred by falling edge on GPIO. It works only for the first time, any other falling edges never copy arrays again. 

 

I noticed that clearing DMA_CSR_DONE_MASK solves the problem but it's not good idea to clear it all the time in main loop. Shoudn't it reset everytime there is a falling edge on the GPIO? or should i reset it in interrupt generated by DMA?

 

Thanks

 

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MK80F25615.h"
#include "fsl_debug_console.h"

volatile uint8_t bufornadawczy[3]={0x0D,0x0C,0x0B};
volatile uint8_t buforodbiorczy[3]={0,0,0};


void dma_init(void)
{
DMAMUX -> CHCFG[0] = (DMAMUX_CHCFG_ENBL_MASK |DMAMUX_CHCFG_SOURCE(51));
DMA0->ERQ |= DMA_ERQ_ERQ0_MASK;

DMA0->TCD[0].SADDR = (uint32_t) &bufornadawczy[0];
DMA0->TCD[0].DADDR = (uint32_t) &buforodbiorczy[0];

DMA0->TCD[0].SOFF = 1;
DMA0->TCD[0].DOFF = 1;

DMA0->TCD[0].ATTR = DMA_ATTR_SSIZE(0) | DMA_ATTR_DSIZE(0);

DMA0->TCD[0].NBYTES_MLNO = 1;

DMA0->TCD[0].CITER_ELINKNO = DMA_CITER_ELINKNO_CITER(3);
DMA0->TCD[0].BITER_ELINKNO = DMA_BITER_ELINKNO_BITER(3);

DMA0->TCD[0].SLAST = -3;
DMA0->TCD[0].DLAST_SGA = -3;


DMA0->TCD[0].CSR |= DMA_CSR_DREQ_MASK;

}


int main(void) {


BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitDebugConsole();

SIM->SCGC5 = (SIM_SCGC5_PORTC_MASK|SIM_SCGC5_PORTE_MASK);
SIM->SCGC6 = (SIM_SCGC6_DMAMUX_MASK|SIM_SCGC6_SPI0_MASK);
SIM->SCGC7 = SIM_SCGC7_DMA_MASK;


//led
PORTE-> PCR[7] = PORT_PCR_MUX(0x01);
GPIOE -> PDDR |= GPIO_PDDR_PDD(1<<7);
GPIOE -> PSOR |= GPIO_PSOR_PTSO(1<<7);

 

PORTC -> PCR[14] |= (PORT_PCR_MUX(0x01)|PORT_PCR_IRQC(2)|PORT_PCR_PE_MASK|PORT_PCR_PS_MASK);//INT2_A, DMA Request, ISR flag

dma_init();

__NVIC_EnableIRQ(61);


while(1)
{



}
return 0 ;
}

Outcomes