Hi All,
I am using EFM32GG11 cpu and have problem with malloc function. It crashes on the first call.
I have specified stack and heap areas in the scatter file.
I would like to debug through malloc function. I am using the standart C library linked to my keil MDK 5 project,
How could i build c runtime and link it to my project?
Thanks,
Define "crashes"
Where does the processor end up?
If you have a Hard Fault you're touching some memory oddly. Check that the memory described to the linker matches the capabilities of the part.
Check how memory is arranged in the .MAP file.
Make sure your SystemInit() code enables clocks, external memories, etc.
Use FromELF to disassemble the .AXF file so you can play along with the debugger. You can step into code where you lack source, it is not that hard.
Pretty sure Keil's code is solid, so issue is likely with structures, or initialization.
Also shouldn't be hard to figure the linked-list implementation, and walk the heap structures.
Check structure alignment, CM4 will fault on unaligned access with LDRD,STRD
Hello,
Thanks for reply. I have checked that HardFauld occur due to read at 0xFFFFFFFF address. Somehow this address is calculated inside malloc function. I currently far from being able to walk in disassembly and check what happens with linked list.
I have some troubles with scatter file. I found an example scatter file without heap definition.
I have defined ARM_LIB_HEAP variable.
ARM_LIB_HEAP 0x2007F000 EMPTY HeapSize {
}
There is a
RW_IRAM1 0x20000158 0x0007EEA8 { ; RW data .ANY (+RW +ZI) }
region for RAM.
I have added another region for heap
RW_IRAM2 0x2007F000 0xC00 { ; RW data .ANY (+RW +ZI) }
Still Hard fault.
I would like to find out how C runtime library initialize it's internal variables for heap base?
Maybe some init function must be called before C runtime?
My systeminit function is called and clocks are initialized, without malloc cpu is working fine.
The Heap/Stack are more usually defined in startup.s
;******************************************************************************* ; ; Amount of memory (in bytes) allocated for Stack ; Tailor this value to your application needs ; <h> Stack Configuration ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> ; </h> Stack_Size EQU 0x0800 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp ; <h> Heap Configuration ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; </h> Heap_Size EQU 0x2000 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit ;*****************************************************************************
When using MicroLib, exporting
. EXPORT __initial_sp EXPORT __heap_base EXPORT __heap_limit
View all questions in Keil forum