MCU getting stuck on CLOCK_BootToPeeMode.

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

MCU getting stuck on CLOCK_BootToPeeMode.

Jump to solution
1,740 Views
m4l490n
Contributor V

I'm struggling with my clock configuration. I configure it like in the following image:

m4l490n_0-1611008116782.png

 

But the execution is getting stuck in this while:

m4l490n_1-1611008316031.png

 

With the following call tree:

m4l490n_3-1611008455635.png

 

I found a similar post here but it is unanswered, and according to the answer offered by @kerryzhou, the HGO0 bit should be 1 but MCG_C2 is disabled in my configuration and I can't modify it.

I'm trying to configure an MK10DN512VLQ10 with an external 8MHz crystal.

0 Kudos
1 Solution
1,710 Views
m4l490n
Contributor V

Thanks for helping.

Your project still was getting stuck in the same place. After poking around I noticed that I had to semi-manually configure these two options:

m4l490n_0-1611179925795.png

 

I say semi-manually, because I didn't have to do that directly in the source code, but neither through the graphical configurator. To configure those two options I had to select the System oscillator block in the clocks diagram to get those options in the Details view on the right and manually select the correct options.

I had to select the OSC Mode as "Using oscillator with external crystal (low power)" and the Frequency Range as "Very_high frequency range 8-32 MHz".

There is another option for OSC Mode which is Using oscillator with external crystal (high gain) but that one doesn't work despite it is also for an external crystal.

For the Frequency Range, you can use Very_high frequency range 8-32 MHz or High frequency range 3-8 MHz, it is the same with those two, the values don't change in the generated code (which makes me wonder why those two options exist).

I attach the .mex config file in case anyone wants to take a look.

View solution in original post

9 Replies
1,734 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n,

  Thank you for your interest in the NXP kinetis product, I would like to provide service for you.

  You are using: MK10DN512VLQ10

   Please also check your chip maskset number: You can find it in your chip

image.png

Make sure it is 2.x chip.

https://www.nxp.com/docs/en/application-note/AN4445.pdf

BTW, do you check your board 8M crystal, whether that can oscillating or not?

HGO0 should can be modified in the MCG_C2, but please note, do you refer to the SDK code directly?

You can't use the PBE mode directly, it should transfer the mode from FEI.

image.png

You can refer to this code:

\SDK_2.2.0_MK10DN512xxx10\boards\twrk60d100m\driver_examples\mcg

it has some clock mode code for your refernece.

When you use the default PEE in the hello_world project can you make it works?

void BOARD_BootClockRUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Initializes OSC0 according to board configuration. */
CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
/* Configure FLL external reference divider (FRDIV). */
CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_BOARD_BootClockRUN.frdiv);
/* Set MCG to PEE mode. */
CLOCK_BootToPeeMode(mcgConfig_BOARD_BootClockRUN.oscsel,
kMCG_PllClkSelPll0,
&mcgConfig_BOARD_BootClockRUN.pll0Config);
/* Configure the Internal Reference clock (MCGIRCLK). */
CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,
mcgConfig_BOARD_BootClockRUN.ircs,
mcgConfig_BOARD_BootClockRUN.fcrdiv);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}

You need to change the osc to the 8Mhz.

 

Please check the above points at first.

Best Regards,

Kerry

 

 

 

 

 

 

0 Kudos
1,730 Views
m4l490n
Contributor V

@kerryzhou thanks for helping!

These are my comments:

  1. My chip says 5N22D. I don't know what version is that (5.X?) but I think I'm good here, am I?
  2. The 8MHz crystal and all the hardware for that matter are working perfectly fine. I'm trying to start a new project at work reusing this particular piece of hardware which currently runs another application just fine. The problem is that the currently running code was developed using Keil and this new project shall be created using MCUXpresso. I looked at the MCG registers on the Keil project at run time and they differ a lot from what I get when configuring the clock in MCUXpresso and I don't know how to obtain the same configuration from the clock configurator in MCUXpresso.
  3. I'm not calling SDK APIs directly for this. I'm relying totally on the generated code.
  4. What do you mean by "it should transfer the mode from FEI"? Isn't that supposed to be taken care of by the code generated from the clock configurator? Or what is the purpose of the MCUXpresso clock configurator?
  5. I looked at the example in \SDK_2.2.0_MK10DN512xxx10\boards\twrk60d100m\driver_examples\mcg but those are a totally "manual" configuration approach. Are you telling me that I should configure my clock manually? What is the purpose of the clock configurator then?
  6. I looked into the hello_world project but the project is for the TWRK60 board which uses an external oscillator and I'm using an external crystal. Does this matter?
