malloc failure

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

malloc failure

1,969 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lifejoker on Mon Mar 10 01:38:57 MST 2014
hi,i download lpcopen_2_09_keil_iar_keil_mcb_4357 from here, and try to debug the project Freertos_tcpecho-iflash_keil_mcb_4357.
i use LPC4357 as the main CPU as the example, and also use DP83848 PHY. But everytime when it ran to
sys_thread_new("receive_thread", vPacketReceiveTask, netif->state,
   DEFAULT_THREAD_STACKSIZE, tskRECPKT_PRIORITY);
in lpc18xx_43xx_emac.c, there was a malloc mistake and went directly into vApplicationMallocFailedHook().

it is my first time to use freertos and Lpc4357, i have no idea what happend.
what should i do ?
Thanks
标签 (1)
0 项奖励
回复
5 回复数

1,812 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lifejoker on Thu May 08 23:44:44 MST 2014
Thanks, I am using heap2.c now.it works well.
it happend because i was using freeRTOS+LWIP, which both need big space.but the ram I choosed was just 40K.
I set LWIP and freeRTOS to different RAM sections, not it is fine .
But i still want to use external SDRAM at the beginning of SystemInit, so i guess i need assembly code for clock and SDRAM initiation.
anywhere i could get it?
Thanks again.
0 项奖励
回复

1,812 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MagnusFogelberg on Thu May 08 07:18:34 MST 2014
Hi,
I think a know what the problem is.
You say you are using heap_3 and heap_3 is using the C library malloc.
When the malloc is performed it is testing if the stack and the heap do not overwrite each other.
If your code is running in a thread you will have the stack defined for your thread and it will be in your thread context.
As you know stack is allocating top -> down and heap is bottom -> up. malloc will recognise an overwrite of the heap if the address is greater than the stack address.
Now when you are running in a thread context the stack pointer is actually a allocation of the heap done when the thread was created. Any malloc of the heap done within a thread would fail because the stack pointer is lower than the heap pointer (if not a free block is found below the thread context). This is the case when using heap_3 model. Depending on your system etc. you could easily change to heap_2 model or check out the link below.
http://www.lpcware.com/content/faq/malloc-failure-using-freertos-heap3c-lpcxpresso-tool-chain

Hope this makes sense
Regards,
Magnus
0 项奖励
回复

1,812 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lifejoker on Mon Mar 10 19:45:23 MST 2014
i set the heap bigger enough, and it works. thanks again.
0 项奖励
回复

1,812 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lifejoker on Mon Mar 10 18:28:30 MST 2014
thanks for reply.
i checked the heap configuration inside applications\lpc18xx_43xx\tool_configs\iar_linker_scripts\lpc18xx_43xx_iflash_heap.icf.
, it is 0x2000, and i tried 0x3000, the problem was still there .
I am using the heap_3. where is the main heap malloc ?
0 项奖励
回复

1,812 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sundarapandian on Mon Mar 10 16:54:45 MST 2014
Make sure you have allocated enough heap.

For IAR lwip projects Heap is allocated inside applications\lpc18xx_43xx\tool_configs\iar_linker_scripts\lpc18xx_43xx_iflash_heap.icf.
For Keil projects it is allocated inside applications\lpc18xx_43xx\examples\lwip\startup_code\keil_startup_lpc18xx43xx.s
0 项奖励
回复