Init with lwIP causes memory overflow

cstrahm wrote on Saturday, December 20, 2008:

I’m trying to use FreeRTOS with an ARM7 LPC2468 (64K RAM) and keep running into mem problems.  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().  I am using heap_2.c

So where do I adjust mem useage at?  I’ve tried configTOTAL_HEAP_SIZE, the Stack alloc in the .ld file, etc.  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.

rtel wrote on Saturday, December 20, 2008:

lwIP will create tasks using the sys_thread_new() function.  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.  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().  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().  The standard GCC sprintf() is particularly bad.  Several of the FreeRTOS demos include a file called printf-stdarg.c which provides smaller implementations of the sprintf() family of functions.  Using the smaller version allows you to allocate much smaller stacks to the lwIP tasks.


cstrahm wrote on Sunday, December 21, 2008:

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.  When I set to 12K app won’t run at all, going up by 2K inc to 32K compiler refuses says RAM is full.  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().  Do I need more threads or something else for this addon?  I really don’t see why the simple ping code would change much.

- I found a printf-stdarg.c in the AVR32 demo.  I guess it will work for this ARM7.  It compiles.  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.  Do I need to do something else?

Still no progress, Chris.

- In the lwIPopts.h file the settings are:

#define lwipBASIC_SERVER_STACK_SIZE     250

#define TCPIP_THREAD_NAME               "lwIP"
#define TCPIP_THREAD_STACKSIZE          600
#define TCPIP_THREAD_PRIO               3

#define DEFAULT_THREAD_PRIO             1

#define LWIP_DEBUG                      1
#define DBG_TYPES_ON                    0xff
#define MEM_SIZE                        2000
#define MEMP_NUM_PBUF                   20
#define PBUF_POOL_SIZE                  4
#define PBUF_POOL_BUFSIZE               1500

- In the FreeRTOSconfig.h file the settings are:

#define configUSE_PREEMPTION        1
#define configUSE_IDLE_HOOK            1
#define configUSE_TICK_HOOK            0
#define configCPU_CLOCK_HZ            ( ( unsigned portLONG ) 72000000 )   
#define configTICK_RATE_HZ            ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES        ( ( unsigned portBASE_TYPE ) 5 )
#define configMINIMAL_STACK_SIZE    ( ( unsigned portSHORT ) 128 )
#define configTOTAL_HEAP_SIZE        ( ( size_t ) ( 24 * 1024 ) )   
#define configMAX_TASK_NAME_LEN        ( 16 )
#define configUSE_TRACE_FACILITY    1
#define configUSE_16_BIT_TICKS        0
#define configIDLE_SHOULD_YIELD        1
#define configUSE_MUTEXES           1

cstrahm wrote on Sunday, December 21, 2008:

Well I just got some results.  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().  The app is running. So something is wrong with what the ping function setup is doing.  I will investigate this further.