This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NXP KL82 RTX low power mode

Hi there,

Is there anybody know where I can find some example code for NXP KL82 processor running in low power mode on RTX?

I already have a working project setup by colleague. but there is no os_idle_thread implemented. I searched on internet and get some clue on how to do it. I know I have to setup a lptmr, llwu, and then put the mcu into lls mode. I saw an example code write for TI's msp430 chip. I did some modification it seems not working properly.

here is my code


void os_idle_demon (void) {

  for (;;) {

          tc_weakup = os_suspend();
          if (tc_weakup > 0)
          {
                  tc = 0;
                  lp_sleep = 1;

          /* Do not wake up on exit from ISR */
                  SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
                  /* Setting the sleep deep bit */
                  SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
                  __WFI();

          }

          os_resume(tc);

  }
}

void systime_tick()
{


        if (tc++ > tc_weakup && lp_sleep)
        {
                lp_sleep = 0;
                scb->scr &= ~scb_scr_sleeponexit_msk;

                return;
        }
    ++systime_ms;
}


any insight would be grateful.
thank you

Parents
  • tried following code still no luck

    volatile uint32_t tc;
    volatile uint32_t tc_weakup;
    volatile uint8_t lp_sleep = 0;
    void LPTMR1_IRQHandler()
    {
            if (kLPTMR_TimerInterruptEnable & LPTMR_GetEnabledInterrupts(LPTMR1))
            {
                    LPTMR_DisableInterrupts(LPTMR1, kLPTMR_TimerInterruptEnable);
                    LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                    LPTMR_StopTimer(LPTMR1);
            }
    }
    
    void LLWU_IRQHandler(void)
    {
        /* If wakeup by LPTMR. */
    
            tc = 0;
            //LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
            if (LPTMR1->CSR >> 7 )
            {
                    INTMUX_DisableInterrupt(INTMUX0, 0, LPTMR1_IRQn);
                    LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                    LPTMR_StopTimer(LPTMR1);
                    NVIC_EnableIRQ(LPTMR0_IRQn);
            }
    
    
    
    }
    
    
    
    /// \brief The idle demon is running when no other thread is ready to run
    void os_idle_demon (void) {
    
      for (;;) {
    //        __WFI();
              tc_weakup = os_suspend();
              if (tc_weakup > 0)
              {
                      lptmr_config_t lptmrConfig;
                      /* Setup LPTMR. */
                      LPTMR_GetDefaultConfig(&lptmrConfig);
                      /* Use LPO as clock source. */
                      lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_1;
                      lptmrConfig.bypassPrescaler = true;
                      LPTMR_Init(LPTMR1, &lptmrConfig);
    
                      NVIC_EnableIRQ(LLWU_IRQn);
              NVIC_EnableIRQ(LPTMR1_IRQn);
    
                      LPTMR_SetTimerPeriod(LPTMR1, tc_weakup - 1U);
                      LPTMR_StartTimer(LPTMR1);
    
    
                      LLWU_EnableInternalModuleInterruptWakup(LLWU, 0, true);//Module 0 for lptmr0 and lptmr1
                      NVIC_EnableIRQ(LLWU_IRQn);
    
                      smc_power_mode_lls_config_t lls_config;
                      lls_config.subMode = kSMC_StopSub3;
                      lls_config.enableLpoClock =1;
    
                      SMC_SetPowerModeLls(SMC, &lls_config);
                      tc = 0;
    
    
              }
    
              os_resume(tc_weakup);
    
      }
    }
    

Reply
  • tried following code still no luck

    volatile uint32_t tc;
    volatile uint32_t tc_weakup;
    volatile uint8_t lp_sleep = 0;
    void LPTMR1_IRQHandler()
    {
            if (kLPTMR_TimerInterruptEnable & LPTMR_GetEnabledInterrupts(LPTMR1))
            {
                    LPTMR_DisableInterrupts(LPTMR1, kLPTMR_TimerInterruptEnable);
                    LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                    LPTMR_StopTimer(LPTMR1);
            }
    }
    
    void LLWU_IRQHandler(void)
    {
        /* If wakeup by LPTMR. */
    
            tc = 0;
            //LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
            if (LPTMR1->CSR >> 7 )
            {
                    INTMUX_DisableInterrupt(INTMUX0, 0, LPTMR1_IRQn);
                    LPTMR_ClearStatusFlags(LPTMR1, kLPTMR_TimerCompareFlag);
                    LPTMR_StopTimer(LPTMR1);
                    NVIC_EnableIRQ(LPTMR0_IRQn);
            }
    
    
    
    }
    
    
    
    /// \brief The idle demon is running when no other thread is ready to run
    void os_idle_demon (void) {
    
      for (;;) {
    //        __WFI();
              tc_weakup = os_suspend();
              if (tc_weakup > 0)
              {
                      lptmr_config_t lptmrConfig;
                      /* Setup LPTMR. */
                      LPTMR_GetDefaultConfig(&lptmrConfig);
                      /* Use LPO as clock source. */
                      lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_1;
                      lptmrConfig.bypassPrescaler = true;
                      LPTMR_Init(LPTMR1, &lptmrConfig);
    
                      NVIC_EnableIRQ(LLWU_IRQn);
              NVIC_EnableIRQ(LPTMR1_IRQn);
    
                      LPTMR_SetTimerPeriod(LPTMR1, tc_weakup - 1U);
                      LPTMR_StartTimer(LPTMR1);
    
    
                      LLWU_EnableInternalModuleInterruptWakup(LLWU, 0, true);//Module 0 for lptmr0 and lptmr1
                      NVIC_EnableIRQ(LLWU_IRQn);
    
                      smc_power_mode_lls_config_t lls_config;
                      lls_config.subMode = kSMC_StopSub3;
                      lls_config.enableLpoClock =1;
    
                      SMC_SetPowerModeLls(SMC, &lls_config);
                      tc = 0;
    
    
              }
    
              os_resume(tc_weakup);
    
      }
    }
    

Children
No data