AnsweredAssumed Answered

Trouble configuring heap

Question asked by SCOTT MILLER on Jan 28, 2017
Latest reply on Mar 10, 2017 by SCOTT MILLER

I've got a CodeWarrior 10.7 project for a K22F that needs more heap space.  I very rarely make any serious use of the heap in embedded projects so I haven't had cause to mess with it before and I'm a little confused.  I need to enlarge the heap and relocate it to SRAM_U but I'm not having much luck.

 

__heap_size is set properly in the linker .ld file.  Changing it has no effect.  Removing it has no effect.  I've relocated __heap_addr into SRAM_U and the map file shows the symbol is at the expected address above 0x2000 0000, but it's still allocating from SRAM_L.  As far as I can tell it seems to be starting at the .end symbol.  Putting a bit of padding before .end shifts it up by that amount.

 

I've been through the EWL docs.  I've rebuilt the libraries with _EMBEDDED_WARRIOR_MALLOC = 1, and it *looks* like it's using the expected allocator.  The EWL docs mention a few symbols required for the allocator, but they don't show up in my map file, which makes me suspect it's either not set up right or I'm looking at documentation for the wrong thing.

 

The __heap_size symbol only seems to affect the heap+stack reservation, which just throws an error if there's not enough space between .end and SP_INIT.

 

stack_safety also seems to be ignored, and I think that's causing my more immediate problem - I've got a malloc() call causing a hardfault rather than returning NULL and I think it's because the heap (which has failed to be relocated) and the stack are colliding.  This is not good.  I'm only making significant use of the heap for interactive functions where it's OK to fail and tell the user there's not enough memory, but I can't do that if malloc() isn't allowing for a minimum separation from the stack.  If I can get it into SRAM_U, with the stack in SRAM_L, then I won't have to worry about the two colliding and I can make sure that nothing is above the heap.  I just can't figure out how to relocate it.

 

What am I missing?

 

Thanks,

 

Scott

Outcomes