Dear support,
I am using MCUXpresso SDK v2.11 and ARMGCC toolchain with a rt1170-evk board.
I noticed the default heap size in my .elf file is only 1KB (learnt by arm-none-eabi-objdump command) , but my app can successfully malloc() 16KB.
So my question is how the malloc library figures out the correct heap size?
Regards,
yf2
已解决! 转到解答。
Hi @yf2 ,
I think this is because gcc malloc doesn't check if the operation will overflow. It is not recommend to use malloc in embedded system.
These is *.ld files in armgcc folder. It defines HEAP_SIZE and STACK_SIZE. You can modify them.
https://community.nxp.com/t5/i-MX-RT/Malloc-failed-in-RT1060-EVK-project-CSI-RGB565/m-p/819249
Regards,
Jing
Thanks for sharing the screenshot, but I am not using the MCUXpresso IDE.
I simply used $SDK/tools/cmake_tool_chain_files/ to build my program. It seems that the heap/stack sizes in the generated .elf file are very small but at runtime in main() the effective stack and heap sizes are much bigger as I can malloc() 16KB blocks and I can define 12KB stack variables.
I am just wondering where the magic happens?
Regards,
yf2
Hi @yf2 ,
I think this is because gcc malloc doesn't check if the operation will overflow. It is not recommend to use malloc in embedded system.
These is *.ld files in armgcc folder. It defines HEAP_SIZE and STACK_SIZE. You can modify them.
https://community.nxp.com/t5/i-MX-RT/Malloc-failed-in-RT1060-EVK-project-CSI-RGB565/m-p/819249
Regards,
Jing
Jing,
Yes I noticed HEAP_SIZE in armgcc/MIMXRT1176xxxxx_cm7_ram.ld file:
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
This reads to 1KB size in my test app.elf.
But this seems have no control for the "malloc()" function of armgcc as I can make bigger "malloc()" successfully. This is why I raised this ticket.
Now I guess that the malloc() implementation of ARMGCC may lacks respect to linker descriptor definitions thus I can make larger allocatons.
Regards,
yf2