Skip to content

Commit ef00edf

Browse files
committed
Issue#4528 K82F: Move the UART clock inititialization to board specific file
Signed-off-by: Mahadevan Mahesh <[email protected]>
1 parent 35999be commit ef00edf

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/mbed_overrides.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ void rtc_setup_oscillator(RTC_Type *base)
3737
/* Enable the RTC oscillator */
3838
RTC->CR |= RTC_CR_OSCE_MASK;
3939
}
40+
41+
// Set the UART clock source
42+
void serial_clock_init(void)
43+
{
44+
CLOCK_SetLpuartClock(2U);
45+
}
46+

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_UBRIDGE/mbed_overrides.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ void rtc_setup_oscillator(RTC_Type *base)
5353
/* Enable the RTC oscillator */
5454
RTC->CR |= RTC_CR_OSCE_MASK;
5555
}
56+
57+
// Set the UART clock source
58+
void serial_clock_init(void)
59+
{
60+
CLOCK_SetLpuartClock(1U);
61+
}
62+

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/peripheral_clock_defines.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333

3434
#include "fsl_clock.h"
3535

36-
/* Array for LPUART module clocks */
37-
#define LPUART_CLOCK_FREQS \
38-
{ \
39-
kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk \
40-
}
41-
4236
/* Array for I2C module clocks */
4337
#define I2C_CLOCK_FREQS \
4438
{ \

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/serial_api.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static uint32_t serial_irq_ids[FSL_FEATURE_SOC_LPUART_COUNT] = {0};
3434
static uart_irq_handler irq_handler;
3535
/* Array of UART peripheral base address. */
3636
static LPUART_Type *const uart_addrs[] = LPUART_BASE_PTRS;
37-
/* Array of LPUART bus clock frequencies */
38-
static clock_name_t const uart_clocks[] = LPUART_CLOCK_FREQS;
37+
/* LPUART bus clock frequency */
38+
static uint32_t lpuart_src_freq;
3939

4040
int stdio_uart_inited = 0;
4141
serial_t stdio_uart;
@@ -47,10 +47,11 @@ 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 UART clock source */
51+
serial_clock_init();
52+
5053
// since the LPuart initialization depends very much on the source clock and its
5154
// 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;
5455
switch (SIM->SOPT2 & SIM_SOPT2_LPUARTSRC_MASK) {
5556
case SIM_SOPT2_LPUARTSRC(3U): {
5657
lpuart_src_freq = CLOCK_GetInternalRefClkFreq();
@@ -65,9 +66,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
6566
break;
6667
}
6768
default: {
68-
/* Set the LPUART clock source */
69-
CLOCK_SetLpuartClock(1U);
70-
lpuart_src_freq = CLOCK_GetFreq(uart_clocks[obj->index]);
69+
lpuart_src_freq = CLOCK_GetOsc0ErClkFreq();
7170
break;
7271
}
7372
}
@@ -106,7 +105,7 @@ void serial_free(serial_t *obj)
106105

107106
void serial_baud(serial_t *obj, int baudrate)
108107
{
109-
LPUART_SetBaudRate(uart_addrs[obj->index], (uint32_t)baudrate, CLOCK_GetFreq(uart_clocks[obj->index]));
108+
LPUART_SetBaudRate(uart_addrs[obj->index], (uint32_t)baudrate, lpuart_src_freq);
110109
}
111110

112111
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)

0 commit comments

Comments
 (0)