Skip to content

Commit dd3cba5

Browse files
committed
Merge pull request #1622 from c1728p9/fix_kl05_uart_clock
Prevent KL05 from using an unstable clock
2 parents ff9d4e2 + 273b464 commit dd3cba5

File tree

1 file changed

+12
-0
lines changed
  • libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z

1 file changed

+12
-0
lines changed

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KLXX/TARGET_KL05Z/system_MKL05Z4.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK;
103103
-- SystemInit()
104104
---------------------------------------------------------------------------- */
105105

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

194206
/* ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)