This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI transmit issue (AM3352 TI SDK 7.0)

Other Parts Discussed in Thread: AM3352

Hello Everyone,

I am using an AM3352 with TI SDK 7.0 (Linux 3.12 Kernel) and have written a driver for our hardware that uses SPI bus. I have successfully tested the driver and also interfaced with a user space application. The AM3352 is the host and our hardware is the slave and the SPI frequency is 1Mhz.

I am facing some problems when I read data greater than 256 bytes from my device. I am using a protocol analyzer on the SPI bus and clearly see that instead of reading 256 bytes or 512 bytes in a single transaction it will occasionally read 202 or 458 bytes, exactly 54 bytes less than what is specified as the length.  All other transactions involving smaller length of data works properly every single time. The buffers I'm using are not malloced and are allocated statically.The function I'm using is below. I pass in the pointer to the buffer and the length of data to be read.

static int mydriver_spi_read(struct mydriver_data *pdata, u8 *buf, u32 length)
{
	struct spi_transfer xfer = {		
		.rx_buf		= buf,
		.len		= length,
	};
	struct spi_message msg;
	int error;

	spi_message_init(&msg);
	spi_message_add_tail(&xfer, &msg);

	error = spi_sync(pdata->spi, &msg);	
	if (error) {
		dev_err(&pdata->spi->dev, "%s - failed, error: %d\n", __func__, error);
		return error;
	}

	return 0;
}

This only happens on some occasion and on others all 512 data is read correctly. I've even tried printing the length variable and each time it is 512. Can someone please let me know if there is something wrong in the code or the setup? 

Thank you for your help.

Regards

Santhosh

  • Hi Santhosh,

    Would you read the:
    e2e.ti.com/.../321533
    This is related for sdk6, but the drivers are very similar.

    BR
    Ivan
  • Hello Ivan,

    Thank you for sharing the link, yes it did help. If I change my buffer size to 128 (less than 160) I get it to work consistently. However, the patch presented in the document is for SDK 6 and it seems there have been some significant changes to the spi-omap2-mcspi.c file in SDK 7.0.

    I did try to include a dummy TX register, but that caused more failures when data size was switched above 160. I will try to understand the changes and see how I can incorporate them but it clearly seems to be a problem with the DMA based transfers.


    Can you please let me know if there are any other sources that I can refer to better understand the problem and find a solution? I see that you are with TI - are you guys aware of this problem and do you have any suggested fixes/patches for SDK 7.0?

    Thank you for your patience and your replies.

    Regards

    Santhosh

  • Hello Ivan,

    I reviewed the patch in detail and also the e2e link and all the explanation provided - I'm not able to see a similarity between the problem they are facing and my situation. They problem mentioned in the link is a problem receiving the last byte of data - in my case the count is around 54 bytes. Can you please indicate how to co-relate the two conditions?

    I can confirm that setting the buffer size to 128 (using PIO) the communication is clean and consistent. Also I don't know why this problem is not seen every single time - rather happens once every 2-3 attempts.

    Any help is much appreciated.

    Thank you
    Regards

    Santhosh
  • Hi Santhosh,

    Wanting to help, I guess that this problem is related to DMA, since such problems has been until now on a other customers. For this reason, I looked for in previous posts and send you some links to see if something is not close to your problem.
    e2e.ti.com/.../1141326
    e2e.ti.com/.../334717
    e2e.ti.com/.../321533
    I also think it's good to look at StarterWare where are ready examples and see at them if somewhere you can take advice.

    BR
    Ivan
  • Ivan,

    Your feedback below means that I can't use the DMA for SPI transactions.  Is there an effort at TI to resolve this issue with the DMA in the next SDK release?  It seems to be well noticed on the forum.

    Thank you,

    Jason 

  • Hi Hi Santhosh/Jason,

    The new SDK SPI interface has changed and I hope some of the current issue are cleared. But I want to try it and to be sure that everything works. For that purpose would you write me in details what you do to get a closest configuration to yours and how can I test my SK or EVM if it works. Of course you first need to adapt new sdk8 for your boards.

    BR
    Ivan
  • Hello Ivan,

    Sorry for the delay in replying back to you, thank you so much for your help. The main problem I faced was that when I increased the size of SPI transaction to anything greater than 160 - the driver automatically switches to DMA mode. In this mode, the receive action is inconsistent where instead of receving x bytes, it only receives y bytes (x > y).

    It also works sometimes and doesn't work on other occasions it works fine. The problem is mainly with DMA mode of SPI transfers for receive/read. I have not tested Transmit for more than 160 chars but I'm thinking it could also have the same problem.

    When I limit the transaction size to 128, the communication works every single time. Hope this explanation helps, please do let me know if you need more information I will reply quicker I promise :)

    Thank you

    Regards

    Santhosh

  • Hi Santhosh,

    Yes, I know that this is a old issue, but could you try with sdk8 to see if this problem is resolved or not.

    BR
    Ivan
  • Hello Ivan,

    I used the SPI driver from SDK8 and the problem was resolved. Sorry for the really late reply.

    Thank you
    Regards

    Santhosh