Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Init with lwIP causes memory overflow

Posted by Chris Strahm on 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.

RE: Init with lwIP causes memory overflow

Posted by Richard on 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.


RE: Init with lwIP causes memory overflow

Posted by Chris Strahm on 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 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_PREEMPTION1
#define configUSE_IDLE_HOOK1
#define configUSE_TICK_HOOK0
#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_FACILITY1
#define configUSE_16_BIT_TICKS0
#define configIDLE_SHOULD_YIELD1
#define configUSE_MUTEXES 1

RE: Init with lwIP causes memory overflow

Posted by Chris Strahm on 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.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists