malloc: out of memory issue
Hello,
I experience a very annoying malloc problem with my STM32F103 (Cortex M3).
Here are the software things I have:
- gcc-arm-
- linker script based on gcc-arm-embedded examples (contains text, data, bss, heap and dummy_stack sections). I use the toolchain libc.
- startup file based on gcc-arm-embedded, +additional peripheral interrupt handler definitions
If I do too much malloc calls (let's say, 1000 calls * 400 bytes each), the system finally ends in Hardfault_Handler, instead of malloc calls just returning 0.
I think the _sbrk used is in the newlib file "mallocr.c".Tracing the execution shows the _sbrk function always return a growing value of the end of heap. It doesn't seem to successfully check the stack/heap overlap. So the end of the heap grows and go above the stack: hardfault!
(BTW, why is the sp register used in this check, and not the StackLimit ?)
Can you please tell me if it does work on your device, so that I can know I have done something wrong in my linker script or something?
Best Regards
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Emeric POUPON for more information if necessary.