FRDMK22 VLLS2 RTC wakeup using RTC_Seconds_IRQHandler

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

FRDMK22 VLLS2 RTC wakeup using RTC_Seconds_IRQHandler

1,029 Views
nesrinemhiri
Contributor III

Hello,

I try to wake up my board from VLLS2 using RTC, I sart from power demo in SDK :

in main.c I do this:
SystemInit();
CLOCK_SYS_SetRtcOutSrc(kClockRtcoutSrc32kHz);
CLOCK_SYS_EnableRtcClock(0U);
RTC_HAL_Init(RTC_BASE_PTR);

if (!(RTC_HAL_IsOscillatorEnabled(RTC_BASE_PTR)))
{
BOARD_InitRtcOsc();
}
/* Enable the RTC Clock output */
RTC_HAL_SetClockOutCmd(RTC_BASE_PTR, true);
NVIC_ClearPendingIRQ(RTC_Seconds_IRQn);
INT_SYS_EnableIRQ(RTC_Seconds_IRQn);
INT_SYS_EnableIRQ(LLWU_IRQn);

while(1)

{

 VLSS2();

}

void VLSS2(void)

{

volatile unsigned int dummyread;
gSecsFlag = false;
/* Write to PMPROT to allow VLLS2 power modes */
SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;
/* Set the VLLSM field to 0b100 for VLLSx(for MC1)
or STOPM field to 0b100 for VLLSx (for MC2)
- Retain state of LPWUI and RUNM */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK ;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4) ;
/* set VLLSM = 0b10 in SMC_VLLSCTRL (for MC2) */
SMC_STOPCTRL &= ~SMC_STOPCTRL_LLSM_MASK;
SMC_STOPCTRL |=SMC_STOPCTRL_LLSM(0x2);
dummyread = SMC_STOPCTRL;
/* Set the SLEEPDEEP bit to enable deep sleep mode - enter stop mode*/
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();

}

void RTC_Seconds_IRQHandler(void)
{
gSecsFlag = true;

//I try to blink led
}

/*!
* @brief LLW_IRQHandler that would cover the same name's APIs in startup code
*/

void LLWU_IRQHandler(void)
{

if (RTC_HAL_HasAlarmOccured(RTC))
{
RTC_HAL_SetAlarmIntCmd(RTC_BASE_PTR, false);
}
LLWU_HAL_ClearExternalPinWakeupFlag(LLWU_BASE_PTR, (llwu_wakeup_pin_t)BOARD_SW_LLWU_EXT_PIN);

}

The issue is that my board enter in VLLS2 and never wake-up , Could you please tel me about the issue in my handler configuration

Thank you for your support 

Nesrine

5 Replies

830 Views
nesrinemhiri
Contributor III

Any help is appreciated 

0 Kudos

830 Views
mjbcswitzerland
Specialist V

Nesrine

If you try to set a new alarm time in the RTC interrupt handler (which is already in the RTC interrupt context and doesn't look to reset the interrupt flag) the new alarm may not work (being in the interrupt context won't stop it waking again but not clearing the flag and allowing a new one to be triggered will).

Don't forget that there is a solution that I have shown you in the uTasker project that does this - it is free and open source in case you need something working.

If you are a professional and your specification is to use the examples as project base you can get them fixed quickly by using the service at the support link given in the previous post.

Regards

Mark

0 Kudos

830 Views
mjbcswitzerland
Specialist V

Hi

Wake up from VLLS2 is via reset, so the handler will never be taken.
Is the problem that you expect the handler to be called (which is not possible) or that the processor never actually exits from VLLS2?

I think that you need to make the actual reset/initialisation visible otherwise you will not know when it is restarting and going back to the VLSS2 state again.

Regards

Mark


Kinetis: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
Low power and LLWU: http://www.utasker.com/kinetis/LLWU.html
Low power videos:
- https://youtu.be/kWNlsAoMly4
- https://youtu.be/iZEMRiDmHzw
- https://youtu.be/v4UnfcDiaE4

Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

Professional Kinetis support, one-on-one training and complete fast-track project solutions: http://www.utasker.com/support.html

830 Views
nesrinemhiri
Contributor III

Hi Mark,

In fact my K22 board takes a lot of time to execute the run (128ms) then enter to VLLS2, I expect lower time in run 

this my issue.

void cmd_alarm(uint8_t offsetSec)
{
uint32_t seconds = 0;
RTC_HAL_GetDatetimeInSecs(RTC_BASE_PTR, &seconds);
seconds += offsetSec;
RTC_HAL_SetAlarmReg(RTC_BASE_PTR, seconds);
RTC_HAL_SetAlarmIntCmd(RTC_BASE_PTR, true);

}

If I call the cmd_alarm(0) in the RTC handler (RTC_IRQHandler) then my Board enter in VLSS2 and never wakeup,


void RTC_IRQHandler(void)
{
RTC_HAL_SetAlarmIntCmd(RTC_BASE_PTR, false);
blink_led(); // 
cmd_alarm(0);
}

if I call the cmd_alarm(0) in VLSS2() function , I have the wakeup every second but in take time in run 

void VLSS2(void)

{

volatile unsigned int dummyread; 
gSecsFlag = false;

 cmd_alarm(0);
/* Write to PMPROT to allow VLLS2 power modes */
SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;
/* Set the VLLSM field to 0b100 for VLLSx(for MC1)
or STOPM field to 0b100 for VLLSx (for MC2)
- Retain state of LPWUI and RUNM */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK ;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4) ;
/* set VLLSM = 0b10 in SMC_VLLSCTRL (for MC2) */
SMC_STOPCTRL &= ~SMC_STOPCTRL_LLSM_MASK;
SMC_STOPCTRL |=SMC_STOPCTRL_LLSM(0x2);
dummyread = SMC_STOPCTRL;
/* Set the SLEEPDEEP bit to enable deep sleep mode - enter stop mode*/
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; 
__WFI();

}

void RTC_IRQHandler(void)
{
RTC_HAL_SetAlarmIntCmd(RTC_BASE_PTR, false); 
blink_led(); // 130MS
}

 what can be the issue of this bigger time in run i?

thank you for your help,

Nesrine.

0 Kudos

830 Views
nesrinemhiri
Contributor III

Any help