AnsweredAssumed Answered

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

Question asked by Graham Taylor-Jones on Feb 3, 2020
Latest reply on Feb 7, 2020 by Graham Taylor-Jones

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.

Outcomes