cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS and cmsis

o_
Associate II
Posted on May 06, 2015 at 18:48

Hi,

 

I would like to known if I don't understand something or if there is a bug in cmsis_os.c (STMCube for STM32F429)

1) In osThreadCreate()  stacksize in bytes is directly passed to xTaskCreate() but the definition for the usStackDepth argument is

usStackDepth 

The size of the task stack specified as the number of variables the stack can hold - not the number of bytes.

typedef struct os_thread_def  {

  char                   *name;        ///< Thread name

  os_pthread             pthread;      ///< start address of thread function

  osPriority             tpriority;    ///< initial thread priority

  uint32_t               instances;    ///< maximum number of instances of that thread function

  uint32_t               stacksize;    ///< stack size requirements in bytes; 0 is default stack size

} osThreadDef_t;

osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)

{

  TaskHandle_t handle;

 

 

  if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,

              thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),

              &handle) != pdPASS)  {

    return NULL;

  }

 

  return handle;

}

I think the definition of stacksize in os_thread_def must be changed or the code of

osThreadCreate() must be corrected.

2 REPLIES 2
sstearns
Associate
Posted on June 02, 2015 at 18:03

Looks like a bug in either the comments or the code to me.  It appears that  thread_def->stacksize is only used in this one place.  IF that's really the case, then the fix could be as simple as fixing the comments associated with osThreadCreate()  stacksize.  In the mean time, it appears the impact is just that you are allocating a size four times larger than intended.  (now if I could only figure out why my code quits starting the task when the stack size is set as big as I need...)

Vito Marolda
Associate III
Posted on May 26, 2017 at 21:15

Another inconsistency: stackSize = 0 should mean DEFAULT stack size; instead it allocates zero stack.