SPI deadlock on SKEAZ1284

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI deadlock on SKEAZ1284

2,118 Views
0815
Contributor II

Actually I have an strange deadlock in the SPI driver for my custom SKEAZ1284 board:

I'm using the Processor Expert SPIMaster_LDD component, the same unchanged configuration was working flawlessly for weeks before. Also, before it deadlocks the code is working for a few calls.

Here is the interesting part of my communication driver, nothing special but SPI is used in polling mode:

while(ERR_BUSY == SM_SPI_ReceiveBlock(SM_SPI_DeviceData, receive, 2));
while(ERR_BUSY == SM_SPI_SendBlock(SM_SPI_DeviceData, transmit, 2));
while (!SM_SPI_GetBlockReceivedStatus(SM_SPI_DeviceData))
{
     SM_SPI_Main(SM_SPI_DeviceData);
}

If the problem occurs, it is deadlocked in the last while loop. At this point, the content of the SPI registers is as follows:

register2.PNG

At the same time the device data structure of the SPI component is this:

devicedata.PNG

So for me it seems, everything is transferred the right way (also confirmed by logic analyzer) but afterwards something happens?

I'm grateful for any help...

Labels (1)
Tags (1)
0 Kudos
11 Replies

1,716 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0815,

   Please upload your test project, I need to check your code.

   Besides, tell me what the IDE you are using.

Waiting for your reply!

Jingjing

0 Kudos

1,716 Views
0815
Contributor II

Hi,

thanks for your reply. I'm using S32 Design Studio for this project.

But I can't upload the whole project to a public forum, could I send it directly to you (maybe via email)?

Thanks in advance!

0 Kudos

1,716 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0815,

    Our email won't give out directly, If you are not convenient, you don't need to upload it.

    Actually, I am not suggest you use so many while in your code, the while may caused the deadlock easily.

 
About the SPIMaster_LDD code, we have a codewarrior sample code for
KL25, you can refer to it, you can refer to this code write your KEA
code, this use the SPI interrupt code, it will not easily

enter in the deadlock.

 
Attached is the spi_demo code for KL25, but it is nearly the same as
the KEA128, please refer to the PE configuration and the code in the
main function.

  Project path:klxx-SPI_PE\projects\spi_demo

Wish it helps you!

If you still have question, please contact with me!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,716 Views
0815
Contributor II

OK - I changed my code so that it is interrupt driven. But I'm still running into a deadlock where it waits for the flag which will be set normally within the interrupt function (Events.c - SM_SPI_OnBlockReceived):

SpiReceived = FALSE;

SM_SPI_ReceiveBlock(SM_SPI_DeviceData, receive, 2);

SM_SPI_SendBlock(SM_SPI_DeviceData, transmit, 2);

while(!SpiReceived);

void SM_SPI_OnBlockReceived(LDD_TUserData *UserDataPtr)

{

  /* Write your code here ... */

  SpiReceived = TRUE;

}

I'm not much surprised, as there is basically the same code of the SPI component behind this.

Also as with the polling code, the deadlock occurs after the code worked flawless a few times before.

Any other ideas?

0 Kudos

1,715 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0815,

    it seems, you didn't receive the SPI data from the slave, did you check the SPI communication wave?

   If you have the SPI communication wave, please post some wave when the SPI code is blocking, I need to check it.

   Besides, what the baud rate you are using now? Try cut down the baud rate and try again.

Best Regards,

Jingjing

0 Kudos

1,715 Views
0815
Contributor II

I made a little mistake - it seems the version with interrupts enabled is working now. :smileywink:

However I tried to use lower bitrates with the polling variant. I found if I change the clock from 1MHz to 0.5MHz it is working too.

But this is no solution for me, at least if I don't know the reason behind.

As you asked, here is a plot of the communication:

pastedImage_0.png

You can see the deadlock on the right side where the CS signal will not be released because of this (CS is controlled by software).

0 Kudos

1,716 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0815,

   Thank you for your information.

    If your baud rate is higher, I suggest you use the interrupt methods to process the SPI communication.

    Because as you know, the PE code is really complicate, not simple, the execute time is long, if you still use the polling in the main while, it may easily enter in the dead blocking with higher communication baud rate. Now there two ways:

1. use interrupt method

2. don't choose PE code, just use the bare bone code with register control, it will shorten the code process time in polling mode.

This post is for your reference:

External flash control via kinetis M series SPI module

Wish it helps you!

If you still have question, please contact with me!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,716 Views
0815
Contributor II

OK, for now I will use the interrupt variant.

However, I have seen the PE code as kind of reference implementation. If there are unaddressed issues then some kind of an uncomfortable feeling remains...

I would really prefer to know the technical reason behind such 'behavior'.

Thanks for your effort!

0 Kudos

1,716 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0805,

    I don't what the bus frequent you are using?

   I am try to use the 24Mhz Bus clock, and configure the SPIMaster_LDD, use the same polling code which you are using, I am not blocking in the 1Mhz, and the CS can be higher.

  Following is my test wave, I didn't connect the slaver, because you said your master have problem:

90.jpg

Attached is my test project, you can use it can check whether it blocks on your side, I test it on our TRK-KEA128 board.

Wish it helps you!

If you still have question, please contact with me!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,716 Views
0815
Contributor II

Thanks for creating a test project. However I didn't use it directly as you used a few different settings (also 20MHz bus clock at my site).

So I created my own demo project with my original settings. Unfortunately I couldn't reproduce the issue with such simple project. I suppose there are other dependencies or conditions I don't see actually...

0 Kudos

1,716 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi 0815,

   If the simple project can't reproduce the issue, your problem should relate to other codes.

   I suggest you add part of your code and test again, then it may helps you to find the root problem!

   If you find any relative codes, please let me know!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos