STM32, problem with tickless idle mode

fosfolipid wrote on Friday, July 19, 2013:

Hi,
I try to implement tickless idle mode in STM32F103 as in example configuration at 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)
{
      /* Wait for RTC registers synchronization */
      RTC_WaitForSynchro();
      /* Wait until last write operation on RTC registers has finished */
      RTC_WaitForLastTask();     
      return RTC_GetCounter();
}

void prvStopTickInterruptTimer(void)
{
  portNVIC_SYSTICK_CTRL_REG &= ~0x00000002;
}

void prvStartTickInterruptTimer(void)
{
          RTC_WaitForLastTask();
         /* Disable the RTC ALARM */
          RTC_ITConfig(RTC_IT_ALR, DISABLE);
          /* Wait until last write operation on RTC registers has finished */
          //RTC_WaitForLastTask();
          portNVIC_SYSTICK_CTRL_REG |= 0x00000002;
}

void vSetWakeTimeInterrupt( portTickType xExpectedIdleTime )
{
  RTC_WaitForLastTask();
  RTC_ClearFlag(RTC_FLAG_SEC);
  while( RTC_GetFlagStatus( RTC_FLAG_SEC ) == RESET )
  {
  }
  RTC_SetAlarm(RTC_GetCounter() + xExpectedIdleTime);
  RTC_WaitForLastTask();
  /* Enable the RTC Alarm */
  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

fosfolipid wrote on Friday, July 19, 2013:

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…

rtel wrote on Friday, July 19, 2013:

Sorry, I’m not sure what you are saying is wrong.  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)?  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?  So using SysTick during normal operation and the RTC when you turn the tick off?

Regards.

fosfolipid wrote on Friday, July 19, 2013:

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 :slight_smile: so i try to deal with it myself.
Thanks

fosfolipid wrote on Monday, July 22, 2013:

hmm, I noticed some strange things:
1)  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  http://www.freertos.org/low-power-tickless-rtos.html) 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…_

fosfolipid wrote on Monday, July 22, 2013:

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.