hello world example gets stuck

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

hello world example gets stuck

Jump to solution
2,065 Views
stdcerr
Contributor IV

Hi,

I've  been wanting to upgrade to SDK 2.X and MCUXpresso IDE. I have downloaded the IDE and crearted an SDK for my MCU MK64FN1M0xxx12. I've loaded it up and tried to import the hello world example application but I can't seem to get it to run, the debugger (using SEGGER JLINK) keeps getting stuck in fsl_clock.c at:

 

 

    /* Wait for CLKST clock status bits to show clock source is ext ref clk */
    while ((MCG->S & (MCG_S_IREFST_MASK | MCG_S_CLKST_MASK)) !=
           (MCG_S_IREFST(kMCG_FllSrcExternal) | MCG_S_CLKST(kMCG_ClkOutStatExt)))
    {
    }

 

 

What am I missing to get this to execute correctly?I'm not sure what ext ref clk refers to exactly.

Labels (1)
Tags (1)
0 Kudos
1 Solution
2,016 Views
myke_predko
Senior Contributor III

@stdcerr 

It may not feel like it but you're on the right track.  While you probably want to use PEE in your application, I suggest that you work up to it.  

Personally, I would start with the goal of getting the crystal running - don't worry about the PLL just yet.  

What happens if you select "PBE"?  You should be able to get the crystal running and then work on the PLL to get your application running at speed.  

I know the clock wizard is cranky and there's no adequate documentation for using it - I have spent a lot of time clicking at things and then going back to the reference manual to try and figure out what's happening and how I want to get to where I'm going.  

Let us know how you are making out on getting the crystal running and then, give us screen shots of the clock wizard so we can see where the problems lie.  

Don't forget to check the "Error" box in the bottom right hand corner of the clock wizard - often the messages are useful (but you'll have to go to the reference manual to understand the messages).  

Good luck,

myke

View solution in original post

20 Replies
2,041 Views
stdcerr
Contributor IV

Turns out that simply commenting-out the call to

BOARD_BootClockRUN() from the main() function resolves the issue - DUH!

0 Kudos
2,052 Views
ErichStyger
Senior Contributor V

It means that the clock is not able to 'lock in' or match the desired settings. 'ext ref clk' is the external reference clock (oszillator) on your board.

Do other examples work on your board?

2,061 Views
stdcerr
Contributor IV

I've set OSC in the Clocks Table to 12MHz (according to the oscillator we are using) but I'm not sure about the MCG Mode I need to select. Can anybody help me with this?

We have a 32.768kHz crystal hooked up to the XTAL32 & EXTAL32 pins and a 12MHz crystal connected to PTA19 & PTA18 but I cannot find where or how I configure this in MCUXpresso....

0 Kudos
2,035 Views
myke_predko
Senior Contributor III

@stdcerr 

I don't know how serious you are about commenting out "BOARD_BootClockRUN" but that will keep the processor running from the SLOW_IRCCLK at the default start speed (32kHz).  

 

@ErichStyger has the right suggestion, but I think you need a bit of context.  As he says, the clocks aren't synchronizing and the easiest way to fix it is to go into the Clocks Wizard in MCUXpresso and change the values for:

  • OSC (System Oscillator) - this should be 12MHz
  • Frequency Range - I find that this operates unexpectedly depending on the specified value
  • Internal (to the Kinetis) capacitors - If you are adding your own crystal capacitors, leave this at 0

and then retest your application (ie see if it returns from the BOARD_BootClockRUN method).  

I have found that with a bit of experimenting with these values, you'll get your board running...

There is a caveat and that depends on the crystal selected and it's placement/wiring on the PCB.  Make sure you understand the caps required, the crystal and caps are as close as possible to the processor pins and you have a good ground plane.  

Good luck!

2,019 Views
stdcerr
Contributor IV

@myke_predko wrote:

@stdcerr 

I don't know how serious you are about commenting out "BOARD_BootClockRUN" but that will keep the processor running from the SLOW_IRCCLK at the default start speed (32kHz).  

 

@ErichStyger has the right suggestion, but I think you need a bit of context.  As he says, the clocks aren't synchronizing and the easiest way to fix it is to go into the Clocks Wizard in MCUXpresso and change the values for:

  • OSC (System Oscillator) - this should be 12MHz
  • Frequency Range - I find that this operates unexpectedly depending on the specified value
  • Internal (to the Kinetis) capacitors - If you are adding your own crystal capacitors, leave this at 0

and then retest your application (ie see if it returns from the BOARD_BootClockRUN method).  

I have found that with a bit of experimenting with these values, you'll get your board running...


