LPSPI Delay calculation error (fsl_lpspi.c - v2.7.0)

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

LPSPI Delay calculation error (fsl_lpspi.c - v2.7.0)

Jump to solution
1,002 Views
graham_taylor-j
Contributor II

LPSPI Delay calculation error

Issue with fsl_lpspi.c Driver Version 2.7.0

I upgraded from SDK 2.6.1 to 2.7 for imxRT 1062.

My LPSPI was working correctly before the driver update. After the update, the timings were changed. Looking through the changes I see:

@@ -568,7 +577,7 @@ uint32_t LPSPI_MasterSetDelayTimes(LPSPI_Type *base,
lpspi_delay_type_t whichDelay,
uint32_t srcClock_Hz)
{
- uint64_t realDelay, bestDelay;
+ uint32_t realDelay, bestDelay;

The demotion from uint64_t to uint32_t.

This is used in 2 places:

....

bestDelay = 1000000000U;
bestDelay *= 257U; /* based on DBT+2, or 255 + 2 */
bestDelay /= clockDividedPrescaler;

....

bestDelay = 1000000000U;
bestDelay *= 256U; /* based on SCKPCS+1 or PCSSCK+1, or 255 + 1 */
bestDelay /= clockDividedPrescaler;

....

The calculation of 1,000,000,000 * 257 (257G) will overflow a 32 bit number (4.2G) and so is not valid.

If I re-promote to uint64_t the calculation works fine.

Am I correct in my analysis please? Is there a new driver fix/update yet?

Thanks,

Graham.

Labels (1)
0 Kudos
1 Solution
923 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Graham Taylor-Jones,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) Am I correct in my analysis please? Is there a new driver fix/update yet?
-- Yes, you're right, I'll report it in the next round of SDK field trial.

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
923 Views
graham_taylor-j
Contributor II

Thanks jeremyzhou

To anyone reading this later, as a workaround for this:

  • I set the three types of delay in spi config structure to 0 (or below the minimum/initial delay value in function) and I adjusted my baud rate setting to compensate to get the right waveform.

Or

  • Change the offending uint32_t back to uint64_t in function.
924 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Graham Taylor-Jones,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) Am I correct in my analysis please? Is there a new driver fix/update yet?
-- Yes, you're right, I'll report it in the next round of SDK field trial.

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos