Prevent KL05 from using an unstable clock

Add a delay after switching to the FEE clock mode so the FLL has a
chance to acquire a better lock.  This fixes a bug where the first byte
sent over the UART is corrupt.
pull/1622/head
Russ Butler 2016-03-20 19:40:13 -05:00
parent 1f340445d5
commit 273b464fe0
1 changed files with 12 additions and 0 deletions

View File

@ -103,6 +103,11 @@ uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK;
-- SystemInit()
---------------------------------------------------------------------------- */
static void busy_delay(uint32_t delay) {
volatile uint32_t i = delay;
while (i--);
}
void SystemInit (void) {
#if (DISABLE_WDOG)
/* Disable the WDOG module */
@ -189,6 +194,13 @@ void SystemInit (void) {
while((MCG->S & MCG_S_IRCST_MASK) == 0x00U) { /* Check that the fast external reference clock is selected. */
}
#endif /* (CLOCK_SETUP == 2) */
// Give the FLL time to stabilize
// This can take up to 1ms according to the KL05 datasheet
// Note: Without this delay the UART's baud can be wrong for the
// first byte sent in some cases. A delay of 1000 fixes this
// problem even under optimizations. The delay of 10,000 is used
// to add a saftey margin.
busy_delay(10000);
}
/* ----------------------------------------------------------------------------