Change System/Core Frequency - KL43

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change System/Core Frequency - KL43

819 Views
srcoolz
Contributor II

Hello,

 

I'm trying to update the system frequency for the hello world program running on the FRDM board. I updated the core frequency value to 24 MHz and changed the CLKDIV1 value to divide IRC48M by 2. I also configured the SysTick to provide an interrupt once every 0.5 seconds and use the Red and Green LED toggle to verify the frequency for SysTick.

 

However, the UART debug console is now working with a wrong baud rate. (The prints are gibberish and the echo feature is also gibberish). I have gone through the Debug code and can't find any reference to system clock other than specific function calls that read the value (ie there is no hard coded value that I could find).

 

Can someone please let me know what I'm missing? Here is the code that I modified in clock_config.c

 

/* Configuration for enter RUN mode. Core clock = 24000000Hz. */
const clock_config_t g_defaultClockConfigRun = {
.mcgliteConfig =
{
.outSrc = kMCGLITE_ClkSrcHirc,
.irclkEnableMode = 0U,
.ircs = kMCGLITE_Lirc8M,
.fcrdiv = kMCGLITE_LircDivBy1,
.lircDiv2 = kMCGLITE_LircDivBy1,
.hircEnableInNotHircMode = true,
},
.simConfig =
{
.clkdiv1 = 0x10010000U, /* SIM_CLKDIV1. */
},
.oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
.capLoad = 0U,
.workMode = kOSC_ModeOscLowPower,
.oscerConfig =
{
.enableMode = kOSC_ErClkEnable,
#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
.erclkDiv = 0U,
#endif
}},
.coreClock = 24000000U, /* Core clock frequency */
};

 

Thank you for your help. michaelsteffenfae Camron Chilton

Regards

 

Santhosh

Labels (1)
0 Kudos
Reply
3 Replies

663 Views
srcoolz
Contributor II

Just adding another data point:

If I change debug initialization code in board.c with baudrate 57600 (half of 115200) then it works fine. I can leave the terminal program on my PC at baud rate 115200 and the messages are fine.

DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, 57600/*BOARD_DEBUG_UART_BAUDRATE*/, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);

This kind of indicates that the clock being used by the LPUART is still at 48Mhz (IRC48M) but the baud rate calculator uses system/core clock which is 24Mhz. It would also make sense based on the clock source for the LPUART as defined in the SIM registers. 

Can someone please confirm? Is this a software bug in the freedom board code?

Thank you

Regards

Santhosh

0 Kudos
Reply

663 Views
isaacavila
NXP Employee
NXP Employee

Hello Santhosh,

Problem here is that LPUART's clock is taking a wrong value in debug initialization function.

If you look at BOARD_InitDebugConsole function will notice that uartClkSrcFreq is taken from BOARD_DEBUG_UART_CLK_FREQ and this macro is using the CLOCK_GetCoreSysClkFreq. Like LPUART0 is taken its reference from HIRC (48MHz) and Core clock is 48 MHz / 2, you are initializing LPUART module as if it was taken 24MHz.

You will need to modify this code as follows:

#if DEFAULT
    uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
#else
    /* Take HIRC reference (48MHz) */
    uartClkSrcFreq = CLOCK_GetFreq(kCLOCK_McgIrc48MClk);
#endif‍‍‍‍‍‍

(DEFAULT macro was set to 0)

In this case, uartClkSrcFreq will get 48000000 value (48MHz) and LPUART's baud rate will be calculated correctly.

I hope this can help you!

Isaac

0 Kudos
Reply

663 Views
srcoolz
Contributor II

Hello Isaac,

Yes I actually changed the code to the following and here is the snippet. It works fine now.

code_change.jpg

Thanks for your help.

Regards

Santhosh