cancel
Showing results for 
Search instead for 
Did you mean: 

�?BUG】Cube MX 6.2.0,STM32L562,Freertos,CMSIS V2,Stack Size.

MShao.1
Associate III

For version 6.2.0 of cubemx software, select stm32l562vetx chip, use FreeRTOS CMOS V2, and fill in the stack size for the new task. In the generated armmdk code, the unit is not "words", but "bytes". But if I change to f429ze chip, the generated code will see stack_ size “* 4�?。

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @MShao.1​ ,

Thanks for your feedback.

Actually you're right, I was able to reproduce the issue with the previous STM32CubeMX version 6.2.0 and STM32L562 MCU:

In CMSIS-RTOS v2 implementation (cmsis_os2.c file > osThreadNew function), the argument from CubeMX is divided by sizeof(StackType_t) (== 4):

if (attr->stack_size > 0U) {
        /* In FreeRTOS stack is not in bytes, but in sizeof(StackType_t) which is 4 on ARM ports.       */
        /* Stack size should be therefore 4 byte aligned in order to avoid division caused side effects */
        stack = attr->stack_size / sizeof(StackType_t);
      }

Thus, the issue would be fixed by generating:

osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 128 * 4
};

The issue is no longer reproduced with the latest STM32CubeMX version 6.3.0 and  the stack size used for CMSIS-RTOS v2 tasks dynamically allocated will be correctly generated.

Could you please confirm from your side ?

Khouloud.

View solution in original post

2 REPLIES 2

Hello @MShao.1​ ,

Thanks for your feedback.

Actually you're right, I was able to reproduce the issue with the previous STM32CubeMX version 6.2.0 and STM32L562 MCU:

In CMSIS-RTOS v2 implementation (cmsis_os2.c file > osThreadNew function), the argument from CubeMX is divided by sizeof(StackType_t) (== 4):

if (attr->stack_size > 0U) {
        /* In FreeRTOS stack is not in bytes, but in sizeof(StackType_t) which is 4 on ARM ports.       */
        /* Stack size should be therefore 4 byte aligned in order to avoid division caused side effects */
        stack = attr->stack_size / sizeof(StackType_t);
      }

Thus, the issue would be fixed by generating:

osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 128 * 4
};

The issue is no longer reproduced with the latest STM32CubeMX version 6.3.0 and  the stack size used for CMSIS-RTOS v2 tasks dynamically allocated will be correctly generated.

Could you please confirm from your side ?

Khouloud.

已�?�?�级到6.3.0,正确了。​:ok_hand: