Use RTC Alarm to wakeup K64 from VLLSx

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

Use RTC Alarm to wakeup K64 from VLLSx

Jump to solution
4,288 Views
willx
Contributor IV

Hello,

I'm having a hard time using the RTC Alarm as a wakeup source from VLLS0/1/2/3 on the K64 and  wondering if anyone here can be of help.

I'm setting bit 5 of the LLWU_ME to enable the RTC Alarm as a wakeup module. I can go into VLLS successfully but never leave and reset using RTC Alarm. The alarm I’m setting is just 30 seconds in the future. So I read the current time from RTC_TSR and increment it by 30. I'm able to use the LPTMR to wake up from VLLS1 but RTC Alarm never works from any of the VLLS levels. So the VLLS part is fine but having the RTC Alarm trigger a LLWU is not.

Here's some snippets of the relevant parts of the code. Any help would be greatly appreciated!

The RTC is initialized in the following way:

void rtc_init(void)

{
   SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;

   // Check Oscillator Enable

   if((RTC_CR & RTC_CR_OSCE_MASK) == 0)

   {

      RTC_CR |= RTC_CR_OSCE_MASK; // Enable Oscillator

      delay_us(RTC_OSC_STARTUP_DELAY_US); // Wait for oscillator to startup

   }

   SIM_SOPT1 |= SIM_SOPT1_OSC32KSEL(3);

   RTC_CR &= ~RTC_CR_CLKO_MASK; // The 32kHz clock is output to other peripherals

   SIM_SOPT2 |= SIM_SOPT2_RTCCLKOUTSEL_MASK; // Output the 32kHz RTC to RTC_CLKOUT

   RTC_IER |= RTC_IER_TAIE_MASK; // Enable Alarm Interrupt

   RTC_IER |= RTC_IER_TOIE_MASK; // Enable overflow interrupt

   RTC_IER |= RTC_IER_TIIE_MASK; // Enable time invalid interrupt

   enable_int_vector(INT_RTC, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);

}

Before going to VLLS we do the following:

       LLWU_ME |= LLWU_ME_WUME5_MASK

       // Clear external pin LLWU flags

       LLWU_F1 = 0xFF;

       LLWU_F2 = 0xFF;

The LLWU IRQ handler is:

__sysfunc void LLWU_IRQHandler(void)

{

   // Clear external pin LLWU flags

   LLWU_F1 = 0xFF;

#ifdef LLWU_F2

   LLWU_F2 = 0xFF;

#endif

   // Clear any filters
   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;

   }

}

Labels (1)
0 Kudos
1 Solution
2,794 Views
willx
Contributor IV

FYI, I was able to fix this by writing to clear the RTC Time Alarm flag inside the LLWU IRQ handler:

__sysfunc void LLWU_IRQHandler(void)

{

   RTC_SR |= RTC_SR_TAF_MASK;

...

...

...

}

I tried this after going through AN4503 and reading this: "Pin wake up flags must be cleared in the LLWU"

View solution in original post

0 Kudos
20 Replies
2,795 Views
willx
Contributor IV

FYI, I was able to fix this by writing to clear the RTC Time Alarm flag inside the LLWU IRQ handler:

__sysfunc void LLWU_IRQHandler(void)

{

   RTC_SR |= RTC_SR_TAF_MASK;

...

...

...

}

I tried this after going through AN4503 and reading this: "Pin wake up flags must be cleared in the LLWU"

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello

Use RTC Alarm as a wakeup module , the wakeupt flag is  LLWU_F3 - > MWUF5 .

and for the internal wakeup source caused the flag , it is cleared follow the internal peripheral flag clearing mechanism,

that it to say , clear the flag on  RTC interrupt function .

Hope it help


Have a great day,
Alice

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

0 Kudos
2,794 Views
willx
Contributor IV

Hi Alice,

Can you clarify which flag exactly needs to be cleared in the RTC interrupt function?

I'm already clearing the the corresponding bit in the RTC status register by writing 0 to the RTC_TAR register:

void RTC_IRQHandler(void)

