[En-Nut-Discussion] Heap and external RAM

Marc Giger gigerstyle at gmx.ch
Sat Sep 9 14:11:47 CEST 2006


Hi Harald

On Sat, 09 Sep 2006 10:38:45 +0200
Harald Kipp <harald.kipp at egnite.de> wrote:

> 
> >I tried to modify (quick & dirty) the heap initialization to the
> >following:
> >
> >//add internal memory to heap
> >if ((u_short)NUTMEM_SIZE - 1 - (u_short) (&__heap_start) > 384) {
> >  NutHeapAdd(&__heap_start, (u_short) NUTMEM_SIZE - 
> > 1-(u_short)(&__heap_start));
> >}
> >//add external RAM to heap
> >u_short mst = NUTXMEM_START;
> >if ((u_short)NUTMEM_END - (u_short) (NUTXMEM_START) > 384) {
> >  NutHeapAdd(&mst, (u_short) NUTMEM_END - 256
> > -(u_short)(NUTXMEM_START));
> >}
> 
> Due to lack of time I'm not able to check your calculations
> right now. But it's not that easy. Note, that the compiler
> can't handle gaps as well, it will put all variables in .bss
> and .data by default and the linker will not be able to
> split these segments afterwards.

My consideration is as long as .data and .bss fits
into the internal memory there should be no problem, but I think I see
your point.

> 
> 
> 
> >I'm not sure what 384 (NUT_THREAD_IDLESTACK ?) and 256 stands for,
> >so I defined the same conditions. Now, if I print out
> >NutHeapAvailable I get 257 ?!
> >What am I doing wrong?
> 
> First make sure that your calculations above are correct.
> Then you may check the linker map file. Probably it would be
> a good idea to exclude the internal RAM from variable
> usage. You can still use it as heap memory.
> 
> The 384 will avoid adding too small fragments in the first
> place. Beside that, at that point the stack is still
> controlled by the compiler's runtime and is indeed located
> at the top of RAM (as the linker knows it). The 256 bytes
> spare allows this.
> 

To summarize my considerations with your answers I come to the
conclusion:

Add linker options to move .data and .bss to external memory at address
0x8000:

Wl,-Tdata=0x808000

Assign external Memory minus 256 to heap:
NutHeapAdd(&__heap_start, NUTMEM_END - 256 - &__heap_start);

Then assign the most internal memory to heap:
NutHeapAdd(0x0100, NUTMEM_SIZE - 0x0100);

Is this correct? Can I call NutHeapAdd multiple times for different
memory regions?

Thank you for your time 

Greetings

Marc



More information about the En-Nut-Discussion mailing list