Evgeny Erenburg

SPI and DMA

Discussion created by Evgeny Erenburg on Jun 2, 2018
Latest reply on Jun 11, 2018 by Evgeny Erenburg

I need to transfer a big block of data (4096 bytes) on SPI using DMA.

I found an example. The example is for K20 and I use K10 but I think the DMA registers are the same.

I have several questions

 

void vfnInitDMA_SPITxMstr(void)
{
  SIM->SCGC6 |= SIM_SCGC6_DMAMUX_MASK;
  SIM->SCGC7 |= SIM_SCGC7_DMA_MASK;
  /**********************************************************************************************************************************/
  /**********************************************************************************************************************************/
  /* Look for the DMA request sources table on your RM for a complete list of available sources */
  DMAMUX->CHCFG[0] |= DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(17); //SPI0 TX
   /*start the sequence*/
  //DMA_ERQ |= DMA_ERQ_ERQ0_MASK;
  /* This example has no table of data to                                                */
    /* transfer, making only a single minor loop necessary to complete a major loop        */
  DMA0->TCD[0].SADDR =  (uint32_t)&MstrDataSend_Buff;    //Source address
  /* Destination address */
  DMA0->TCD[0].DADDR = (unsigned long)(&SPI0->PUSHR); //
    /* Source offset disabled */
  DMA0->TCD[0].SOFF = 0x04;
    /* Source and Destination Modulo off, source and destination size 2 = 32 bits */
  DMA0->TCD[0].ATTR = DMA_ATTR_SSIZE(2) | DMA_ATTR_DSIZE(2);
    /* Transfer 4 bytes per transaction */
  DMA0->TCD[0].NBYTES_MLNO = 0x04;
    /* No adjust needed */
  DMA0->TCD[0].SLAST = -32;
    /* Destination offset disabled */
  DMA0->TCD[0].DOFF = 0x00;
    /* No link channel to channel, 1 transaction */
  DMA0->TCD[0].CITER_ELINKNO = DMA_CITER_ELINKNO_CITER(8);
    /* No adjustment to    destination address */
  DMA0->TCD[0].DLAST_SGA = 0;
    
  DMA0->TCD[0].BITER_ELINKNO = DMA_BITER_ELINKNO_BITER(8);

 

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

 

I didn't find the DMA request sources table - what source corresponds to what module.
The destination data transfer size - is it total size to transfer? how do I set total size to transfer?
In the example no CS pin handling. Hwo operates the CS pin?

Outcomes