cancel
Showing results for 
Search instead for 
Did you mean: 

Startup file heap size for using malloc()

bhushan_shanthi
Associate II
Posted on April 12, 2007 at 11:15

Startup file heap size for using malloc()

4 REPLIES 4
bhushan_shanthi
Associate II
Posted on May 17, 2011 at 09:41

Hi,

I am using the attached startup file in my application. In order to use malloc() function changed:

Heap_Size EQU 0x00000000

to

Heap_Size EQU 0x00004000

in the startup file. I was able to build application and run it successfully. When I add modules into the application, the code builds fine and am able to flash it. However, when I run the debugger it jumps to Dabt_handler every time.

Could you please have a look into the startup file and let me know where I am not properly congifuring the file, is it a case of not enough heap space?.

I am using MCBSTR9 board with STR912FW44(it has 96kB RAM) with Keil compiler.

Thanks in advance.

Regards,

Vasisht

bhushan_shanthi
Associate II
Posted on May 17, 2011 at 09:41

Hi Zouh,

Thanks for the reply and the example. The startup file you posted works well with my application. I started increasing the Heap_Size and the maximum value is 0x7200 (29184 bytes) for the application to run properly. Any value of Heap_size greater than this will result in program jumping to Abort_Handler.

I observe that the difference in the startup file you had posted corresponding to heap and stack sizes is that you have reduced:

IRQ_Stack_Size EQU 0x00000400 to IRQ_Stack_Size EQU 0x00000100

Since the startup file uses two region memory for stack and heap allocation, from my understanding:

__user_initial_stackheap

LDR R0, = Heap_Mem

LDR R1, =(Stack_Mem + USR_Stack_Size)

LDR R2, = (Heap_Mem + Heap_Size)

LDR R3, = Stack_Mem

R0 and R2 set the boundary for the heap while R1 and R3 set the same for the stack.

I am wondering how a reduction in 768 bytes in IRQ_Stack_Size (0x400 to 0x100) is resulting in increase of heap size from 0x4000 to 0x7200 (12800 bytes).

Further, would 29184 bytes be the maximum available heap, out of 96kB of RAM?

Thanks again for the example.

Regards,

Vasisht.

Posted on May 17, 2011 at 09:41

Hi Vasisht,

did you check the linker allocation table for your

project? there should be someting like *.scf for the keil.

bhushan_shanthi
Associate II
Posted on May 17, 2011 at 09:41

Hi stevejamal,

Sorry for the delay in replying. .sct file in keil is the scatter loading file. .map file gives detailed information about the memory map. On first glance, I didnt find anything out of normal in it, I am sure the issue is around the stack and heap allocation (either not enough memory or overlapping). I will try to use scatter loading to allocate separate locations for stack and heap.

Regards,

Vasisht.