[En-Nut-Discussion] How to determin size of RAM
Ulrich Prinz
uprinz2 at netscape.net
Sun Aug 22 20:14:56 CEST 2010
Hi!
Is there someone who knows how to figure out the RAM memory size
automatically?
For configuration of Nut/OS I need the available Heap. The start of the
heap is pretty easy, as it is behind the last var in .bss segment or
behind the stacks. For convenience a __heap_start token is added.
Fine, but how to find out about the end of the RAM?
Existing solution is to set NUT_MEMSTART and NUT_MEMSIZE manually in
nutconf. If you omit one of them, calculation goes wrong. Dangerous!
With this piece of code the initial calculation for the heap is done:
/*!
* \brief Last memory address.
*/
#define NUTMEM_END (uptr_t)(NUTMEM_START + NUTMEM_SIZE - 1U)
extern void *__heap_start;
#define HEAP_START &__heap_start
#define HEAP_SIZE ((uptr_t) (NUTMEM_END - 256 - (uptr_t) (&__heap_start)))
To do it more automatically I have the following in my linker file:
MEMORY
{
FLASH0 (rx) : ORIGIN = 0x00000000, LENGTH = 256K
SRAM0 (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}
....
.bss :
{
PROVIDE (_sbss = .);
*(.bss)
*(COMMON)
. = ALIGN(4);
PROVIDE (_ebss = .);
. += 0x400;
PROVIDE (__exp_stack = .);
. += 0x400;
PROVIDE (_estack = .);
PROVIDE (__heap_start = .);
} > SRAM0
So adding "extern void *__heap_start;" to nutinit.c is the first part of
the action. But how to figure out the size between this and the end of
the RAM? Is there such a thing like a variable filler to declare
__heap_end or something to calculate something like
origin+size-__heap_start?
Best regards
Ulrich
More information about the En-Nut-Discussion
mailing list