Why the scheduller does not entry in a periodical task?

Hi,

I have created a task to be executed every 500ms with the following code:
I set a breakpoint on the task and after the osKernelStart() I saw that the debugger executes the function only the first time and not again. The kernel is running without a hard fault or an other failure but the task is never called again. I changed randomly the stack size for the task from 128 bytes to 512 bytes and after this change the kernel is calling my task every 500ms.

Why I don’t have an error message or something similar?
How can avoid in the future same problems? and why 128 bytes of stack are not enough for a very small code example like on my example?
Why the task needs so much amount of stack?

/* USER CODE END Header_testTask500msFunc */
void testTask500msFunc(void *argument)
{
  /* USER CODE BEGIN testTask500msFunc */
  portTickType xLastWakeTime;
  const portTickType xDelay = 500 / portTICK_RATE_MS;
   // Initialise the xLastWakeTime variable with the current time.
  xLastWakeTime = xTaskGetTickCount ();
  /* Infinite loop */
   for(;;)
     {
           // Wait for the next cycle.
       vTaskDelayUntil( &xLastWakeTime, xDelay );

       uint16_t intermediateVar[2]={0,0};
       MX_DRV8304_Request_Status(intermediateVar,&hdrv8304);
       HAL_GPIO_WritePin(GPIOB,DRV_INLC_Pin, GPIO_PIN_SET);
       HAL_GPIO_TogglePin(GPIOB,DRV_INHC_Pin);

       

     }
      /* USER CODE END testTask500msFunc */
}

Thanks in advance,
Nikos

If I understand correctly, your stack is overflowing, so do you have a stack overflow checking turned on? If so, what is it doing? If the stack overflow hook does not halt the system it may appear to carry on running even though one task has stopped.

Hi,

thank you for the response,
no I am not using a stack check, I think also the same, that I have a stack overflow.
Important for me is to predict an overflow or to understand better why I don’t have a Hard Fault exception.

But how can you explain that the software is still running, the kernel is still running but the task would be never called?

if I pause the debugger then I see that the software is on the prvCheckTasksWaitingTermination() or portTASK_FUNCTION( prvIdleTask, pvParameters ).

Stack overflows are hard to detect (e.g. OS/syscalls needed as checkpoints). Even worse they might lead to unpredictable behavior. Turning on stack checking for development is nevertheless strongly recommened.
Stack size is predicted by educated guessing based on experience and also having a good idea about the stack requirements of 3rd party library code maybe called from your code. See the forum for the surprising impact to stack size needed when using printf.
Or simply make it just large enough if you have plenty of RAM :wink:

1 Like