[En-Nut-Discussion] How to move the heap start address in Nut/OS?

Malte Marwedel m.marwedel at onlinehome.de
Wed Apr 8 11:23:51 CEST 2009

Harald Kipp schrieb:
> Malte Marwedel wrote:
>> I have a Arthernet board (with 512KB external memory), which has the
>> memory of the CLPD and RTL chipset mapped directly after the internal
>> RAM in the region 0x1100 to 0x14ff. 
>>From a comment in arch/avr/os/nutinit.c:
> "This had been messed up somehow. It's nice to have one continuous heap
> area, but we lost the ability to have systems with a gap between
> internal and external RAM."
>> As __heap_start is somehow defined
>> as 0x19f in my program, allocating heap results in overwriting the CLPD
>> and RTL memory, so that the tcps demo crashes after a first connect and
>> the httpd demo does not work at all.
>> I tried to find a way to set __heap_start to 0x1500 but failed, to do
>> so, becasue
>> a) I did not found out where __heap_start is initialized or even defined.
>> b) I tried to add __heap_start=(u_char *) 0x1500; in the NutCustomInit()
>> function, but this had no effect.
>> c) I tried to add it into the normal main function, but it did not work
>> either.
> This symbol is created by the linker and specified in the linker script.
> It can be overridden by a linker option in app/Makedefs.avr-gcc:
> -Wl,--defsym=main=0,--defsym=__heap_start=0x801500,-Map=$(PROJ).map,--cref
Thank you, but for some unknown reasons, the applications did not start 
after doing this.
But I discovered that Nut/OS 4.8 is now stable and it supports systems 
with a gap in the RAM again by calling  NutHeapAdd for each region.
In the file nut/arch/avr/os/nutinit.c I made the following changes:
In line 156, I replaced #ifdef NUTXMEM_SIZE by
#if defined(NUTXMEM_SIZE) && !defined(ARTHERNET1)
and in the NutInitHeap() function, I added
     /* Add external RAM */
     NutHeapAdd((u_char *)NUTXMEM_START, (u_short) NUTXMEM_SIZE - 32);
(I guess I could remove the -32 as the stack will stay in the internal RAM.)
This seems to work and does not loose the internal, faster, RAM for the 
heap. I hope I did not oversaw some unexpected side-effects this changes 
  could create.

As I had to do some more fixes in order to get my board working, where 
should I submit them?

Malte Marwedel

More information about the En-Nut-Discussion mailing list