This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-CC2652RB: How to increase the stack size of TI-RTOS project's main.c?

Part Number: LP-CC2652RB
Other Parts Discussed in Thread: CC2652RB

I'm encountering stack overflow while running CC2652RB projects now. How do I increase its stack size for the main.c and each task? For the main.c stack size, I tried to set the --stack_size in the ARM linker options, but it doesn't seem to work (the .map file says __STACK_SIZE is 1024 no matter what I set it to). The ProjectZero sample project doesn't have either a .cfg file or linker file which other posts suggest to edit. What should I do?

Also, for increasing the app stack size, is it as simple as increasing the #define in each app's C file?

Thank you!

  • Hello Qinchen Gu,

    I hope you are well. 
    To find the cmd file you first need to open the properties for project_zero, go into build, arm linker, and find the file search path, under that we will se the path with “/examples/rtos/LP_CC2652RB/ble5stack/project_zero/tirtos7/ticlang/”, paste that after where your sdk is located in files and we will find the cmd file (second image). As a test when STACK_SIZE (in .cmd file, open/edited with text editor) is set to 1024, we get 00000400 in .map, but when we double it to 2048 we get 00000800 as __STACK_SIZE.

    You can configure the stack size for each task separately, find the code snippet below in the project_zero. 

    For example, 

    void ProjectZero_createTask(void)
    {
        Task_Params taskParams;
    
        // Configure task
        Task_Params_init(&taskParams);
        taskParams.stack = appTaskStack;
        taskParams.stackSize = PZ_TASK_STACK_SIZE;
        taskParams.priority = PZ_TASK_PRIORITY;
    
        Task_construct(&pzTask, ProjectZero_taskFxn, &taskParams, NULL);
    }
     located within project_zero allows you to define PZ_TASK_STACK_SIZE for the task size. 
    I hope this helps.

    For more information on heap sizes (which could be the reason for your overflow) try looking into the ble_relase.cfg file found in "C:\ti\simplelink_cc13xx_cc26xx_sdk_7_10_01_23\source\ti\dmm\apps\common\tirtos" (or wherever you installed your sdk). Alternatively, the BLE user/migration guide gives some useful insight into the functions of the program (search for "heap"). 

    If increasing the RTOS and application stack sizes does not resolve the issue, please consider monitoring your heap usage and adjusting accordingly, have a great day. 

    Thanks,
    Alex

  • Hi Alex,

    Thanks for your detailed reply! I found the .cmd file and opened it, and found the following lines related to STACK_SIZE:

    /*******************************************************************************
     * Stack
     */
    
    /* Create global constant that points to top of stack */
    /* CCS: Change stack size under Project Properties    */
    __STACK_TOP = __stack + __STACK_SIZE;

    And

    --symbol_map __TI_STACK_SIZE=__STACK_SIZE
    --symbol_map __TI_STACK_BASE=__stack

    It doesn't seem to contain explicit definition of the __STACK_SIZE symbol. The comment in the first code snippet takes me back to the project properties -> ARM linker settings. However, no matter what value I set the "Set C system stack size (--stack_size, -stack)" (under Build -> Arm Linker -> Basic Options) to, I always get 0x400 for __STACK_SIZE in the generated map file. BTW, the value was initially blank, and I tried both 1024 and 2048, which doesn't seem to affect the build at all.

    Regarding setting the app stack size, how do I verify the its stack size increased? I'm observing the Memory Allocation's SRAM section, and its value doesn't seem to change with the app stack size value.

    Thanks!

    Qinchen

  • Hello,

    In the file that you've opened (the .cmd file) use ctrl+f and search for stack size, and locate --stack_size=1024 (it is in the CSS Linker Config part of that .cmd file), changing the --stack_size = 1024 to another number like 2048 changes the map file stack size. Make sure to do a clean then rebuild of the project, and see if that changed/affected your map file stack size. 

    In the Memory Allocation you can find the TaskStack (among other tasks), which when we change #define PZ_TASK_STACK_SIZE to something like 4096, the memory allocation reflects to show that.

    Thanks
    Alex 

  • Thanks, Alex! I'm finally able to change the stack size now.