Skip to main content
AGarp.1
Associate II
December 26, 2019
Question

Does cubeide assign the wrong stack size?

  • December 26, 2019
  • 5 replies
  • 1793 views

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

This topic has been closed for replies.

5 replies

turboscrew
Senior III
December 26, 2019

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
AGarp.1Author
Associate II
December 26, 2019

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
December 27, 2019

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
AGarp.1Author
Associate II
December 27, 2019

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
Visitor II
December 30, 2019

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.