LPTMR does not work in low-leakage modes VLLS.

cancel
Showing results for 
Search instead for 
Did you mean: 

LPTMR does not work in low-leakage modes VLLS.

295 Views
albertomartin
Contributor II

Hello:

I am using a Kinetis MK60 microcontroller and  it enters correctly in vlls3 mode.
I want to count the milliseconds that it is in VLLS3 mode. So, I want to use the LPTMR.

This is the code that I called before entering VLLS3:

 /* SIM_SCGC5: LPTIMER=1 */
  SIM->SCGC5 |= SIM_SCGC5_LPTIMER_MASK; /// Activamos.
 
   LPTMR0->CSR = (LPTMR_CSR_TCF_MASK | LPTMR_CSR_TPS(0x00)); /* Clear control register */

  LPTMR0->PSR = LPTMR_PSR_PRESCALE(0x00) | LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PCS(0x01);    /* Set up prescaler register */

   LPTMR0->CSR = ( LPTMR_CSR_TPS(0x00) |  LPTMR_CSR_TFC_MASK | LPTMR_CSR_TEN_MASK); /* Set up control register */

This works correctly.
But when I wake up by LLWU, the LPTMR module is off.
This is because in the SIM_SCGC5 register the SCGC5_LPTMR bit is set to 0.

What can you owe?
How can I operate the Low-Power Timer in low-power mode?

Thanks.

Labels (1)
Tags (4)
0 Kudos
5 Replies

74 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Alberto Martin,

   Please enable the LLWU interrupt, then in the LLWU interrupt, when check the wakeup is caused by the LPTMR, enable the LPTMR in SIM_SCGC5, clear the LPTMR TCF, this is the llwu ISR code from KL25 for your reference:

