SPI hangs when updating a 12kb buffer.

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

SPI hangs when updating a 12kb buffer.

1,022 Views
pramodk_g_
Contributor III

Hi,

We are working on K70 with MQX 4.0.1 It is having 2 tasks and 1 task is updating the LCD via SPI with 12 Kb buffer. Every 1 sec it is updating in the polling method. It works few times but sometimes it hangs. We have a hardware interrupt running background while updating the LCD.  LCD update task is having stack 32000 and the other is having 5000 stack.

Is SPI polling the best method? Is it having any interrupt disabling inside MQX? Do we have to switch to interrupt method?

Thanks

Pramod

Tags (3)
0 Kudos
4 Replies

643 Views
razed11
Contributor V

Using DMA is the best option. Basically you set up a buffer, start the DMA, and you get an interrupt when it completes although the MQX driver hides some of these details.

Interrupt driven is better than polling as the interrupt code runs only when the SPI peripheral has received new data or has an empty buffer for new data to be shifted out. It just sucks to get an interrupt on every word.

Polling is the least desirable approach. In is incredibly inefficient but if you are just trying to get some basics working can be acceptable. I'd say the real problem with it is making sure you don't drop data and that means you need to give it high task priority and that means giving priority to some loop that is constantly asking if data is available.

But to address your question: Where is it hanging? When it hangs you should be able to halt the processor, choose the polling task from the MQX plug-in, and find the exact spot where that code is hanging. The plug-ins are very powerful.

Regarding your stacks. Again, use the plug-in to view the stack usage for each individual stack. It'll tell you right away if one has overflowed.

My opinion is to spend some time learning how to use DMA. Find the maximum SPI clock speed that both the processor and the LCD will accept and burst those frames over. And use a scope to verify things.

Best of luck,

Kenny

0 Kudos

643 Views
pramodk_g_
Contributor III

Hi,

Thanks for the reply. I found that when the task hangs its in the LW semaphore blocked and its always inside the queue enqueue, int disable section. Please check attachment for the debug window.

Our code is running at different clocks ie power modes, 2Mhz, 24 Mhz and 120 MHZ. This issue is always happening at 120 Mhz and we are handing CS pin as GPIO.

I also found a post A bug in the SPI bus driver (iMX6 BSP 4.0.0/4.1.0) which is mentioning SPI hang issue. Is this similar to which i am facing.

Please let me know what is the real cause of this hanging issue.

Thanks

Pramod

0 Kudos

643 Views
razed11
Contributor V

Hi Pramod,

Ironically, I am now seeing this issue myself--hangs waiting on a semaphore. This is on the K64. I have posted a detailed account.

Glad someone marked this as "Assumed Answered" (so obnoxious). Did you find a fix?

Thanks,

Kenny

0 Kudos

643 Views
RadekS
NXP Employee
NXP Employee

It is difficult to say what could be reason for that behavior.

Pooling method has strong impact on system performance, therefore I would like to recommend interrupt mode for SPI transfers, especially in case of such big piece of data.

MQX 4.0.1 contains SPI and SPI_legacy drivers. I would like to recommend use SPI driver in interrupt mode for Kinetis K70.


Have a great day,
RadekS

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

0 Kudos