Skip to content

Commit 265c046

Browse files
thinkbergtheotherjimmy
authored andcommitted
patch latest clock settings for ubirch#1
fix lpuart clock source settings, retrieve clock frequency accordingly
1 parent 0e504da commit 265c046

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/peripheral_clock_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/* Array for LPUART module clocks */
3737
#define LPUART_CLOCK_FREQS \
3838
{ \
39-
kCLOCK_PllFllSelClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk \
39+
kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk \
4040
}
4141

4242
/* Array for I2C module clocks */

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/serial_api.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,38 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
4747
obj->index = pinmap_merge(uart_tx, uart_rx);
4848
MBED_ASSERT((int)obj->index != NC);
4949

50-
/* Set the LPUART clock source */
51-
CLOCK_SetLpuartClock(1U);
50+
// since the LPuart initialization depends very much on the source clock and its
51+
// frequency, we do a check here and retrieve the frequency accordingly
52+
// The CLOCK_SetLpuartSrc() is already done during clock init.
53+
uint32_t lpuart_src_freq;
54+
switch (SIM->SOPT2 & SIM_SOPT2_LPUARTSRC_MASK) {
55+
case SIM_SOPT2_LPUARTSRC(3U): {
56+
lpuart_src_freq = CLOCK_GetInternalRefClkFreq();
57+
break;
58+
}
59+
case SIM_SOPT2_LPUARTSRC(2U): {
60+
lpuart_src_freq = CLOCK_GetOsc0ErClkFreq();
61+
break;
62+
}
63+
case SIM_SOPT2_LPUARTSRC(1U): {
64+
lpuart_src_freq = CLOCK_GetPllFllSelClkFreq();
65+
break;
66+
}
67+
default: {
68+
/* Set the LPUART clock source */
69+
CLOCK_SetLpuartClock(1U);
70+
lpuart_src_freq = CLOCK_GetFreq(uart_clocks[obj->index]);
71+
break;
72+
}
73+
}
5274

5375
lpuart_config_t config;
5476
LPUART_GetDefaultConfig(&config);
5577
config.baudRate_Bps = 9600;
5678
config.enableTx = false;
5779
config.enableRx = false;
5880

59-
LPUART_Init(uart_addrs[obj->index], &config, CLOCK_GetFreq(uart_clocks[obj->index]));
81+
LPUART_Init(uart_addrs[obj->index], &config, lpuart_src_freq);
6082

6183
pinmap_pinout(tx, PinMap_UART_TX);
6284
pinmap_pinout(rx, PinMap_UART_RX);

0 commit comments

Comments
 (0)