Skip to content

OsThreadNew is incorrectly limiting thread stack size to 64K #51

@david-oz00

Description

@david-oz00

In the file cmsis_os2.c :

When the osThreadNew() function calls the FreeRTOS xTaskCreate() function it casts the stack size parameter to an (uint16_t) as seen below:

        #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
          if (xTaskCreate ((TaskFunction_t)func, name, (uint16_t)stack, argument, prio, &hTask) != pdPASS) {
            hTask = NULL;
          }

However, FreeRTOS allows the stack parameter to be defined by the user using configSTACK_DEPTH_TYPE. If the user defines the stack depth to be a uint32_t it could be truncated when cast to a uin16_t. I recommend the cast to be removed or at the very least, cast to configSTACK_DEPTH_TYPE like:

        #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
          if (xTaskCreate((TaskFunction_t)func, name, (configSTACK_DEPTH_TYPE)stack, argument, prio, &hTask) != pdPASS) {
            hTask = NULL;
          }
        #endif

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions