This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to set stacksize

Excuse me:

                    I'm porting other FreeRTOS projects to ble_app_hrs_freertos example In the directory nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_hrs_freertos,I need to ask the following questions:

                    1、What is the maximum stack? Where can I set it?

                    2、How many stacks should be reserved for ble task?

                    3、The stack used by my other projects to be migrated is shown in the figure below,How do I set the size of the stack for my project?

                     

  • Hi!

    Due to the summer holidays, a huge portion of the support staff and R&D developers are currently on vacation, including our FreeRTOS experts. 

    You can expect someone to take a look at this case in week 31. If you need an answer before this time, please let me know and I will see what I can do.

    Best regards,

    Heidi

  • Hi,

    Thanks for your patience in waiting for the reply. I will try to answer your questions below.

          1、What is the maximum stack? Where can I set it?

    There are two different types of overall stack sizes you need to set. One is for your overall application that the compiler needs to know and the other is for FreeRTOS kernel that you set in FreeRTOSConfig.h file. 

    1. If you are using SES, you can see the overall ROM and STACK sizes that the compiler needs to know to create the executable image.


    2. The BLE protocol stack (Softdevice) does not uses any RTOS and works as a baremetal. So as you can see in the image above  RAM_START and RAM_SIZE does not use the whole available RAM as the BLE protocol uses that reserved RAM (you can find more in the softdevice release notes about these numbers). The BLE task that was created in this example is the application task that works with the BLE events received from the softdevice. This BLE task as you can see in the SDK_17.0.2_d674dde\components\softdevice\common\nrf_sdh_freertos.c:nrf_sdh_freertos_init :NRF_BLE_FREERTOS_SDH_TASK_STACK reserves 256 bytes based on this example as softdevice_task is quite simple. But this can increase if you are doing more complex handling in this softdevice_task and using more stack. You should then increase configTOTAL_HEAP_SIZE in FreeRTOSConfig.h (Since FreeRTOS stack is created from RTOS heap) and then increase the softdevice_task stack size accordingly based on your application needs and handling of BLE events.

     

      2、How many stacks should be reserved for ble task?

     Atleast one task is recommend for handling BLE events as shown in the FreeRTOS examples (SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_hrs_freertos\main.c). You can ofcourse design this to have more tasks based on how complex your application handling on each BLE event. There is no clear answer for this, it is for your application architect to design.

     

    3、The stack used by my other projects to be migrated is shown in the figure below,How do I set the size of the stack for my project?

     Probably you are asking if you have enough HEAP from which these tasks could be created? If so you should then look into the configTOTAL_HEAP_SIZE to see if you have allocated enough FreeRTOS heap which could be used for allocating stack for your other tasks.

Related