0 Kudos
1,720 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n,

  Answer your related questions:

  1. My chip says 5N22D. I don't know what version is that (5.X?) but I think I'm good here, am I?

Answer: Your chip is the 2.x chip, it's oK, you can use SDK_2.2.0_MK10DN512xxx10 as your chip SDK.   

2. The 8MHz crystal and all the hardware for that matter are working perfectly fine. I'm trying to start a new project at work reusing this particular piece of hardware which currently runs another application just fine. The problem is that the currently running code was developed using Keil and this new project shall be created using MCUXpresso. I looked at the MCG registers on the Keil project at run time and they differ a lot from what I get when configuring the clock in MCUXpresso and I don't know how to obtain the same configuration from the clock configurator in MCUXpresso.

Answer: Thanks for your updated information. So, your hardware really has no issues, as your keil project can works OK. Now, just the MCUxpresso project issues.

Do you try to copy your keil project clock boot related code to your MCUXPresso project directly, that should also works. I mean, don't use the CFG tool generated code, just use the keil related clock code.

BTW, I also help you to create a simple project, the clock mode is the PEE, the external crystal is 8Mhz, the core clock is 96Mhz. As I don't have the board, so I can't test it directly, I think you can test it on your side. Please check my attached project, please note, you need to add the SDK_2.2.0_MK10DN512xxx10.zip to your MCUXPresso IDE installed SDK.

My MCUXPresso IDE version is 11.3.0

3. I'm not calling SDK APIs directly for this. I'm relying totally on the generated code.

Answer: It's Ok!

4.What do you mean by "it should transfer the mode from FEI"? Isn't that supposed to be taken care of by the code generated from the clock configurator? Or what is the purpose of the MCUXpresso clock configurator?

Answer: I mean, any K10 chip is run from FEI, FEI is the default mode, if you want to run to other mode, you need to follow the circuit which I share you to transfer it. But don't worry, you can test my PEE mode directly. BOARD_BootClockRUN function will help you do it.

5.  looked at the example in \SDK_2.2.0_MK10DN512xxx10\boards\twrk60d100m\driver_examples\mcg but those are a totally "manual" configuration approach. Are you telling me that I should configure my clock manually? What is the purpose of the clock configurator then?

Answer: You can ignore it, run my new project on your side, whether that works or not.

6.I looked into the hello_world project but the project is for the TWRK60 board which uses an external oscillator and I'm using an external crystal. Does this matter?

Answer: you are right, the project is using the external reference clock which should be 50Mhz, you can run my generated code.

 

Any updated information from your side, just kindly let me know.

Best Regards,

Kerry

0 Kudos
1,711 Views
m4l490n
Contributor V

Thanks for helping.

Your project still was getting stuck in the same place. After poking around I noticed that I had to semi-manually configure these two options:

m4l490n_0-1611179925795.png

 

I say semi-manually, because I didn't have to do that directly in the source code, but neither through the graphical configurator. To configure those two options I had to select the System oscillator block in the clocks diagram to get those options in the Details view on the right and manually select the correct options.

I had to select the OSC Mode as "Using oscillator with external crystal (low power)" and the Frequency Range as "Very_high frequency range 8-32 MHz".

There is another option for OSC Mode which is Using oscillator with external crystal (high gain) but that one doesn't work despite it is also for an external crystal.

For the Frequency Range, you can use Very_high frequency range 8-32 MHz or High frequency range 3-8 MHz, it is the same with those two, the values don't change in the generated code (which makes me wonder why those two options exist).

I attach the .mex config file in case anyone wants to take a look.

