| Latest News Items: FAT file system released - Tick suppression demo'ed SAM4L MCU & RX100 MCUs - embTCP released for PIC32 |
|
|||||||||||||||||||||||||||||||||||||||||
FreeRTOS FAQ - Memory Usage and Boot Times
How much RAM does FreeRTOS use? How much RAM does FreeRTOS use? This depends on your application. Below is a guide based on:
Note these figures are much lower for 8 and 16 bit architectures! Why does my compiler tell me FreeRTOS is consuming all the available RAM? Two of the example memory allocation schemes supplied with FreeRTOS allocate memory from a statically allocated array that is dimensioned by the configTOTAL_HEAP_SIZE constant in FreeRTOSConfig.h. These are just normal statically allocated arrays, and therefore appear in the RAM usage figures provided by many tool chains. The tool chain is in effect showing the heap as consumed RAM, even though at that point the heap is completely free as no memory has actually been allocated. C applications require some RAM for things like static variables, buffers, etc. but will rarely use all the RAM available on a microcontroller. Many of the FreeRTOS demo applications dimension the heap to use up all the RAM that is left over, making it appear as if the application is using all the RAM available. Why do queues use that much RAM? Event management is built into the queue functionality. This means the queue data structures contain all the RAM that other RTOS systems sometimes allocate separately. There is no concept of an event control block within FreeRTOS. How much ROM/Flash does FreeRTOS use? This depends on your compiler, architecture, and RTOS kernel configuration. The RTOS kernel itself required about 5 to 10 KBytes of ROM space when using the same configuration as stated for the FAQ "How much RAM does FreeRTOS use?". How can I reduce the amount of RAM used?
Why does my compiler tell me FreeRTOS is using much more ROM than you claim it requires? The quoted ROM/Flash footprint figures are genuine. If you write a tiny FreeRTOS test program and it appears to consume more ROM than expected then it is probably because of the libraries that are being included in your build, not because of FreeRTOS. In particular, GCC string handling and any floating point library is going to bloat your code. FreeRTOS includes a very cut down open source implementation of many string handling functions in a file called printf-stdarg.c. Including this in your project can greatly reduce both the amount of ROM used by the build, and the size of the stack required to be allocated to any task making a string handling library call (sprintf() for example). Note that printf-stdarg.c is open source, but not covered by the FreeRTOS license. Ensure you are happy with the license conditions stated in the file itself before use. Also, most linkers will remove unused code by default, but the GNU linker will only remove unused code if you explicitly tell it to. Check the output .map file to find exactly how ROM/Flash is being used. How is RAM allocated to tasks? Two calls to pvPortMalloc() are made when a task is created. The first allocates the task control block, the second allocates the task stack. The stack used by main() is not used by tasks, but (depending on the port) may be used by interrupts. Please read the memory configuration section of the API documentation for details of the allocation scheme. How is RAM allocated to queues? To create a queue the RTOS kernel makes two calls to pvPortMalloc(). The first allocates the queue structure, the second the queue storage area (the size of which is a parameter to xQueueCreate()). How big should the stack be? This is completely application dependent, and not always easy to calculate. It depends on the function call depth, number of local variables allocated, number of parameters in function calls made, etc. The stack must always be large enough to contain the execution context (all the processor registers). The FreeRTOS download contains a demo application for each port. A task created using that port must not be allocated a stack size that is lower than the value of configMINIMAL_STACK_SIZE used in the demo application. The RTOS kernel itself only uses configMINIMAL_STACK_SIZE to set the size of the stack used by the idle task. Tasks that allocate more variables than the idle task, or have a larger function call nesting depth than the idle task, will require a larger stack. The stack of each task is filled with 0xa5 bytes upon creation which allows the high water mark to be viewed using suitable debugging tools, and obtained using the uxTaskGetStackHighWaterMark() API function. The RTOS kernel can also be built to include stack overflow detection. How long does FreeRTOS take to boot? FreeRTOS, OpenRTOS and in most cases SafeRTOS are supplied as source code for static linking into the users application. The build process therefore results in a single executable binary image. Typically such an image will include a C start up routine to set up the C run time environment, before calling main() to execute the users application. The interrupt vector table will also be statically configured and included at a predetermined location within the same binary. The table below provides an indication of the sequence of processing booting such a system will require, along with some guidance on the time required for this processing to complete. Note that any numbers provided are indicative only and realistic. Actual times achievable will depend on the architecture being used, the clock frequencies configured, and the configuration of the memory interface.
Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2013 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. |
|||||||||||||||||||||||||||||||||||||||||