Quantcast
Channel: Processors
Viewing all articles
Browse latest Browse all 123717

Forum Post: RE: SPI slave using EDMA3 (C6748 platform)

$
0
0

Some comments. Most relating to the parameterization of the SPI ports. I would guess that you are using SPI0 as most of the code is still hard-coded for SPI0.

1) StarterWare has a pinmux function for each bus. It's awkward but you should add a conditional call either SPI0CSPinMuxSetup() or SPI1SPinMuxSetup().

2) TRM says that SPIDAT1.CSNR must set to 0 for slave mode. The existing code in spi_init() will set it some non-zero value.

3) I don't see a call to PSCModuleControl() anywhere, I assume it's outside of spi.c.

4) EDMA channel requrest code in spi_edma_ch_req() is still hard-coded for SPI0. The event queue is also hard-coded to 0, Unsure the event queue number has to change.

5) The functions spi_edma_tx() and spi_edma_rx() have hard-coded references to SPI0 EDMA tcc and cc.

6) Functions spi_txedma_par_set() and spi_rxedma_par_set() have hard-coded references to SPI0 base address.

7) You should use separate dummy for tx and rx.

8) I am not sure if it is a good to start up another DMA from the interrupt handler. Definitely printing from an interrup handler is questionable. There could be timing issues made worse by the printing. I would suggest taking a step back and following the StarterWare example more closely and do most buffer handling outside the interrupt handler. I've had some problems with the DMA still transferring data when the interrupt occurs. I've worked around so far by handling data outside the ISR. I also moved the IRQ disable from ISR to mainline. That seemed to give the DMA time to finish up. The following changes will support a single receive transaction. I am not sure what happens if the master clocks and there is no DMA setup on the slave side to send. Just guesses. Never used SPI slave mode.

volatile unsigned int flagTx = 0;
volatile unsigned int flagRx = 0;

static void spi_edma_callback(unsigned int tccnum, unsigned int status)
{
  if(tccnum == EDMA3_CHA_SPI0_TX)
  {
    flagTx = 1;
  }
  else if(tccnum == EDMA3_CHA_SPI0_RX)
  {
    flagRx = 1;
  }
}

void spi_read(struct spi *spi, unsigned char *buf, unsigned int len)
{
  flagTx = 0;
  flagRx = 0;
  spi_edma_rx(buf, len);
  spi_edma_tx(NULL, len);
  spi_edma_start(spi);
  while((0 == flagTx) || (0 == flagRx));
  spi_edma_stop(spi);
}

void test_it(struct spi *spi)
{
  int i;
  unsigned char buf[8];
  spi_read(spi, buf, sizeof(buf));
  for(i=0; i<sizeof(buf);i++
    print("%x", buf[i]);
  print("\n", buf[i]);
}

static struct spi *spi_bus_init(void)
{
  struct spi *spi;

  spi = spi_setup(DEFAULT_SPI_BUS, DEFAULT_SPI_CS, DEFAULT_SPI_MODE, NULL);
  if (spi == NULL)
  {
    DL_ERR("Init spi failed!\n");
    return NULL;
  }

  spi_edma_init();
  spi_edma_ch_req();

  /* Registering Callback Function for Transmission. */
  cb_Fxn[EDMA3_CHA_SPI0_TX] = &spi_edma_callback;
  /* Registering Callback Function for Reception. */
  cb_Fxn[EDMA3_CHA_SPI0_RX] = &spi_edma_callback;

  return spi;
}


Viewing all articles
Browse latest Browse all 123717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>