Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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 ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists