Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


how does one determine enough stack is reserv

Posted by Rich Painter on July 5, 2008
I am running 5.0.0 with microchip C30 3.10 on a dspic33fj256.

I have set the freertos heap size to 18,000 bytes. I create 6 tasks with a total of 4K of stack specified.

I am getting address errors at times and stack errors at other times depending on the number of tasks I use. If I remove one task the errors go away. If I put that back and remove a different one the errors go away. If I change the stack sizes specified I can chase these around too.

How does one determine the heap size required for the rtos config in relation to those called out for all of the task creations?

If I have 18,000 bytes reserved and have speced out a total of, say 10K that should give my tasks plenty, then why does increasing the speced amount of stack on the task creates cause more address and stack errors?

Increasing stack for a task that may be suspect of running out should make it go away, not make it happen.

If I run any one task it will run without address or stack errors. Does this mean that I have given it enough stack alloc in the task creation? One would think so.

Where am I going wrong?

Could this be a microchip C30 problem that has been alluded to elsewhere?


RE: how does one determine enough stack is re

Posted by Rich Painter on July 5, 2008
I forgot to mention I am using the heap1 method.

Also, if when I specify the queue sizes and stack sizes and I exceed some limit then would I not be told with an error return during this queue and stack creation steps?


RE: how does one determine enough stack is re

Posted by Dave on July 5, 2008
When using heap_1 you need only check the xNextFreeByte variable within heap_1.c to see how much of the total heap space you have used. If after creating all your tasks and queues there is heap space left you can reduce the configTOTAL_HEAP_SIZE setting accordingly.

Calls to xTaskCreate() and xQueueCreate() return an error if there was not enough heap available for the create to complete.

Also TaskStartScheduler() will return if there is not enough heap to create the idle task. Its a good idea to put a while(1); at the end of main to catch TaskStartScheduler() returning unexpectedly.

Unfortunately the PIC24 stack grows up rather than the more conventional down so the uxTaskGetStackHighWaterMark() function does not work. You can always look at the stack in the memory window to see how much is unused as it is filled with 0xa5 when it is created. Or you could look at the implementation of uxTaskGetStackHighWaterMark() and change it to work for stacks that grow the wrong way.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner