# Init with lwIP causes memory overflow

**URL:** <https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382>\
**Category:** Kernel\
**Created:** [December 20, 2008, 1:58pm UTC](https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382 "2008-12-20T13:58:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 20, 2008, 1:58pm UTC](https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382/1 "2008-12-20T13:58:39Z")

</div>

**[cstrahm](https://sourceforge.net/u/cstrahm/)** wrote on [Saturday, December 20, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ef4fac2e/#8254):

I’m trying to use FreeRTOS with an ARM7 LPC2468 (64K RAM) and keep running into mem problems.&nbsp; I have FreeRTOS running with the rest of my code fine, but when I try to add my lwIP init I get traps into vApplicationStackOverflowHook().&nbsp; I am using heap\_2.c

So where do I adjust mem useage at?&nbsp; I’ve tried configTOTAL\_HEAP\_SIZE, the Stack alloc in the .ld file, etc.&nbsp; Between all the various places that alloc mem in FreeRTOS and lwIP, I’m more than slightly confused as to where to make the adjustments.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 20, 2008, 2:12pm UTC](https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382/2 "2008-12-20T14:12:45Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Saturday, December 20, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ef4fac2e/#8254/677b):

lwIP will create tasks using the sys\_thread\_new() function.&nbsp; Take a look at this function in the file Demo\lwIP\_Demo\_Rowley\_ARM7\lwip-1.1.0\contrib\port\FreeRTOS\AT91SAM7X\sys\_arch.c.&nbsp; This is a very old implementation, and completely specific to the this particular demo (not generic in any way), but it shows where the stack sizes used by this demo are defined.

lwipTCP\_STACK\_SIZE and lwipBASIC\_SERVER\_STACK\_SIZE are defined at the top of the file then used in sys\_thread\_new().&nbsp; Later demos define these stack sizes in the FreeRTOSConfig.h file.

Note that depending on what you are doing and the compiler you are using, lots of the lwIP files can potentially use a lot of stack as they make use of things such as sprintf().&nbsp; The standard GCC sprintf() is particularly bad.&nbsp; Several of the FreeRTOS demos include a file called printf-stdarg.c which provides smaller implementations of the sprintf() family of functions.&nbsp; Using the smaller version allows you to allocate much smaller stacks to the lwIP tasks.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 21, 2008, 12:40am UTC](https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382/3 "2008-12-21T00:40:27Z")

</div>

**[cstrahm](https://sourceforge.net/u/cstrahm/)** wrote on [Sunday, December 21, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ef4fac2e/#8254/ae48):

I’m using lwIP 1.3 and GCC.

- I looked at your AT91SAM7 demo and your FreeRTOSconfig is pretty much about the same. None of the params look that much different.

- Does lwIP allocate RAM within the configTOTAL\_HEAP\_SIZE, or does it need it’s own RAM outside FreeRTOS for memp, pbufs, etc. ?

- The org configTOTAL\_HEAP\_SIZE = 24K.&nbsp; When I set to 12K app won’t run at all, going up by 2K inc to 32K compiler refuses says RAM is full.&nbsp; No matter what the setting, overflow of your stack remains.

- I am also using the ping.c/ping.h file addon with lwIP, and often see the “ping-thread” is the task that is overflow’d in vApplicationStackOverflowHook().&nbsp; Do I need more threads or something else for this addon?&nbsp; I really don’t see why the simple ping code would change much.

- I found a printf-stdarg.c in the AVR32 demo.&nbsp; I guess it will work for this ARM7.&nbsp; It compiles.&nbsp; When I don’t have it in the makefile, the map file shows ‘sprintf’ as coming from the usual libg.a . When I add printf-stdarg.c to my makefile, the map file only shows ‘sprintf’ as in printf-stdarg.o . So I think that is right, but I still get your stack overflow the same.&nbsp; Do I need to do something else?

Still no progress, Chris.

- In the lwIPopts.h file the settings are:

#define lwipBASIC\_SERVER\_STACK\_SIZE&nbsp;&nbsp;&nbsp;&nbsp; 250

#define TCPIP\_THREAD\_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "lwIP"  
#define TCPIP\_THREAD\_STACKSIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 600  
#define TCPIP\_THREAD\_PRIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3

#define DEFAULT\_THREAD\_STACKSIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 200  
#define DEFAULT\_THREAD\_PRIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1

#define LWIP\_DEBUG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define DBG\_TYPES\_ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xff  
#define MEM\_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2000  
#define MEMP\_NUM\_PBUF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20  
#define PBUF\_POOL\_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4  
#define PBUF\_POOL\_BUFSIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1500

- In the FreeRTOSconfig.h file the settings are:

#define configUSE\_PREEMPTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define configUSE\_IDLE\_HOOK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define configUSE\_TICK\_HOOK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
#define configCPU\_CLOCK\_HZ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( unsigned portLONG ) 72000000 )&nbsp;&nbsp;&nbsp;  
#define configTICK\_RATE\_HZ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( portTickType ) 1000 )  
#define configMAX\_PRIORITIES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( unsigned portBASE\_TYPE ) 5 )  
#define configMINIMAL\_STACK\_SIZE&nbsp;&nbsp;&nbsp; ( ( unsigned portSHORT ) 128 )  
#define configTOTAL\_HEAP\_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( size\_t ) ( 24 \* 1024 ) )&nbsp;&nbsp;&nbsp;  
#define configMAX\_TASK\_NAME\_LEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( 16 )  
#define configUSE\_TRACE\_FACILITY&nbsp;&nbsp;&nbsp; 1  
#define configUSE\_16\_BIT\_TICKS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
#define configIDLE\_SHOULD\_YIELD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define configUSE\_MUTEXES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 21, 2008, 1:30am UTC](https://forums.freertos.org/t/init-with-lwip-causes-memory-overflow/5382/4 "2008-12-21T01:30:28Z")

</div>

**[cstrahm](https://sourceforge.net/u/cstrahm/)** wrote on [Sunday, December 21, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ef4fac2e/#8254/70ea):

Well I just got some results.&nbsp; I thought I would take out the “ping” files just to see if this would make a difference, and wow I didn’t get the trap into vApplicationStackOverflowHook().&nbsp; The app is running. So something is wrong with what the ping function setup is doing.&nbsp; I will investigate this further.
