mirror of https://github.com/ARMmbed/mbed-os.git
KL82Z: Fix the clock selection for LPUART module
Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>pull/6579/head
parent
bb59226cd0
commit
957e1ce56e
|
@ -39,3 +39,9 @@ void NMI_Handler(void)
|
||||||
gpio_t gpio;
|
gpio_t gpio;
|
||||||
gpio_init_in(&gpio, PTA4);
|
gpio_init_in(&gpio, PTA4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the UART clock source
|
||||||
|
void serial_clock_init(void)
|
||||||
|
{
|
||||||
|
CLOCK_SetLpuartClock(2U);
|
||||||
|
}
|
||||||
|
|
|
@ -54,3 +54,9 @@ void rtc_setup_oscillator(RTC_Type *base)
|
||||||
RTC->CR |= RTC_CR_OSCE_MASK;
|
RTC->CR |= RTC_CR_OSCE_MASK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Set the UART clock source
|
||||||
|
void serial_clock_init(void)
|
||||||
|
{
|
||||||
|
CLOCK_SetLpuartClock(2U);
|
||||||
|
}
|
||||||
|
|
|
@ -33,12 +33,6 @@
|
||||||
|
|
||||||
#include "fsl_clock.h"
|
#include "fsl_clock.h"
|
||||||
|
|
||||||
/* Array for LPUART module clocks */
|
|
||||||
#define LPUART_CLOCK_FREQS \
|
|
||||||
{ \
|
|
||||||
kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk, kCLOCK_Osc0ErClk \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Array for I2C module clocks */
|
/* Array for I2C module clocks */
|
||||||
#define I2C_CLOCK_FREQS \
|
#define I2C_CLOCK_FREQS \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -34,8 +34,8 @@ static uint32_t serial_irq_ids[FSL_FEATURE_SOC_LPUART_COUNT] = {0};
|
||||||
static uart_irq_handler irq_handler;
|
static uart_irq_handler irq_handler;
|
||||||
/* Array of UART peripheral base address. */
|
/* Array of UART peripheral base address. */
|
||||||
static LPUART_Type *const uart_addrs[] = LPUART_BASE_PTRS;
|
static LPUART_Type *const uart_addrs[] = LPUART_BASE_PTRS;
|
||||||
/* Array of LPUART bus clock frequencies */
|
/* LPUART bus clock frequency */
|
||||||
static clock_name_t const uart_clocks[] = LPUART_CLOCK_FREQS;
|
static uint32_t lpuart_src_freq;
|
||||||
|
|
||||||
int stdio_uart_inited = 0;
|
int stdio_uart_inited = 0;
|
||||||
serial_t stdio_uart;
|
serial_t stdio_uart;
|
||||||
|
@ -47,10 +47,11 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
obj->index = pinmap_merge(uart_tx, uart_rx);
|
obj->index = pinmap_merge(uart_tx, uart_rx);
|
||||||
MBED_ASSERT((int)obj->index != NC);
|
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
|
// since the LPuart initialization depends very much on the source clock and its
|
||||||
// frequency, we do a check here and retrieve the frequency accordingly
|
// 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) {
|
switch (SIM->SOPT2 & SIM_SOPT2_LPUARTSRC_MASK) {
|
||||||
case SIM_SOPT2_LPUARTSRC(3U): {
|
case SIM_SOPT2_LPUARTSRC(3U): {
|
||||||
lpuart_src_freq = CLOCK_GetInternalRefClkFreq();
|
lpuart_src_freq = CLOCK_GetInternalRefClkFreq();
|
||||||
|
@ -65,9 +66,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
/* Set the LPUART clock source */
|
/* Set the LPUART clock source */
|
||||||
CLOCK_SetLpuartClock(1U);
|
CLOCK_SetLpuartClock(2U);
|
||||||
lpuart_src_freq = CLOCK_GetFreq(uart_clocks[obj->index]);
|
lpuart_src_freq = CLOCK_GetOsc0ErClkFreq();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +107,7 @@ void serial_free(serial_t *obj)
|
||||||
|
|
||||||
void serial_baud(serial_t *obj, int baudrate)
|
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)
|
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
|
||||||
|
|
Loading…
Reference in New Issue