Bug in LPSPI_MasterTransferBlocking() if bytesPerFrame < 4

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

Bug in LPSPI_MasterTransferBlocking() if bytesPerFrame < 4

Contributor II

There seems to be an issue in LPSPI_MasterTransferBlocking() (as found in fsl_lpspi.c / SDK 2.7, MKE14F512VLL16). A related issue existed in SDK v2.6. (see Bug in LPSPI_MasterTransferBlocking()?). A fix was put in for SDK release 2.7 to address it, but I believe there is still a problem if bytesPerFrame is less than 4.

What I have observed is that if this function is preempted/interrupted for a substantial length of time at the wrong time, an overrun can still occur in the Rx FIFO which causes the function to get stuck in an endless loop and never return. I believe the problem is that the rxFifoMaxBytes value is initialize improperly for bytesPerFrame values less than 4.

This value is currently set in SDK 2.7 as follows:

uint32_t rxFifoMaxBytes = 4U * fifoSize;

I believe it should instead take bytesPerFrame into consideration. Something like:

uint32_t rxFifoMaxBytes = ((bytesPerFrame <= 4U) ? bytesPerFrame : 4U) * fifoSize;

In my case, I was using a bits per frame setting of 8 (so my bytesPerFrame is 1), and observed the same lockup as before. After putting in the proposed fix, the lockup no longer occurs.

Labels (1)
1 Reply

NXP TechSupport
NXP TechSupport

Hi Kevin:

Thanks for sharing your feedback.

There is a bug fix for this issue in SDK 2.8.0_EVKB-IMXRT1050, which will be released later this month.