Skip to content

Issue#4528 K82F: Move the UART clock inititialization to board specif… #4542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ void rtc_setup_oscillator(RTC_Type *base)
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}

// Set the UART clock source
void serial_clock_init(void)
{
CLOCK_SetLpuartClock(2U);
}

Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ void rtc_setup_oscillator(RTC_Type *base)
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}

// Set the UART clock source
void serial_clock_init(void)
{
CLOCK_SetLpuartClock(1U);
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@

#include "fsl_clock.h"

/* Array for LPUART module clocks */
#define LPUART_CLOCK_FREQS \
{ \
kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk \
}

/* Array for I2C module clocks */
#define I2C_CLOCK_FREQS \
{ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static uint32_t serial_irq_ids[FSL_FEATURE_SOC_LPUART_COUNT] = {0};
static uart_irq_handler irq_handler;
/* Array of UART peripheral base address. */
static LPUART_Type *const uart_addrs[] = LPUART_BASE_PTRS;
/* Array of LPUART bus clock frequencies */
static clock_name_t const uart_clocks[] = LPUART_CLOCK_FREQS;
/* LPUART bus clock frequency */
static uint32_t lpuart_src_freq;

int stdio_uart_inited = 0;
serial_t stdio_uart;
Expand All @@ -47,10 +47,11 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->index = pinmap_merge(uart_tx, uart_rx);
MBED_ASSERT((int)obj->index != NC);

/* Set the UART clock source */
serial_clock_init();

// since the LPuart initialization depends very much on the source clock and its
// frequency, we do a check here and retrieve the frequency accordingly
// The CLOCK_SetLpuartSrc() is already done during clock init.
uint32_t lpuart_src_freq;
switch (SIM->SOPT2 & SIM_SOPT2_LPUARTSRC_MASK) {
case SIM_SOPT2_LPUARTSRC(3U): {
lpuart_src_freq = CLOCK_GetInternalRefClkFreq();
Expand All @@ -65,9 +66,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
break;
}
default: {
/* Set the LPUART clock source */
CLOCK_SetLpuartClock(1U);
lpuart_src_freq = CLOCK_GetFreq(uart_clocks[obj->index]);
lpuart_src_freq = CLOCK_GetOsc0ErClkFreq();
break;
}
}
Expand Down Expand Up @@ -106,7 +105,7 @@ void serial_free(serial_t *obj)

void serial_baud(serial_t *obj, int baudrate)
{
LPUART_SetBaudRate(uart_addrs[obj->index], (uint32_t)baudrate, CLOCK_GetFreq(uart_clocks[obj->index]));
LPUART_SetBaudRate(uart_addrs[obj->index], (uint32_t)baudrate, lpuart_src_freq);
}

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