[En-Nut-Discussion] How to determin size of RAM

Ole Reinhardt ole.reinhardt at embedded-it.de
Mon Aug 23 11:20:21 CEST 2010


Hi Ulrich,

Sorry for doing a nearly full quote.. but I think this is needed to
understand the calculations.

> /*!
> * \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?

What's about:

__ram_start__           = ORIGIN(SRAM0);
__ram_size__            = LENGTH(SRAM0);
__ram_end__             = __ram_start__ + __ram_size__;

__heap_size__           = __ram_end__ - __heap_start;


Regards,

Ole Reinhardt

-- 

Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting

http://www.embedded-it.de

Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 



More information about the En-Nut-Discussion mailing list