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




Loading

Available memory - Am I understanding this correctly ?

Posted by lactose99 on August 31, 2014

Hello. I have been seeing some strange stuff in my software (debugger stepping wrong, variables passed to a function that land with the wrong value...). I wrote a quick function to see how much free memory is left, and it indicates I am out of memory.

Some info: -using RX600 CPU -using heap3.c -optimization = 0

My outOfMemory function assumes stack is at the top moving down, and heap is on the bottom moving up. Experimentally, this matches my observations. So is measuring from the bottom of the stack to the top of the heap a valid way of determining free memory ?

~~~~~~ void outOfMemoryCheck() { // address of this var used to find bottom of stack int32t testStackVar = 0; uint8t *pHeap = NULL;

define TESTALLOCATIONSIZE 8
// determine the top of the heap
pHeap = malloc(TEST_ALLOCATION_SIZE);

// available_memory is bottom_of_stack - top_of_heap
// stack bottom should never be below heap top
if((NULL == pHeap) || ((int32_t) pHeap > (int32_t) &testStackVar))
{
	// we are out of memory, loop here 
	while(1);
}	


free(pHeap);

} ~~~~~~

Thanks.


Available memory - Am I understanding this correctly ?

Posted by richard_damon on September 1, 2014

No, this is not true in FreeRTOS. Each tasks stack will be allocated from within the FreeRTOS heap (which with heap3.c is the C heap).

The primary issue is that you no longer have THE stack, but each task has their own stack.


Available memory - Am I understanding this correctly ?

Posted by lactose99 on September 1, 2014

Wow, thanks for the quick response. My apologies, I did not qualify that I am calling this outOfMemoryCheck function from a comm sci TX interrupt. In that case, I believe I am looking at the system stack.

In that case, I can assume that stack bottom should never be below heap top. Correct ?


Available memory - Am I understanding this correctly ?

Posted by richard_damon on September 1, 2014

It depend on the port, some will use the starting stack for the interrupt routines, some don't.

Best is to check your linker map and the addresses that are being reported.


[ 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