{

  ISR_ENTER();

  if(RTC_SR & RTC_SR_TAF_MASK)

  {

      // Alarm flag

      // Clear by writing to the RTC_TAR

      RTC_TAR = 0;

Thanks!

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello ,

Yes , you are right , the RTC interrupt flag.

- Which VLLSx mode do you run, if VLLS0, In reference manual, the LPO is off , so you can not use LPO here :

  SIM_SOPT1 |= SIM_SOPT1_OSC32KSEL(3);   

  You can change to “RTC 32.768KHZ oscillator” ot test , and the LPO is power on on VLLS1 VLLS2 VLLS3 mode , so you can test these mode .

-If it still can not work ,  you can set a breakpoint to check if RTC alarm interrupt happen.

- And i recommend you one DOC http://cache.freescale.com/files/rf_if/doc/app_note/AN4857.pdf ,

although the chip is different , while the procedure is the same :

pastedImage_1.png

Hope it helps


Have a great day,
Alice

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

0 Kudos
2,794 Views
willx
Contributor IV

Still no luck Alice.

Changing from

SIM_SOPT1 |= SIM_SOPT1_OSC32KSEL(3)

to

SIM_SOPT1 |= SIM_SOPT1_OSC32KSEL(2);

doesn't make a difference.

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Will,

What about the VLLS1 , does it can be wake up ?

And have test check whether it can run into the RTC alarm interrupt ?

BR

Alice

0 Kudos
2,794 Views
willx
Contributor IV

Hi Alice,

- RTC alarm cannot wake up K64 from any VLLS level (VLLS1/2/3).

- RTC alarm can fire normally in regular operation. I already verified that.

Thanks for your help!

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Will,

I also create one KDS bare board project abut RTC alarm wake up the VLLS3 mode , please see the attachment .

And for after VLLS3 wake up , the chip will be reset , so when you use the it be wake up,  it will run to main , it run to the VLLS3 mode again, then .....loop..

(for in my project , i did nothing after wake up , so i will loop). If you check the current , you will see it also loop from low to high ...

Hope it helps


Have a great day,
Aice

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

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Will,

There is a KSDK1.3 sample code about RTC-alarm  vake up k64 from any VLLSx model :

...\KSDK_1.3.0\examples\twrk64f120m\demo_apps\power_manager_hal_demo\kds

I have test the sample , it can work well .

Have you install KSDK ? if not , i recommend you install it , please download it here :

Software Development Kit for Kinetis MCUs|Freescale

Hope it helps

Alice

0 Kudos
2,794 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Will,

Ok , i will create on project refer to your requirement , then will send it to you , while please wait .

BR

Alice

0 Kudos
2,794 Views
mjbcswitzerland
Specialist V

Hi Will

If you don't find a quick fix you can also get complete RTC/LLWU support for the K64 in the uTasker project - see inks below. I have attached a FRDM-K64F image which includes the uTasker Time Keeper module (maintains all time functions including SNTP for the K64, Gregorian time, daylight-saving and various alarms) and the LLWU module (which works together with it allow timed wakeup from low power modes).

The command line shell is on the its virtual COM port at 115'200 Baud and the time and low power interface is in the "Administrator" menu:

Hello, world... KINETIS

Serial number: 00
Software version V1.4.010
Device identification: KINETIS

   Admin. menu
===================
up               go to main menu
show_config      Show configuration
save             Save configuration to FLASH
reject           Reset non-saved changes
restore          Restore factory settings
show_time        Display date/time
set_time         Set time hh:mm:ss
set_date         Set Date dd:mm:yyyy
show_alarm       Display alarm d/t
set_alarm        Set alarm (date)(+)[time]
del_alarm        Delete alarm
show_lp          Show low power mode and options
set_lp           [option] Set low power mode
reset            Reset device
last_rst         Reset cause
help             Display menu specific help
quit             Leave command mode

#show_time
22.10.2015 15:29:30

set_alarm +5
New alarm set
22.10.2015 15:29:50

#RTC Alarm fired
set_alarm +5
New alarm set
22.10.2015 15:29:58

#set_lp 6


Hello, world... KINETIS

Here an alarm can be set using "set_alarm +" or with a time and/or data. set_lp allows various low power modes to be set:

#show_lp
0 = RUN
1 = WAIT [active]
2 = STOP
3 = VLPR
4 = VLPS
5 = LLS
6 = VLLS0
7 = VLLS1
8 = VLLS2
9 = VLLS3

whereby I used 6 above (VLLS0) and the alarm wakes this a few seconds later via a reset (shown by the "Hello, world... KINETIS").

- LLUW module: http://www.utasker.com/kinetis/LLWU.html
- Time Keeper: http://www.utasker.com/docs/uTasker/uTasker_Time.pdf

Regards Mark

Kinetis: http://www.utasker.com/kinetis.html

K64: http://www.utasker.com/kinetis/FRDM-K64F.html / http://www.utasker.com/kinetis/TWR-K64F120M.html / http://www.utasker.com/kinetis/TWR-K65F180M.html

For the complete "out-of-the-box" Kinetis experience and faster time to market

:smileyinfo: Out-of-the-box support for 47 Kinetis boards and 10 IDEs (470 combinations from a single code source with no porting required)

0 Kudos
2,794 Views
willx
Contributor IV

Hi Mark,

I'm not sure how what you sent is helpful. The attachment is just a binary.

Thanks though!

0 Kudos
2,794 Views
mjbcswitzerland
Specialist V

Will

The binary allows checking the operation on a standard board - also, by viewing register settings it may be possible to identify a difference that can explain why it works but yours doesn't.

In addition, the links are to full source code of a complete solution in case you were interested in avoiding the need to solve example difficulties.

Regards

Mark

0 Kudos
2,794 Views
willx
Contributor IV

Which code are you referring to? I don't see any links to code in the uTasker LLWU Support page?

0 Kudos
2,794 Views
mjbcswitzerland
Specialist V

Will

LLWU is a technical document. Try clicking on the navigation menu to find other things.

Regards

Mark

0 Kudos
2,794 Views
willx
Contributor IV

I'm not sure where you're trying to point me to. The website has no valuable code to look at.

0 Kudos
2,794 Views
mjbcswitzerland
Specialist V

Will

I am sorry that you can't find anything - it is probably easier to stay with what you have and try to solve that.

A few tips:

1. The default clock to the RTC is the 32kHz oscillator, which continues oscillating in VLLSx

2. You don't need to supply the clock to other peripherals - it is always supplied to the RTC, irrespective of RTC_CR_CLKO_MASK

3. SIM_SOPT1 and SIM_SOPT2 are not required to be set/modified - the first controls the clock to the LPTRM and so doen't affect the RTC or waking from VLLSx. The second contros the RTC_CLKOUT to other peripherals and is not needed for this funtion.

Good luck.

Regards

Mark

0 Kudos
2,794 Views
willx
Contributor IV

My code does what you recommended but still no luck. Any other suggestions?

Thanks for your help Mark!

0 Kudos
2,794 Views
mjbcswitzerland
Specialist V

Will

- Measure the 32kHz quarz to ensure that it is still oscillating in the VLLSx mode.

- If you have a FRDM-K64F board load the binary that I posted to it and check that it operates correctly. With a debugger check the register settings and compare to those that you have (or use the memory debugger in I/O menu to read the values)

If your work is commerical I can also offer a solution if you send me your complete code so that I can correct it accordingly. You can request such a service at http://www.utasker.com/support.html

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html

K64: http://www.utasker.com/kinetis/FRDM-K64F.html / http://www.utasker.com/kinetis/TWR-K64F120M.html / http://www.utasker.com/kinetis/TWR-K65F180M.html

For the complete "out-of-the-box" Kinetis experience and faster time to market

:smileyinfo: Out-of-the-box support for 47 Kinetis boards and 10 IDEs (460 combinations from a single code source with no porting required)

0 Kudos
2,795 Views
willx
Contributor IV

Thanks Mark.

I was able to verify that the 32KHz oscillator is still oscillating in VLLSx mode.

I narrowed down the problem to something in the wakeup procedure that happens when the RTC alarm fires. This is because I have 2 LLWU sources defined: the RTC alarm and a switch connected to PTC1:

      LLWU_ME |= LLWU_ME_WUME5_MASK; // RTC Alarm

      LLWU_PE2 |= LLWU_PE2_WUPE6(3); // Button switch

For debugging purposes, my RTC alarm is set to 30 seconds in the future. When the K64 goes into VLLS, I can press the button at any point within those 30 seconds and it will wake up from sleep and go through reset as expected. However, if I wait 30 seconds, the RTC alarm never wakes up the K64 and any button presses have no effect. So I'm guessing that the alarm fires but something is messed during the wakeup and the K64 gets stuck.

Any help would be greatly appreciated!

0 Kudos