I've tried around a bit but I always end up with getting BOARD_BootClockRUN in red (drop down on top - in Clocks view). Hovering over it, reads:

ERRORS:
Requirement(s) not satisfiable.

And when I select PEE (in IMCG Mode), everything past the PLL block is red. I've tried to modify the PLL accordingly but am not able to. The PLL Frequency is set at 28.8MHz (and it shows a little red cross to the left of the number but doesn't provide any further hints) plus i don't seem to be able to change the frequency at all. Both PLL clock & PLL clock in Stop mode are set Disabled, PRDIV is set to /20 (is in red color) and VDIV is set to *48 (red colored also). I'm not sure how I can configure this correctly.

Can anyone assist me with this?

 

Tags (2)
0 Kudos
2,017 Views
myke_predko
Senior Contributor III

@stdcerr 

It may not feel like it but you're on the right track.  While you probably want to use PEE in your application, I suggest that you work up to it.  

Personally, I would start with the goal of getting the crystal running - don't worry about the PLL just yet.  

What happens if you select "PBE"?  You should be able to get the crystal running and then work on the PLL to get your application running at speed.  

I know the clock wizard is cranky and there's no adequate documentation for using it - I have spent a lot of time clicking at things and then going back to the reference manual to try and figure out what's happening and how I want to get to where I'm going.  

Let us know how you are making out on getting the crystal running and then, give us screen shots of the clock wizard so we can see where the problems lie.  

Don't forget to check the "Error" box in the bottom right hand corner of the clock wizard - often the messages are useful (but you'll have to go to the reference manual to understand the messages).  

Good luck,

myke

2,010 Views
stdcerr
Contributor IV

@myke_predko wrote:

@stdcerr 

It may not feel like it but you're on the right track.  While you probably want to use PEE in your application, I suggest that you work up to it.  

Personally, I would start with the goal of getting the crystal running - don't worry about the PLL just yet.  

What happens if you select "PBE"?  You should be able to get the crystal running and then work on the PLL to get your application running at speed.  

I know the clock wizard is cranky and there's no adequate documentation for using it - I have spent a lot of time clicking at things and then going back to the reference manual to try and figure out what's happening and how I want to get to where I'm going.  

Let us know how you are making out on getting the crystal running and then, give us screen shots of the clock wizard so we can see where the problems lie.  


Thank you for the tips, it does look better already but seem not to be able to resolve the Core clock issue. How it looks so far:

stdcerr_0-1604603286252.png

 

0 Kudos
1,971 Views
myke_predko
Senior Contributor III

Hey @stdcerr 

That's helpful and I think it's starting to explain what's happening.  

I *think* you have IRC48M enabled - correct?  What are you going to use it for?   

Could I suggest turning off IRC48M internal oscillator and then selecting OSCCLK in OSCSEL to run from the 12MHz clock?  

In the screen shot you've provided, I can't see what's happening with the System Oscillator - this is where you should be getting your 12MHz clock signal.  Once you have that, you should be passing it through MCGOUTCLK (this is PBE) and then to the Core Clock etc.  

More importantly, you should be able to get out of the BOARD_InitBootClocks method.  

When you get to this point, then you can start working on getting PEE working.  

1,997 Views
stdcerr
Contributor IV

There, I've got a configuration without errors now but with PEE:

stdcerr_0-1604611638601.png

 

BOOM: Yeps, I was able to confirm that after I clkicked on Update Code, the function BOOT_InitBootClocks() now returns fine! Yay!

Only thing is, is it a problem that I'm using the internal 48MHz oscillator instead of the 12MHz system oscillator?

 

0 Kudos
1,960 Views
myke_predko
Senior Contributor III

@stdcerr 

Sorry, just saw this now - I replied directly to your reply to me but didn't read through the whole thread.  

You're asking if it's a problem that you're running the Internal 48 MHz Oscillator instead of the external 12 MHz.  That depends on your application, if you're going to use the Kinetis for anything that requires a precision clock (USB & Ethernet being  big ones and you may have issues with the UART).  

If you aren't using any of these peripherals, then you can delete the 12 MHz crystal and use the two pins for IO.  

Personally, I would recommend getting the crystal working.  Maybe you don't need it now...

 

1,927 Views
stdcerr
Contributor IV

@myke_predko wrote:

@stdcerr 

Sorry, just saw this now - I replied directly to your reply to me but didn't read through the whole thread.  

You're asking if it's a problem that you're running the Internal 48 MHz Oscillator instead of the external 12 MHz.  That depends on your application, if you're going to use the Kinetis for anything that requires a precision clock (USB & Ethernet being  big ones and you may have issues with the UART).  

