cancel
Showing results for 
Search instead for 
Did you mean: 

Does cubeide assign the wrong stack size?

AGarp.1
Associate II

When I use CMSIS RTOS I set a stack size of 128 words. Then the following code is generated:

 /* Create the thread(s) */
 
 /* definition and creation of cmdHandlerTask */
 
 const osThreadAttr_t cmdHandlerTask_attributes = {
 
  .name = "cmdHandlerTask",
 
  .priority = (osPriority_t) osPriorityNormal,
 
  .stack_size = 128
 
 };
 
 cmdHandlerTaskHandle = osThreadNew(CmdHandlerTask, NULL, &cmdHandlerTask_attributes);

When I read the documentation, the stack size in osThreadAttr_t is in bytes and the code seems to confirm this. Is this a bug or have I misunderstood it? (Im new to stm32 and this kind of low level programming so Im not too confident that I understood things right.)

Can someone confirm or disprove my suspicion?

Best,

Anders

5 REPLIES 5
turboscrew
Senior III

The stack size seems to be in bytes: https://arm-software.github.io/CMSIS_5/RTOS2/html/group__CMSIS__RTOS__ThreadMgmt.html#structosThreadAttr__t

Where did you get that it would be in words?

AGarp.1
Associate II

It is explicitly stated so in the CubeMX IDE that the stack size is in words. And the heap usage calculator seems to use that info.0690X00000BuxvbQAB.png

turboscrew
Senior III

Which one are you using? FreeRTOS (built on CMSIS-RTOS) or CMSIS-RTOS (alone)? FreeRTOS uses words for stack sizes.

There is also CMSIS-API for FreeRTOS. Don't get fooled.

AGarp.1
Associate II

Im using CMSIS API v2 which is using FreeRTOS as backend. But what seem to be the issue is the Cube code autogenerator.

Dmytro Kovalenko
Associate II

I agree with topic starter. When selected CMSISv2 - then Cube "say Words", but code generated in bytes. As result stack overflow for default task mostly guaranteed.