How to enter STOP mode in KE04?

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

How to enter STOP mode in KE04?

Jump to solution
4,878 Views
abdullahkahrama
Contributor IV

Hello,

I am trying to make the KE04 wait in STOP mode for about 1 sec, however it wakes up every 800 us. I have set the RTC timer with 100ms interrupt and I have checked that this is correct by toggling a pin in RTC interrupt. I have SysTick interrupt set at 1 ms and I have checked that this is correct by toggling a pin in SysTick interrupt. Also, when the WFI command is given, SysTick interrupt doesn't toggle the pin that should be toggled in the interrupt, so that means the SysTick timer is stopped.

Here is the code I use for testing and the pin is toggled about every 800 us:

_100_ms_ctr = 0;

while (_100_ms_ctr < 11) // 1 sec

{

    //Cpu_SetOperationMode(DOM_STOP, NULL, NULL);

    /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */

    SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;

    /* WFI instruction will start entry into STOP mode */

    asm("WFI");

    // Toggle pin

    GPIOA_PTOR = (1 << 10);

}

Here is my interrupt code:

PE_ISR(RTC_Interrupt)

{

    RTC_SC |= RTC_SC_RTIF_MASK;

    WDOG_CNT = 0x02A6; // write the 1st refresh word

    WDOG_CNT = 0x80B4; // write the 2nd refresh word to refresh counter

    _100_ms_ctr++;

}

What is the reason for this?

Labels (1)
1 Solution
2,538 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Yasuhiko Koumoto,

The reply from the AE as follows and hope it helps.

It’s not very clear in the manual, but the systick is actually clocked by the platform clock which is the same frequency as the core clock. We don’t really document the difference between the two very well. Since they are the same frequency most of the time it doesn’t matter, but for low power modes it starts to become important. The platform clock runs in WAIT mode, so it is expected operation for the systick to run in WAIT mode and be able to wake you up.


Have a great day,
Ping

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

View solution in original post

0 Kudos
47 Replies
1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Abdullah,

I'm working on your issue now, however I was wondering if you can share your PE project, then I can fix the issue of the project directly.

I'll update you if I figure out the issue and I'm also looking forward to your project.
Have a great day,
Ping

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

1,992 Views
abdullahkahrama
Contributor IV

Hello Ping,

My issue has changed now and SysTick interrupt is waking the KE04 up I guess.. Anyways, here is my project, attached to this message.

0 Kudos
1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Abdullah Kahraman,

I think I already figured out the fundamental reason this issue that systick interrupt couldn't wake up the MCU from the STOP mode.

After you've had a brief look through the KE04's RM, you can find that the core clock provide the particular clock source for the systick (Fig 1), however the core clock will become disabled when MCU works under either Wait or Stop mode (Fig 2).

Wish it helps.

2015-03-06_16-25-41.jpg

                                                            Fig 1

2015-03-06_16-26-56.jpg

                                                      Fig 2
Have a great day,
Ping

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

1,992 Views
abdullahkahrama
Contributor IV

Hello Ping,

Thank you for your answer.

Actually, I don't want SysTick to wake the MCU up, that's why I am putting it under WAIT and/or STOP mode with the RTC timer and interrupt enabled. I want the MCU to wake up every 100 ms. However, in my code it seems like SysTick is also waking up my MCU. When I debug the code, debugger is telling me that the MCU has entered the WAIT or STOP mode but SysTick interrupt wakes the MCU up. I am aware that I cannot debug the WAIT or STOP modes with their full functionality that's why I am toggling some pins on the MCU to detect the interrupts, but no luck.

0 Kudos
1,991 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Abdullah Kahraman,

Please check the attachment and refer to it for details.
Have a great day,
Ping

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

1,992 Views
abdullahkahrama
Contributor IV

Hello Ping,

Your project doesn't implement a SysTick timer or any interrupt other than RTC. If I disable SysTick interrupt before going to sleep and enable it when the CPU wakes up by RTC, everything works fine in my project, too.

What I don't understand is SysTick is running and generating interrupts when the CPU is in STOP or WAIT mode. I am really confused with this.

0 Kudos
1,992 Views
PatriciaTeran
Contributor III

Hi, Abdullah Kahraman

Sorry for the late response, are you still having problems?

Regards

Patricia

0 Kudos
1,992 Views
yasuhikokoumoto
Senior Contributor I