//Interrupt handler for LLWU 
#ifdef CMSIS
void LLW_IRQHandler(void) {
#else
void llwu_isr(void){
#endif
   //printf("\n [LLWU ISR] "); 
   if (LLWU_F1 & LLWU_F1_WUF5_MASK) {
   //    printf("****WUF5 was set *****\r\n"); 
       LLWU_F1 |= LLWU_F1_WUF5_MASK;   // write one to clear the flag
   }
   if (LLWU_F1 & LLWU_F1_WUF6_MASK) {
   //    printf("****WUF6 was set *****\r\n"); 
       LLWU_F1 |= LLWU_F1_WUF6_MASK;   // write one to clear the flag
    }
   if (LLWU_F1 & LLWU_F1_WUF7_MASK) {
   //    printf("****WUF7 was set from PTC3 input  *****\r\n"); 
       LLWU_F1 |= LLWU_F1_WUF7_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF8_MASK) {
   //    printf("****WUF8 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF8_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF9_MASK) {
   //    printf("****WUF9 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF9_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF10_MASK) {
   //    printf("****WUF10 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF10_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF11_MASK) {
   //    printf("****WUF11 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF11_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF12_MASK) {
   //    printf("****WUF12 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF12_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF13_MASK) {
   //    printf("****WUF13 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF13_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF14_MASK) {
   //    printf("****WUF14 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF14_MASK;   // write one to clear the flag
   }
   if (LLWU_F2 & LLWU_F2_WUF15_MASK) {
   //    printf("****WUF15 was set *****\r\n"); 
       LLWU_F2 |= LLWU_F2_WUF15_MASK;   // write one to clear the flag
   }
   
   /************************************************************************
    * Note: This ISR does not write to the LLWU_F3 register because these
    * are peripheral module wakeups.  The flags contained in the LLWU_F3 
    * register should be cleared through the associated module interrupt 
    * and not through the LLWU_F3 per the Kinetis L Family Reference
    * Manual (LLWU Chapter)
    **********************************************************************/
  if (LLWU_F3 & LLWU_F3_MWUF0_MASK) {
    //   printf("****WUF3_MWUF0 IF  LPTMR  *****\r\n"); 
         SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;
         LPTMR0_CSR |=  LPTMR_CSR_TCF_MASK;   // write 1 to TCF to clear the LPT timer compare flag
         LPTMR0_CSR = ( LPTMR_CSR_TEN_MASK | LPTMR_CSR_TIE_MASK | LPTMR_CSR_TCF_MASK  );
   }
   if(LLWU_FILT1 & LLWU_FILT1_FILTF_MASK){
        
        LLWU_FILT1 |= LLWU_FILT1_FILTF_MASK;
   }
   if(LLWU_FILT2 & LLWU_FILT2_FILTF_MASK){
        
        LLWU_FILT2 |= LLWU_FILT2_FILTF_MASK;
   }
   NVIC_ICPR |= 1 << (LLWU_irq_no%32);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  if (LLWU_F3 & LLWU_F3_MWUF0_MASK) {
    //   printf("****WUF3_MWUF0 IF  LPTMR  *****\r\n");
         SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;
         LPTMR0_CSR |=  LPTMR_CSR_TCF_MASK;   // write 1 to TCF to clear the LPT timer compare flag
         LPTMR0_CSR = ( LPTMR_CSR_TEN_MASK | LPTMR_CSR_TIE_MASK | LPTMR_CSR_TCF_MASK  );
   }

You can try it on your side.

If you still have question about it, please kindly let me know!


Have a great day,
Kerry

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

0 Kudos

74 Views
albertomartin
Contributor II

Hello:
Thank you very much for the reply, but it does not work.When we return from reset the module and LPTMR is deactivated.

This is code, includes the LLWU and activated interrupts.

!

          /// Init Milisec.
     /* SIM_SCGC5: LPTIMER=1 */
     SIM->SCGC5 |= SIM_SCGC5_LPTIMER_MASK; /// Init Clock of LPTIMER.

     LPTMR0->CSR = (LPTMR_CSR_TCF_MASK | LPTMR_CSR_TPS(0x00)); /* Clear control register */

     LPTMR0->CMR = (0xFFFE); /* Compare. */

     LPTMR0->PSR = LPTMR_PSR_PRESCALE(0x00) | LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PCS(0x01);    /* Set up prescaler register */

     LPTMR0->CSR = ( LPTMR_CSR_TPS(0x00) |  LPTMR_CSR_TFC_MASK | LPTMR_CSR_TIE_MASK | LPTMR_CSR_TEN_MASK); /* Set up control register */

     //enable_irq();
     NVIC_ClearPendingIRQ(LPTimer_IRQn);
     NVIC_EnableIRQ(LPTimer_IRQn);

     // LLWU_EnableLPTMR.
     SIM->SCGC4 |= (uint32_t) SIM_SCGC4_LLWU_MASK;
     /* Initialization of the LLWU module */
     LLWU->PE1 = 0x00;
     LLWU->PE2 = 0x00;
     LLWU->PE3 = 0x00;
     LLWU->PE4 = 0x00;
     LLWU->ME = 0x00;
     /* LLWU_FILT1: FILTF=1,FILTE=0,??=0,FILTSEL=0 */
     LLWU->FILT1 = LLWU_FILT1_FILTF_MASK | LLWU_FILT1_FILTE(0x00) | LLWU_FILT1_FILTSEL(0x00);
     LLWU->FILT2 = LLWU_FILT2_FILTF_MASK | LLWU_FILT2_FILTE(0x00) | LLWU_FILT2_FILTSEL(0x00);
     LLWU->RST = LLWU_RST_LLRSTE_MASK | LLWU_RST_RSTFILT_MASK;
     
     LLWU->ME |= (uint8_t) ( LLWU_ME_WUME0_MASK); /// -> Module LPTMR0

     // Goto SLEEP:
     SMC->PMPROT |= SMC_PMPROT_AVLLS_MASK; // PMPROT -> AVLLS
     SMC->PMCTRL |= SMC_PMCTRL_STOPM(STOPM_VLLSx); //PMCTRL ->VLLSx
     SMC->PMCTRL |= SMC_PMCTRL_LPWUI_MASK; // LPWUI Active.
     SMC->VLLSCTRL = SMC_VLLSCTRL_VLLSM(VLLSM_VLLS3); // VLLSCTRL -> VLLSM_VLLS3
     
     SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
     __wfi();
0 Kudos

74 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Alberto,

  Thank you for your updated information.

  Please tell me your K60 part number, I will test it on my side.

Waiting for your reply!


Have a great day,
Kerry

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

0 Kudos

74 Views
albertomartin
Contributor II

Hi Kerry Zhou:

I am using the equipment MK60FN1M0VMD12


Thank you very much for all the information and help.

Alberto Martin.

0 Kudos

74 Views
kerryzhou
NXP TechSupport
NXP TechSupport

HI Alberto Martin,

  Please also share your problem project, I will modify the code directly on your project, and test it.

  You can delete all the other code which is important to you, just leave the smallest project which can reflect your problem.


Have a great day,
Kerry

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

0 Kudos