AnsweredAssumed Answered

imx6qp ECSPI slave mode TX data missing

Question asked by sijil cv on Apr 25, 2016
Latest reply on May 4, 2016 by sijil cv

We have developed a custom ECSPI slave driver for iMX6 and tested it on saber AI development board with imx6qp processor (MCIMX6QPAICPU3.)

The ECSPI_1 lines of the development board is connected to another microcontroller for testing.

 

Following are our observations.

The Reception (MOSI) on imx6 side was working perfectly. but on the transmission side (MISO) we observed that some bytes are missing in TX data.

 

Could you please help us to resolve this issue.

 

Another strange thing is that the same code works perfectly in a imx6 saber lite evaluation board, both Tx and Rx data is perfect.

 

 

 

 

#define SPI_LENGTH 64

struct spi_transfer

{

  uint8_t rx[SPI_LENGTH];

  uint8_t tx[SPI_LENGTH];

};

 

typedef struct __spi_dev{

   struct spi_transfer spi_xfer;

   int irq;

   void __iomem *base; 

   struct clk *clk_per;                                                      

   struct clk *clk_ipg;

   unsigned long spi_clk;                                                    

   unsigned int spi_bus_clk;

   struct completion xfer_done;

}spi_dev_t;

spi_dev_t * p_spi_dev = NULL;

 

Reg Configuration:

static int setup_spi_slave(spi_dev_t *spi_imx)

{

    writel(0x00000000, p_spi_dev->base + MX51_ECSPI_CTRL); /* Reset ecspi*/                  

   writel(0x00700001, p_spi_dev->base + MX51_ECSPI_CTRL); /* Burst length to 1 byte */                  

   writel(0x00000011, p_spi_dev->base + MX51_ECSPI_CONFIG); /* Set PHA and POL*/                

   writel(0x003f0000, p_spi_dev->base + MX51_ECSPI_DMA); /* Set threshold to 63 bytes */

   writel(0x00000010, p_spi_dev->base + MX51_ECSPI_INT); /* Set threshold interrupt */

    return 0;

}

 

ISR code

static irqreturn_t imx6_spi_slave_isr(int irq, void *dev_id)

{

    static unsigned int count = 0;

    while (rx_available(p_spi_dev))

    {                    

      p_spi_dev->spi_xfer.rx[count] = (uint8_t)readl(p_spi_dev->base + MXC_CSPIRXDATA);

      writel(p_spi_dev->spi_xfer.tx[count],p_spi_dev->base + MXC_CSPITXDATA);

      count++;

    }

    count = 0;

    /*Clear TX buff*/

    memset(&p_spi_dev->spi_xfer.tx,0,SPI_LENGTH);

    complete(&p_spi_dev->xfer_done);

 

 

return IRQ_HANDLED;

}

 

The buffer is filled with following data.

static void fill_tx_buff(void)                                               

{                                                                            

   snprintf(p_spi_dev->spi_xfer.tx,64,"%s","This code is to test ECSPI communication between two micro   \r\n");

}

 

The output is as follows.

[0] 'T'

[1] 'h'

[2] 'i'

[3] 's'

[4] ' '

[5] 'o' /* c  is missing */

[6] 'd'

[7] 'e'

[8] ' '

[9] 'i'

[10] 's'

[11] ' '

[12] 't'

[13] ' ' /* o missing */

[14] 't'

[15] 's' /* e missing */

[16] 't'

[17] ' '

[18] 'E'

[19] 'C'

[20] 'S'

[21] 'P'

[22] 'I'

[23] ' '

[24] 'c'

[25] 'o'

[26] 'm'

[27] 'm'

[28] 'u'

[29] 'n'

[30] 'i'

[31] 'c'

[32] 'a'

[33] 't'

[34] 'i'

[35] 'o'

[36] 'n'

[37] ' '

[38] 'b'

[39] 't' /* e missing */

[40] 'w'

[41] 'e'

[42] 'e'

[43] 'n'

[44] ' '

[45] 't'

[46] 'w'

[47] 'o'

[48] ' '

[49] 'm'

[50] 'i'

[51] 'c'

[52] 'r'

[53] 'o'

[54] ' '

[55] ' '

[56] '\r

[57] '\n

[58] ' '

Outcomes