Hello Patricia,

My problem which would be taking care by Ping have not been solved.

I am waiting for an answer long time.

Best regards,

Yasuhiko Koumoto.

0 Kudos
2,539 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Yasuhiko Koumoto,

The reply from the AE as follows and hope it helps.

It’s not very clear in the manual, but the systick is actually clocked by the platform clock which is the same frequency as the core clock. We don’t really document the difference between the two very well. Since they are the same frequency most of the time it doesn’t matter, but for low power modes it starts to become important. The platform clock runs in WAIT mode, so it is expected operation for the systick to run in WAIT mode and be able to wake you up.


Have a great day,
Ping

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

0 Kudos
1,992 Views
yasuhikokoumoto
Senior Contributor I

Hello Ping,

thank you for the confirmation.

Regarding WAIT mode, I understood.

How about STOP mode?

Even in the STOP mode, does the platform clock not stop?

Is it the Bus clock?

According to TRM, the Bus clock will stop in STOP mode but we found different behavior.

Bets regards,

Yasuhiko Koumoto.

0 Kudos
1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Hi Yasuhiko Koumoto,

I think the platform clock still be available in STOP mode too, not the BUS clock and this clock's never mentioned in the RM yet.

However it actually exists according to the reply.
Have a great day,
Ping

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

1,992 Views
abdullahkahrama
Contributor IV

Hello Ping,

Thank you for your answer, it now makes sense. I hope they will update the reference manual soon. :smileyhappy:

0 Kudos
1,992 Views
yasuhikokoumoto
Senior Contributor I

Hello Ping,

thank you got your clarification.

Best regards,

Yasuhiko Koumoto.

0 Kudos
1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Yasuhiko Koumoto,

I've also waited for the reply from the AE team until now and I think the issue maybe pended by other issues which have higher priority.

So I will increase the priority of the issue and thanks for your understanding.

Ping

0 Kudos
1,992 Views
yasuhikokoumoto
Senior Contributor I

Hello Ping,

may I enter the discussion?

How do you realize the RTC interrupt period of 10ms?

I think no RTC setting seems to be in your sample code.

Best regards,

Yasuhiko Koumoto.

0 Kudos
1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Yasuhiko Koumoto,

Of course, welcome to join the discussion.

I've configured 1.408s as the RTC interrupt period as an example in the project, not the 10ms.

2015-03-10_8-50-23.jpg
Have a great day,
Ping

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

1,992 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Abdullah Kahraman,

Thanks for your reply.

I'm going to create a simple demo about using RTC interrupt to wake up MCU periodically and run this demo with the FRDM-KE04 for validation.

Then you can refer to it for checking.
Have a great day,
Ping

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

1,993 Views
yasuhikokoumoto
Senior Contributor I

Hi Abdullah Kahraman,

I guess the reason that SysTick interrupt makes the MCU up would be SysTick Interrupt had been pending before executing WFI instruction. Also in the case, WFI will skip to enter the WAIT/STOP mode. You had better clear pending of SysTick interrupt before execution WFI by writing 1 to ICSR.PENDSTCLR (bit 25 of 0xE000ED04) .

I know this is not the final target of your program.

Best regards,

Yasuhiko Koumoto.

1,993 Views
abdullahkahrama
Contributor IV

Hello Yasuhiko,

Thank you for your answer and sorry for my late reply.

I have tried to clear pending interrupts using following code and the CPU still enters SysTick interrupt and wake up.

while (1)

    {

        GPIOA_PTOR = (1 << 13);

        SCB_SCR &= (uint32_t) ~(uint32_t) (SCB_SCR_SLEEPONEXIT_MASK);

        SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;

       

        NVIC_ICPR = 0xFFFFFFFF;

       

        PE_WFI();

    }

0 Kudos
1,993 Views
yasuhikokoumoto
Senior Contributor I

Hi Abdullah Kahraman,

I don't mention NVIC_ICPR but mention ICSR because SysTick interrupt is out of NVIC control.

CPU core interrupt pending would be cleared by ICSR (0xE000ED04).

pastedImage_0.png

To clear SysTick pending,

*(long *)(0xE000ED04) = (1<<25);

As the register includes SysTick interrupt pending set bit (bit 26), you cannnot write all "1" into it.

Best regards,

Yasuhiko Koumoto.