Bug in fsl_clock.c in SDK for LPC812

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

Bug in fsl_clock.c in SDK for LPC812

865 次查看
petrolivka
Contributor II

Hi!

  The frequency of USART is not correctly computed in file fsl_clock.c in SDK 2.9.0 for LPC812. 

  The current code is:

uint32_t CLOCK_GetUartClkFreq(void)
{
    uint32_t freq = CLOCK_GetMainClkFreq();
    uint32_t uartDiv = SYSCON->UARTCLKDIV & 0xffU;

    return uartDiv == 0U ? 0U :
    (uint32_t)((uint64_t)(freq << 8U) /
        (uartDiv * (256U + ((SYSCON->UARTFRGMULT) & SYSCON_UARTFRGMULT_MULT_MASK))));
}

The variable freq should be retyped to uint64_t before shift left. Better is:

return uartDiv == 0U ? 0U : (uint32_t)((((uint64_t)(freq)) << 8U) /....

It is easy to test it for MainClock 24 MHz, UARTCLKDIV =1 and UARTFRGMULT=0. The correct result should be 24 MHz, but the function returns bad result: 7222784 Hz. 

The 24 MHz is 0x16E3600 and after shift left is out of range of uint32_t. 

Petr

 

 

 

1 回复

850 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi petrolivka

We will fix this problem in release SDK2.11.0.

Thank you for bringing the problem to our attention.

 

Best Regards

Jun Zhang

0 项奖励
回复