Mike Katz

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

Discussion created by Mike Katz on Jun 6, 2019
Latest reply on Jun 9, 2019 by jeremyzhou

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.

Outcomes