default malloc behavior in MCUXpresso SDK example

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

default malloc behavior in MCUXpresso SDK example

跳至解决方案
2,082 次查看
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

 

 

 

标记 (1)
0 项奖励
回复
1 解答
2,045 次查看
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 项奖励
回复
4 回复数
2,071 次查看
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 项奖励
回复
2,061 次查看
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 项奖励
回复
2,046 次查看
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 项奖励
回复
1,973 次查看
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 项奖励
回复