We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Setup
Keil: uVision 5.17.0.0 ARM: LPC1768 A standard project with some UARTS and I2C "Use memory Layout form target" is checked (using the standard scatter file) "Use MicroLIB" is not checked
from startup_LPC17xx.s Heap_Size EQU 0x00002000
AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit
Problem Any call to malloc returns NULL, that is, the system can not allocate memory.
Why does not the mallco work, is my only options to 1) Use microLIB 2) Implement _init_alloc() and __rt_heap_extend() on my own
?
Regards Stefan
It works now as expected, it was all related to one of all of the added lines at the top of startup_LPC..
EXPORT __initial_sp EXPORT __heap_base EXPORT __heap_limit
If any of them, even if the program only have "EXPORT __initial_sp" (and not the other two) the heap dont get initalized. If none of them are exported then the runtime library will call __user_initial_stackheap as expected.
It is neccessary to export a new/seperate variabel if the stack top is going to be used somewhere else, like this
EXPORT __initial_stack_top Stack_Size EQU 0x00000800 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp __initial_stack_top
One interesting observation was that if the program had
EXPORT __initial_sp EXPORT __heap_base EXPORT __heap_limit The map file will contain __rtentry4.o(.ARM.Collect$$rtentry$$00000004) refers to sys_stackheap_outer.o(.text) for __user_setup_stackheap sys_stackheap_outer.o(.text) refers to startup_lpc17xx.o(.text) for __user_initial_stackheap But they was never called
Conclusive: Dont export any of __initial_sp, __heap_base or __heap_limit form the startup_XXXX.s