Porting to atmega128 with xram+lwip+enc28j60

Hi all, I am working on create a port using freeRTOS 5.0.4, lwip 1.30 on the atmega128 with 32Kb of external sram, using a mcrochip enc28j60 module for the ethernet. The hardware works fine as I have had uip running on it, but unfortunately the delayed acks just made that not feasible solution for my project. I am using winavr 20080610 for the toolset.  I have started with the atmega323 port and have got the demo apps working correctly for the atmega128 (nothing special here). Since I have the extra 32Kb of external sram I moved the global vars and heap to utilise this, leaving the 4Kb of internal sram available for the stack.  This brought up an interesting point.  There are various posts in various forums stating that the stack should always be located in internal sram (performance and reliability).  But using the heap_2.c from freeRTOS will moved the stack into the external sram as it is alloacted using a global variable.  I therefore created heap_4.c that simply starts allocating ram from the start of the internal sram memory space at 0x0100.  Since nothing other than the original stack was ever going to touch this ram I figure it safe to use for this purpose.  I simply used heap_1.c as a starting point and changed pvPortMalloc to the following: void *pvPortMalloc( size_t xWantedSize ) { void *pvReturn = NULL;     /* Ensure that blocks are always aligned to the required number of bytes. */     #if portBYTE_ALIGNMENT != 1         if( xWantedSize & heapBYTE_ALIGNMENT_MASK )         {             /* Byte alignment required. */             xWantedSize += ( portBYTE_ALIGNMENT – ( xWantedSize & heapBYTE_ALIGNMENT_MASK ) );         }     #endif     vTaskSuspendAll();     {         /* Check there is enough room left for the allocation. */         if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&             ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte )    )/* Check for overflow. */         {             /* Return the next free byte then increment the index past this             block. */             pvReturn = (void*)(0x0100+xNextFreeByte);             xNextFreeByte += xWantedSize;                    }        }     xTaskResumeAll();     return pvReturn; } This allows configTOTAL_HEAP_SIZE to be set to something quite close to 4096 as long as you don’t have too many stack requirements before the schedular is started. I have also changed to use a makefile generated using mfile from winavr as I was having problems with the one from the atmega323 port. All of the above changes were tested on the demo apps and worked fine. I am however having major problems with getting the lwip code to work. I am using the code from the contrib port ARM9_STR91X_IAR to pinch the lwip/webserver code.  It compiles fine and appears to run correctly until to create the tasks.  But as soon as the schedular is started the atmega128 resets.  As I am new to both freeRTOS and lwip I am unsure as to were to start looking.  Does anyone have any ideas?  I suspect it is probably some sort of memory issue, but I am struggling.  If anyone has any idea of where to start looking it would be appreciated. I believe it to be within the lwip code that things go wrong.  The initialisation function for the enc28j60 never gets called. I have a jtagmk2 to assist in debugging although I am new to it and still learning how to use it to debug. Sorry about the long post, but any assistance would be much appreciated.  When I get this working I intend to make it available to the community. Cheers Simon