1,696 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n,

  In fact, the low power mode also can be supported, do you add the feedback resistor in the OSC circuit?

image.png

You can check the code, 

const osc_config_t oscConfig_BOARD_BootClockRUN =
{
.freq = 8000000U, /* Oscillator frequency: 8000000Hz */
.capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */
.workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
.oscerConfig =
{
.enableMode = OSC_ER_CLK_DISABLE, /* Disable external reference clock */
}
};

CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);

 

void CLOCK_InitOsc0(osc_config_t const *config)
{
uint8_t range = CLOCK_GetOscRangeFromFreq(config->freq);

OSC_SetCapLoad(OSC0, config->capLoad);
OSC_SetExtRefClkConfig(OSC0, &config->oscerConfig);

MCG->C2 = ((MCG->C2 & ~OSC_MODE_MASK) | MCG_C2_RANGE(range) | (uint8_t)config->workMode);

if ((kOSC_ModeExt != config->workMode) && (OSC0->CR & OSC_CR_ERCLKEN_MASK))
{
/* Wait for stable. */
while (!(MCG->S & MCG_S_OSCINIT0_MASK))
{
}
}
}

So, the low power mode with 8Mhz should also works, but you need add the RF in the circuit, normally 1Mhz, do you add it?

 

Now, when you debug the code, where it is stopping, still the old code place?

 

Best Regards,

Kerry

 

0 Kudos
1,683 Views
m4l490n
Contributor V

No, I haven't added any resistor or caps to the crystal. I have only the crystal connected directly to the MCU exactly how you show in your image.

Yes, the code is stopping in the exact same place if I choose a setting different than "Using oscillator with external crystal (low power)"

0 Kudos
1,672 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n

  Change to FEI mode, and updated to the code, whether you can run the code or not?

  My attached code is FEI mode, please test it, let the project work at first.

  If it works, you can change to FEE, whether that works or not.

 

Please test it.

Any updated information, please kindly let me know.

Best Regards,

Kerry

0 Kudos
1,657 Views
m4l490n
Contributor V

@kerryzhou I have tested the project you include and it works. But I don't understand why are you executing the CLOCK_BootToFeiMode, I mean, I need to go to PEE mode, not FEI.

I was able to make my code work and not get stuck in CLOCK_BootToPeeMode by making the changes in the clock config tool I mentioned in my previous post. The "secret" is:

  • Configure OSC Mode as "Using oscillator with external crystal (low power)
  • Configure Frequency Range as "Very_high frequency range 8-32 MHz" or "High frequency range 3-8 MHz"

That way I don't need to execute CLOCK_BootToFeiMode as you suggestIf I do that, then I will also have to execute CLOCK_SetFbeMode, then CLOCK_SetPbeMode, and finally CLOCK_SetPeeMode to transition the clock from FEI to PEE according to the transition diagram in the RM which seems a lot and unnecessary since that can be done on a single call to CLOCK_BootToPeeMode.

Or maybe I didn't understand the purpose of your attached project. It is working, but I don't understand why executing CLOCK_BootToFeiMode.

Thanks!!

1,651 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n

 Thanks for your updated information.

  You mean, when you modify :

  • Configure OSC Mode as "Using oscillator with external crystal (low power)
  • Configure Frequency Range as "Very_high frequency range 8-32 MHz" or "High frequency range 3-8 MHz"

These two points, you already make it works, right?

If yes, It's my misunderstanding that even you modify the OSC mode as the correct one in the CFG tool, you still can't work, that's why I want to let your test from the first clock mode, then change to the other mode which you want step by step, as I don't have the 100M board with external 8Mhz crystal for testing. Sorry about it.

 About High-frequency (3~32 MHz), high-gain, it needs the external circuit connection contains the feedback resistor and loader capacitor, but you are using connection 1, so you need to use High-frequency (3~32 MHz), low-power.

Of course, you are right, you can use the CLOCK_BootToPeeMode API directly, as this API already help you transfer the mode in this API.

Now, you totally can make the PEE work with the MCUXPresso CFG tool right, and the above post, which you share the .mex, just for the other customer's easy use.

Really thanks so much for your contribution.

 

Best Regards,

Kerry