# STM32, problem with tickless idle mode

**URL:** <https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816>\
**Category:** Kernel\
**Created:** [July 19, 2013, 10:42am UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816 "2013-07-19T10:42:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 19, 2013, 10:42am UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/1 "2013-07-19T10:42:12Z")

</div>

**[fosfolipid](https://sourceforge.net/u/fosfolipid/)** wrote on [Friday, July 19, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#3166):

Hi,  
I try to implement tickless idle mode in STM32F103 as in example configuration at [http://www.freertos.org/low-power-tickless-rtos.html](http://www.freertos.org/low-power-tickless-rtos.html) I get some good results - it’s working, but not exactly as I wanted: the ticks period is about 150ms (I computed that it can be max 233ms with my configuration (CPU core clock 72MHz, SysTick clock -\> the same, TickRate 1000Hz)). The additional timer used to generate interrupt is RTC.  
These are my implementations of functions from example:

\_unsigned long ulGetExternalTime(void)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Wait for RTC registers synchronization \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RTC\_WaitForSynchro();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Wait until last write operation on RTC registers has finished \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RTC\_WaitForLastTask();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return RTC\_GetCounter();  
}

void prvStopTickInterruptTimer(void)  
{  
&nbsp; portNVIC\_SYSTICK\_CTRL\_REG &= ~0x00000002;  
}

void prvStartTickInterruptTimer(void)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RTC\_WaitForLastTask();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Disable the RTC ALARM \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RTC\_ITConfig(RTC\_IT\_ALR, DISABLE);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Wait until last write operation on RTC registers has finished \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //RTC\_WaitForLastTask();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portNVIC\_SYSTICK\_CTRL\_REG |= 0x00000002;  
}

void vSetWakeTimeInterrupt( portTickType xExpectedIdleTime )  
{  
&nbsp; RTC\_WaitForLastTask();  
&nbsp; RTC\_ClearFlag(RTC\_FLAG\_SEC);  
&nbsp; while( RTC\_GetFlagStatus( RTC\_FLAG\_SEC ) == RESET )  
&nbsp; {  
&nbsp; }  
&nbsp; RTC\_SetAlarm(RTC\_GetCounter() + xExpectedIdleTime);  
&nbsp; RTC\_WaitForLastTask();  
&nbsp; /\* Enable the RTC Alarm \*/  
&nbsp; RTC\_ITConfig(RTC\_IT\_ALR, ENABLE);  
}\_  
Additionally, RTC is clocked with external 32768Hz oscillator, its prescaler is set to 32  
Does anybody has any ideas what’s wrong?

\*sorry for my English, i realize it’s not very good

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 19, 2013, 10:55am UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/2 "2013-07-19T10:55:24Z")

</div>

**[fosfolipid](https://sourceforge.net/u/fosfolipid/)** wrote on [Friday, July 19, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#ca5b):

I forgot it:  
when I changed prvStopTickInterrupt to disable SysTick timer interrupts and disable counter too, the tick period grew to about 30ms.  
Apart of them, I can see on the osciloscope that the tick occurs every 150ms but it toggles four times…

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [July 19, 2013, 12:06pm UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/3 "2013-07-19T12:06:30Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, July 19, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#5ce9):

Sorry, I’m not sure what you are saying is wrong.&nbsp; Is it just that the tick period is incorrect (you try to set the tick period to generate a certain frequency, but the frequency achieved is not what you intended)?&nbsp; Or is it something specific to turning the tick on and off that is wrong?

Unfortunately I can’t comment on chip or peripheral specific configurations as there are just too many chips and peripherals out there to be familiar with all of them.

Are you trying to use both the SysTick timer and the RTC?&nbsp; So using SysTick during normal operation and the RTC when you turn the tick off?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 19, 2013, 12:27pm UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/4 "2013-07-19T12:27:00Z")

</div>

**[fosfolipid](https://sourceforge.net/u/fosfolipid/)** wrote on [Friday, July 19, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#b147):

Yes, I try to use SysTick during normal operation and the RTC when tick is turn off.  
But the problem seems to be with hardware configuration, not with my (mis)understanding of the FreeRTOS 🙂 so i try to deal with it myself.  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 22, 2013, 10:02am UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/5 "2013-07-22T10:02:10Z")

</div>

**[fosfolipid](https://sourceforge.net/u/fosfolipid/)** wrote on [Monday, July 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#d4b8):

hmm, I noticed some strange things:  
1)&nbsp; as i said, i’ve got 2 tasks, both blink led. I don’t change any configuration parameters. When I run default implementation of tickless idle mode, the condition  
\_ if( eTaskConfirmSleepModeStatus() == eAbortSleep )  
is never true. In my implementation (made from example from&nbsp; [http://www.freertos.org/low-power-tickless-rtos.html)](http://www.freertos.org/low-power-tickless-rtos.html%29) this condition is true very often.

2. Another strange thing - change of configTICK\_RATE\_HZ from 1000Hz to 993Hz makes my tickless period (in my own implementation) around 2x longer. And i haven’t a clue why…\_

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 22, 2013, 10:07am UTC](https://forums.freertos.org/t/stm32-problem-with-tickless-idle-mode/1816/6 "2013-07-22T10:07:27Z")

</div>

**[fosfolipid](https://sourceforge.net/u/fosfolipid/)** wrote on [Monday, July 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/561e247d/#bfc5):

and another thing:  
When in function prvStopTickInterruptTimer ( and prvStartTickInterruptTimer ) I only turn off interrupts from SysTick timer the tickless period is 5x longer than when I turn off interrupts and disable a counter too.
