cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: STM32CubeMX Task Stack Size, words Vs bytes.

David Bathurst
Associate III

0690X00000BxopVQAR.pngThe GUI interface for defining FreeRTOS tasks dictates that stack size is specified in words. That generates a call to CMSIS V2's osThreadNew() which requires attributes.stack_size to be specified in bytes. (The CMSIS layer then divides that by 4 to convert it back words before passing it to FreeRTOS which dictates it's specified in words).

The GUI gets it right for Static tasks, but appears to get it wrong for Dynamic tasks. For example, the above selection in the GUI produces the following correct code for the static case. It declares the array to be 256 words long, and sets stack size to 1024 bytes.

uint32_t bannerTaskBuffer[ 256 ];
osStaticThreadDef_t bannerTaskControlBlock;
const osThreadAttr_t bannerTask_attributes = {
  .name = "bannerTask",
  .stack_mem = &bannerTaskBuffer[0],
  .stack_size = sizeof(bannerTaskBuffer),

In contrast, the size for the dynamic task is passed through to .stack_size unchanged:

const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 512
};

so it's requesting 512 bytes as per the CMSIS V2 API, which the intermediate layer turns into 128 words before calling down to FreeRTOS. So while I specified 512 words in the GUI, I only got 1/4 of that.

7 REPLIES 7
Khouloud ZEMMELI
ST Employee

​Hello @David Bathurst​ 

I will check this problem.

Best Regards,

Khouloud

Khouloud ZEMMELI
ST Employee

@David Bathurst​  Issue fixed , you will receive the fix with the 5.6.0 MX version.

Thanks for your feedback.

Best Regards,

Khouloud​

David Bathurst
Associate III

Excellent, thanks Khouloud​.

MShao.1
Associate III

For version 6.2.0 of cubemx software, select stm32l562vetx chip and use FreeRTOS CMOS V2, there will be the same problem. But after I change f429ze, the generated code will see stack_ size“*4�?。

Hello @MShao.1​ ,

Could you please switch to the latest CubeMX version 6.3.0?

If you still face a problem, please share your ioc file to check it.

I'll be waiting for your feedback 🙂

Thanks, Khouloud

"6.3.0" is OK.👌

Great ! 🙂