stack overflow

gridsense wrote on Wednesday, November 09, 2011:

My application goes to “vApplicationStackOverflowHook()” in some conditions, I can’t work out the reason. There are 4 tasks, 3 in block state, only one is running, I add “ChargerTaskWaterMark3 = uxTaskGetStackHighWaterMark(NULL);” at the end of this task, but it return good value (436).

Would someone give me a clue how to trace this problem.

richard_damon wrote on Wednesday, November 09, 2011:

Note that the vApplicationStackOverflowHook is called with 2 parameters to help figure out what happened, the first is the TCB of the task that failed, and the second is the task name.

Note that tasks can sometimes take differing amounts of memory depending on the path they take, and on many implementations which interrupts occured while they are running.

jandle wrote on Wednesday, November 09, 2011:

Keep a global dubug structure and for each task take the lesser of the measurement and remaining stack.
Place the test at places where you might allocate temporary variables like a char array that chew up stack briefly but not permanently.  Allow extra stack for called functions, ISR’s etc.

unsigned short usNew = uxTaskGetStackHighWaterMark (xTH_Serial0Command);
xDebug.usSD_Serial0Command = xDebug.usSD_Serial0Command<usNew?xDebug.usSD_Serial0Command:usNew;

gridsense wrote on Wednesday, November 09, 2011:

Problem found.
There is a function force the MCU go to sleep, the high frequency oscillator is turned off, systick timer is connected to high frequency oscillator,  but the 32Khz low frequency oscillator is still running.

But I can’t work out why “systick timer” stop will cause stackoverflow.
If MCU go to sleep, How to make RTOS keep going after MCU wakeup? Connect the “systick timer” to 32Khz oscillator with
same Tick_Rate_Hz"(say 10mS per tick), then switch to high frequency oscillator after wakeup?

rtel wrote on Thursday, November 10, 2011:

I can’t answer specifically, just generically, but would say it sounds like you are entering a very deep sleep, and therefore it depends on what happens to other peripherals/RAM etc while asleep, and what happens when you wake up again.

I’m not sure how you are wanting your system to work, but if the SysTick is stopping, than task blocks times that are not infinite are probably not going to function correctly, as to them, time will have stopped.

This might be of interest to you - in particular the pdf file:
http://interactive.freertos.org/entries/20291196-energy-optimized-port-of-freertos-6-for-efm32

Regards.

glory1978 wrote on Friday, January 20, 2012:

I’m little confused.
I use STM3240g evaluation board. And try to run FreeRTOS on it. My main function

int main(void)
{
  unsigned portBASE_TYPE i;

  /* Initialize CAN interface */
  vSetupNVIC_CAN();
  vSetupCAN();
  vSetupCANFilters();

  CAP2Init();

  LCD_LED_Init();

  for(i=0;i<NUMBER_OF_TIMERS;i++)
  {
    xAutoReloadTimers_ = xTimerCreate(………….);
  }

  xTimerReset(xAutoReloadTimers, 0);
  xTimerReset(xAutoReloadTimers, 0);

  xTaskCreate( ……………);

  vTaskStartScheduler();

  return 0;
}

After  LCD_LED_Init(); program goes to vApplicationStackOverflowHook.
But when I move LCD initialization in task-function like this:

static void vTaskLCD( void *pvParameters )
{
  volatile TaskParam *pxTaskParam;
  pxTaskParam = (TaskParam *) pvParameters;
  LCD_LED_Init();
  for( ;; )
  {
    vTaskDelay( 100 / portTICK_RATE_MS);
    … led blinking …
  }
  vTaskDelete( NULL );
}

and create new task
   xTaskCreate( vTaskLCD, (signed char *) “Task LCD”,  configMINIMAL_STACK_SIZE*2, (void*)&xTP1, 1, NULL );
everything work - LCD initialized.

Where may be a problem ?
sources
http://rghost.ru/36003924
http://rghost.ru/36004000
http://rghost.ru/36004015
USE_LCD - defined_