0

I'm currently trying to make my device (STM32F105) which is usually running 12 threads on CMSIS RTOS go to low power mode. In order to simplify the algorythm I think (definitely not sure) that it's a good idea to terminate all the threads using osThreadTerminate and after a wake up recreate them using osThreadCreate

    void os_idle_demon (void) {
  /* The idle demon is a system thread, running when no other thread is      */
  /* ready to run.                                                           */

  for (;;) {
    /* HERE: include optional user code to be executed when no thread runs.*/
        if (Sleep.SleepEnabled == 1)
        {
            if (Sleep.IsSleeping == 1)
            {
//              __wfi();
//              PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); //PWR_Regulator_LowPower
                __nop();
//              osDelay(5000);
                if (Sleep.WakeUp)
                {
                    Sleep.IsSleeping = 0;
                    WakeUp();
//                  SetSysClock();
                    Sleep.WakeUp = 0;
                    Sleep.SleepEnabled = 0;
                    Sleep.TimeTillSleep = 60;
                }
            }
            else
            {
                if (Sleep.TimeTillSleep == 0 )
                {
                    TerminateTasks();
                    ResetPeripherals();
                    Sleep.IsSleeping = 1;
//              PWR_EnterSTANDBYMode();
//                  __wfi();
//                  PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
                    __nop();
//                  osDelay(5000);
                }
            }
        }
  }
}    

As you can see I use some global variables to determinte when to sleep. TerminateTasks(); is used to terminate all of my running threads using osThreadTerminate function which doesn't seem to cause any trouble, but after I call WakeUp(); which uses osThreadCreate function to recreate terminated threads I run into an os stack overflow. So there are a few questions I struggle to find answers to. Does osThreadTerminate command in CMSIS-RTOS release stack after execution? Is there a better way to go into a low power mode ? I hope I made my point clear, if there's a need to be more specific let me know. Would be grateful if you shared your experience with similar problems.

Alutis
  • 1
  • 3
  • You don't need to terminate your tasks to go into low power mode. In general, you don't want to stop and restart RTOS threads. – rost0031 Jun 09 '16 at 15:23
  • Ok, let's consider different scenario. What if I use some global variables which tell threads to stop doing work, for example while(sleep){osDelay(1000)}; I believe that __wfi(); instructions stops CPU till interrupt is executed so I wonder how this would respond to my current consumption. – Alutis Jun 10 '16 at 12:14
  • There should be no effect of your threads still "running" while you're in low power mode. The entire processor is asleep and the only circuitry that is active is RAM and the Interrupt monitoring for getting out of sleep (this really depends on which processor you're using but the you get the idea). – rost0031 Jun 10 '16 at 17:21

1 Answers1

0

Do you use dynamic allocation in your other thread ? Because if so, killing your thread when there are running could result in memory leak.

nbout
  • 1,159
  • 8
  • 12