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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,457 次查看
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.

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
2,378 次查看
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 项奖励
回复
2 回复数
2,378 次查看
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.
2,379 次查看
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 项奖励
回复