default malloc behavior in MCUXpresso SDK example

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

default malloc behavior in MCUXpresso SDK example

ソリューションへジャンプ
1,202件の閲覧回数
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 解決策
1,165件の閲覧回数
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 返答(返信)
1,191件の閲覧回数
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 件の賞賛
1,181件の閲覧回数
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 件の賞賛
1,166件の閲覧回数
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,093件の閲覧回数
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 件の賞賛