Kinetis MK60 Low Power System Tick

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

Kinetis MK60 Low Power System Tick

1,582 Views
jfs
Contributor I

Hello,

I am working with MK60 processor with CW 10.4 to set it in VLPR mode without PE. I have implemented a function to set the clocks and enter in VLPR mode, that works. However it seems that the systick is lost because functions like _time_delay or _time_delay_ticks stop to work.

I want to update from my application the systick to be able to use it. My first approach was to use:

SYST_RVR =  4000000/1000; //clock used in VLPR is 4MHz (fast internal RC)

SYST_CVR = 0; //current value to zero

SYST_CSR = 0x07;

But it doesn't works. Can you help me please?

I also attach my function to change to the VLPR:

  SIM_SOPT1|=1<<SIM_SOPT1_OSC32KSEL_SHIFT;

  MCG_C2|=1<<MCG_C2_IRCS_SHIFT;

  /////////////////Switch to PBE////////////////////////////////

  MCG_C1|= MCG_C1_CLKS(0x02);

  MCG_C1&=~(MCG_C1_IREFS_MASK);

  while(((MCG_S&MCG_S_CLKST_MASK)>>MCG_S_CLKST_SHIFT)!=0x02){

  }

  MCG_C6|= 1<<MCG_C6_PLLS_SHIFT;

  MCG_C2&=~(MCG_C2_LP_MASK);

  //If we pass this while, it means we achieve PBE clock

  while(1){

  if(((MCG_C1 & MCG_C1_CLKS_MASK)>>MCG_C1_CLKS_SHIFT==0x02) && ((MCG_C1 & MCG_C1_IREFS_MASK)==0x00) && ((MCG_C2 & MCG_C2_LP_MASK)>>MCG_C2_LP_SHIFT==0x00)) break;

  }

  //////////////////////////////////////////////////////////////

  /////////////////Switch to BLPE///////////////////////////////

  MCG_C2|=(1<<MCG_C2_LP_SHIFT);

  //If we pass this while, it means we achieve BLPE clock

  while(1){

  if(((MCG_C1 & MCG_C1_CLKS_MASK)>>MCG_C1_CLKS_SHIFT==0x02) && ((MCG_C1 & MCG_C1_IREFS_MASK)==0x00) && ((MCG_C2 & MCG_C2_LP_MASK)>>MCG_C2_LP_SHIFT==0x01)) break;

  }

  //////////////////////////////////////////////////////////////

  SMC_PMCTRL &= ~SMC_PMCTRL_RUNM_MASK;

  SMC_PMCTRL = (SMC_PMCTRL_RUNM(0x02) | SMC_PMCTRL_STOPM(0x00) ); /* Enable very low power mode */

  while(SMC_PMSTAT != 0x04U) {         /* Wait until in the Very Low Power run mode */

  }

Thank you!

Labels (1)
0 Kudos
5 Replies

974 Views
DavidS
NXP Employee
NXP Employee

Hi JFS,

You might consider using the KDS_3.0 and KSDK_1.2 development tool (both are free) to implement power management capability without PE.

The KDS is the IDE.

The KSDK is static peripheral driver source code used by the demo's and examples.

For the TWR-K60D100M the best starting point would be:

C:\Freescale\KSDK_1.2.0\examples\twrk60d100m\demo_apps\power_manager_hal_demo\kds

Read the C:\Freescale\KSDK_1.2.0\doc\Getting Started with Kinetis SDK (KSDK) v.1.2.pdf PDF to get started.

Video's to help out:  Kinetis Design Studio

Document's too:  Kinetis Design Studio

Regards,

David

0 Kudos

974 Views
jfs
Contributor I

Hi David,

Thank you for your help, but by now it is not possible for us to switch to KDS iddle. I look the examples you said me but it talks about the low power timmer. Maybe I don't explain well.

The routine I attached changes the mode clock to the BLPE one using the fast internal oscillator of 4MHz. I got it work but when I use functions like _time_delay (useful for introduce delays and switch tasks), the system seems to be unsynchronized with the new frequency. The _time_delay or _time_delay_ticks work but the delay time is much higher than the one I want to introduce. I try to update the systick timer using the function _time_set_hwticks_per_tick but it still doesn't work.

Which registers I have to change to achieve it? Could you said me which is the clock that systick timer uses?

Regards,

     Joan

0 Kudos

974 Views
isaacavila
NXP Employee
NXP Employee

Hello Joan,

Systick timer is a core timer (ARM) that uses either Core clock or internal clock, this can be modified on CLKSOURCE bit (for more information: ARM Information Center) but in K60 processor, CLKSOURCE bit is always set to select the core clock (You can check this on section 3.2.1.2 System tick Timer on K60 reference manual).

Are you using MQX? or could you please tell me where _time_delay functions come from?

Regards,

Isaac

0 Kudos

974 Views
jfs
Contributor I

Hello Avila,

You are right, I am using MQX on CW and I use the _time_delay function to switch between tasks. I have seen that the system tick timer is linked to the core clock as you said and also that the systick timer is initalized in the bsp initialization. Once the system is powered up (after bsp initialization), I change the core clock frequency but the systic timer is not update with the new frequency. 

Is there any way to update it through any register or with intrinsic functions of MQX?

Regards,

        Joan

0 Kudos

974 Views
soledad
NXP Employee
NXP Employee

Hello Joan,

In order to modify the system tick please check the below doc.

https://community.freescale.com/docs/DOC-104385

However it is necessary to remember, we cannot guarantee the correct behavior if you modify original settings. Some of drivers, for example USB, Ethernet PHY, ESDHC, etc, use commands like _time_delay; if the resolution is changed then we could get unexpected behavior of these drivers. Only change this value if you know what you are doing.

For Low Power please check the below link and the attached documents:

http://cache.freescale.com/files/32bit/doc/app_note/AN4447.pdf


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos