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
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); } }
I feel after the rtx initialized, my code never blocked and enter to os_idle_deamon. Does os_delay put the thread into wait state and block the code?
I forgot to write "SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeLls);" to enable lls mode. And seems you cannot stop while debugging? the PMSTAT is always 1 no matter how I se PMPROT, PMCTRL and STOPCTRL.
But it entered into sleep mode, if I just reset my board. The current reading from my power supplier is 0ma. Have to see if my os_deamon_idlea implementation work tomorrow.
do not forget enable lptmr interrupt “LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);”