Bug in SDK 2.5.0 for LPC804 (and maybe other micros) in fsl_usart.c

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Bug in SDK 2.5.0 for LPC804 (and maybe other micros) in fsl_usart.c

956件の閲覧回数
mike_katz
Contributor I

Version 2.0.0 of the fsl_usart driver from the LPC804 SDK has the following code snippet from the USART_SetBaudRate() function (this works):

            diff = baudrate_Bps < baudrate ? baudrate - baudrate_Bps : baudrate_Bps - baudrate;
            if (diff < best_diff)
            {
                best_diff = diff;
                best_osrval = osrval;
                best_brgval = brgval;
            }
        }

        /* value over range */
        if (best_brgval > 0xFFFF)
        {
            return kStatus_USART_BaudrateNotSupport;
        }

        base->OSR = best_osrval;
        base->BRG = best_brgval;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Version 2.0.1 of the fsl_usart driver has the following code:
            diff = baudrate_Bps < baudrate ? baudrate - baudrate_Bps : baudrate_Bps - baudrate;
            if (diff < best_diff)
            {
                best_diff = diff;
                best_osrval = osrval;
                best_brgval = brgval;
            }
        }

        /* value over range */
        if (best_brgval > 0xFFFF)
        {
            return kStatus_USART_BaudrateNotSupport;
        }

        /* If the baud rate caculated is not very precise, please select the FRG clock as
         * the USART's source clock, and set the FRG frequency to a more suitable value.
         */
        assert(diff < ((baudrate_Bps / 100) * 3));

        base->OSR = best_osrval;
        base->BRG = best_brgval;

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
The assert on line 17 is new and is incorrect.
The assert should be:   
assert( best_diff < ((baudrate_Bps / 100) * 3));
The purpose of the assert is to insure that a valid baud rate multiplier has been found.  The value that is used to determine this is stored in best_diff, diff is used as temporary calculation holder.
タグ(3)
0 件の賞賛
返信
1 返信

808件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Mike Katz,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
Yes, it should be replaced by the below code, I'll report it to SDK team for checking.

assert( best_diff < ((baudrate_Bps / 100) * 3));‍‍

Have a great day,
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 件の賞賛
返信