default malloc behavior in MCUXpresso SDK example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

default malloc behavior in MCUXpresso SDK example

Jump to solution
2,083 Views
yf2
Contributor III

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

 

 

 

Tags (1)
0 Kudos
Reply
1 Solution
2,046 Views
jingpan
NXP TechSupport
NXP TechSupport

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

View solution in original post

0 Kudos
Reply
4 Replies
2,072 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi @yf2 ,

You can set heap size at here, by right click the project and select Properties.

jingpan_0-1662366147108.png

 

Regards,

Jing

 

0 Kudos
Reply
2,062 Views
yf2
Contributor III

@jingpan 

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

 

 

 

0 Kudos
Reply
2,047 Views
jingpan
NXP TechSupport
NXP TechSupport

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

0 Kudos
Reply
1,974 Views
yf2
Contributor III

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

 

 

0 Kudos
Reply