In trying to use the ROM Bootloader on the KL81 over USB, we're running into the chip failing to transition to PEE clock mode. This results in the post-bootloader initialization code sometimes becoming permanently stuck in an infinite loop. Performing a hardware reset of the chip restarts everything, sometimes causing the same issue to reproduce. The problem reproduces ~60% of the time.
For the 1st work-around, are other steps necessary to get it to work?
Regarding the other work-arounds:
We're using an external clock.
No modifications have been made to BOARD_BootClockRUN() or CLOCK_BootToPeeMode() functions nor to their related variables. For reference, the config code is provided below.
We could try using CLOCK_SetPeeMode(), but should point out that this would be making code changes to CLOCK_BootToPeeMode() that is in fsl_clock.c whose implementation comes from the FRDM-KL82Z SDK. The SDK version of CLOCK_BootToPeeMode() calls CLOCK_SetToPbeMode(). Would doing such an edit of an SDK file cause other unintended consequences for the clocks?
There is an update and a correction on this issue, so hopefully this does not cause any confusion. This issue is occurring with the KL82, not the KL81. Essentially, there are 2 pieces of hardware being used:
Our understanding is that the below code should be correct for the FRDM-KL82Z since it is from a sample app from its SDK. Also, we assume it is acceptable to use this for the custom board even though it uses an oscillator rather than a crystal.
Here is the implementation if BOARD_BootClockRUN(), up to the call to CLOCK_BootToPeeMode():
void BOARD_BootClockRUN(void)
{
CLOCK_SetSimSafeDivs();
CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_BOARD_BootClockRUN.frdiv);
CLOCK_BootToPeeMode(mcgConfig_BOARD_BootClockRUN.oscsel,
kMCG_PllClkSelPll0,
&mcgConfig_BOARD_BootClockRUN.pll0Config);
...
Here are the config structures for the clocks:
const mcg_config_t mcgConfig_BOARD_BootClockRUN =
{
.mcgMode = kMCG_ModePEE,/* PEE - PLL Engaged External */
.irclkEnableMode = kMCG_IrclkEnable,/* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
.ircs = kMCG_IrcSlow,/* Slow internal reference clock selected */
.fcrdiv = 0x0U, /* Fast IRC divider: divided by 1 */
.frdiv = 0x0U,/* FLL reference clock divider: divided by 32 */
.drs = kMCG_DrsLow, /* Low frequency range */
.dmx32 = kMCG_Dmx32Default,/* DCO has a default range of 25% */
.oscsel = kMCG_OscselOsc,/* Selects System Oscillator (OSCCLK) */
.pll0Config =
{
.enableMode = MCG_PLL_DISABLE,/* MCGPLLCLK disabled */
.prdiv = 0x0U,/* PLL Reference divider: divided by 1 */
.vdiv = 0x8U, /* VCO divider: multiplied by 24 */
},
};const osc_config_t oscConfig_BOARD_BootClockRUN =
{
.freq = 12000000U,/* Oscillator frequency: 12000000Hz */
.capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */
.workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
.oscerConfig =
{
.enableMode = kOSC_ErClkEnable,/* Enable external reference clock, disable external reference clock in STOP mode */
.erclkDiv = 0,/* Divider for OSCERCLK: divided by 1 */
}
};
Hello @SynapticLathe,
Relating the use of CLOCK_SetPeeMode(), please continue to use CLOCK_SetPbeMode() as it is necessary for CLOCK_BootToPeeMode() to work.
Also, could you please change the following values of the BCA?
What other differences do you have between the custom board and FDRM-KL82? In the FDRM-KL82 could you please try with another example that is not QSPI related? Could be a led_blinky example.
Finally, regarding your bootloader, could you please share us how are you exiting the bootloader and jumping to the application? Are you using MCU Boot?
Best regards, Raul.
Hello @SynapticLathe,
First of all, let us apologize for the late reponse.
Just for double check, could you please check if by using the other workarounds the stuck issue is solved?
You are mentioning that the program got stuck in MCG_S[IREFST], could you please tell us if you are using an external or an internal reference clock?
Also, have you done some modification to BOARD_BootClockRUN() or CLOCK_BootToPeeMode() functions or variables related to them? Which PLL output clock are you selecting and CLOCK_BootToPeeMode() configuration do you have?
Finally, you are mentioning that you want to use PEE mode, could you please use CLOCK_SetPeeMode() instead of CLOCK_SetPbeMode() and configure it as mentioned in KL81 Sub-Family Reference Manual. Chapter 29.5.1.1. MCG modes of operation?
[KL81 Sub-Family RM. Table 29-4. MCG modes of operation]
Best regards, Raul.