If you aren't using any of these peripherals, then you can delete the 12 MHz crystal and use the two pins for IO.  

Personally, I would recommend getting the crystal working.  Maybe you don't need it now...

 


Yes, I'll need the crysral working because I'm going to be using this for CAN which needs precision timing.

I have now changed the OSCSEL to the 12MHz oscillator, deactivated the PLL, changed the PLLS to FLL but can't seem to get the numbers right for the Core clock. Do you have any further hints? What I have now looks like:

stdcerr_0-1604682721395.png

 

0 Kudos
1,922 Views
myke_predko
Senior Contributor III

Hiya @stdcerr 

Looking at your clock diagram, you're running your system with the SLOW_IRCLK and not the 12 MHz Crystal.  

Follow the heavy lines on the diagram because that's the clock path - You've specified "FEI", which is FLL Engaged Internal which is what you're seeing - the internal clock going into the FLL and then into MCGOUTCLK Mux.  

I think you want to try "PBE" which will use your external clock, bypass the PLL, go directly to MCGOUTCLK and you'll have your core/system clocks running at 6 MHz.  

When I look at your PLL values (/ 20 * 50 - divide by 20 and then times 50) I don't think they're valid for the clock register.  Regardless, we can look at that later, let's get PBE working.

1,923 Views
stdcerr
Contributor IV

e we go:

PLL = /4*40:

stdcerr_0-1604685055675.png

I think this should/could/would do the trick, shouldn't it?

0 Kudos
1,920 Views
myke_predko
Senior Contributor III

@stdcerr 

Yes, that's more in line with what I'm looking for.  

Let me know how it works on the part.  

myke

1,913 Views
stdcerr
Contributor IV

@myke_predko wrote:

@stdcerr 

Yes, that's more in line with what I'm looking for.  

Let me know how it works on the part.  

myke


No,

 

This actually isn't good, the code gets stuck in BOARD_InitBootClocks(); at

 

    /* Wait for CLKST clock status bits to show clock source is ext ref clk */
    while ((MCG->S & (MCG_S_IREFST_MASK | MCG_S_CLKST_MASK)) !=
           (MCG_S_IREFST(kMCG_FllSrcExternal) | MCG_S_CLKST(kMCG_ClkOutStatExt)))
    {
    }

 

What am I missing?

This is with:

stdcerr_0-1604688606852.png

 

0 Kudos
1,904 Views
myke_predko
Senior Contributor III

@stdcerr 

Okay, we're where we want to be - you're trying to start the clock and we can build from there.  

Have you tried running PBE yet?  That should just be the 12MHz oscillator.  

When you have and you're still stuck in the loop, what are the values for the following parameters (found in the "Clocks Table" of the Clocks Wizard):

  • OSC Mode
  • Frequency Range
  • System Osc. Capacity Load

With PBE, I found that I had to select different values until I got it right.  

As a note "System Osc. Capacity Load" is what you want for internal bypass capacitors to the crystal - if you have added any externally, then make this value zero (0).  

0 Kudos
1,898 Views
stdcerr
Contributor IV

So yes, I tried OPBE now and I've got this:

stdcerr_0-1604690505749.png

As for the clocks table, it looks like:

stdcerr_1-1604690590141.png

 One little thing that I realized is, Core clkock was at 120MHz with a little padlock and showed an error, I then double clicked on it in the clocks table, which removed the error (and padlock)and it then changed to 12MHz.

So with the above setup, it still gets stuck at

    /* Wait for CLKST clock status bits to show clock source is ext ref clk */
    while ((MCG->S & (MCG_S_IREFST_MASK | MCG_S_CLKST_MASK)) !=
           (MCG_S_IREFST(kMCG_FllSrcExternal) | MCG_S_CLKST(kMCG_ClkOutStatExt)))
    {
    }

 

0 Kudos
1,896 Views
stdcerr
Contributor IV

wait, i modified the OSC mode and selected

  • Using oscillator with external crystal (low power)

instead of

  • Using external reference clock

which I think solved the problem!

0 Kudos
1,893 Views
myke_predko
Senior Contributor III

Are you out of the BOARD_BootClockRUN method?  

If yoiu are, then you should be able to select PBE as your run mode.  You asked about using /4 * 40 -> that should give you a clock speed of 120 MHz ((12MHz / 4) * 40).

I think you're pulling it together,

myke

0 Kudos
2,050 Views
ErichStyger
Senior Contributor V

Use the 'clocks' tool. See https://mcuoneclipse.com/2020/02/16/tutorial-maximum-clock-frequency-for-kinetis-using-mcuxpresso-cl... which is a tutorial for a different board but the same applies for your board.

I hope this helps,

Erich

0 Kudos