On PIC32MX using the standard "sys_arch.c" the procedure sys_sem_new is called and in this routine a semaphore is created by calling vSemaphoreCreateBinary which at some points call pvPortMalloc (allocating 0x4c bytes) and which at the end calls prvInsertBlockIntoFreeList This throws an exception and I end up in the _general_exception_handler.
I am trying to find a possible cause for this but as been unsuccessfull so far. Any tips what to look for here would be appreciated.
Can you confirm that prvHeapInit() is getting called the first time you call pvPortMalloc()? If there is something wrong in the startup code or linker script then it could be that the variable xHeapHasBeenInitialised is not being initialised to zero, which would prevent prvHeapInit() being called, which could cause a crash.
Also, do you have portBYTE_ALIGNMENT set to 4 (this is defined by the kernel in portmacro.h, so it should already be set to 4)?
>Can you confirm that prvHeapInit() is getting called the first time you call pvPortMalloc()?
Yes can confirm that.
>Also, do you have portBYTE_ALIGNMENT set to 4
yes.
btw I am using heap_2.c
I noticed that pxNewBlockLink->xBlockSize on line 220 of heap_2.c got a crazy value before the error. Its 0x0400FFAB. I will see if I can find the cause of this.
Yes I know. I have tried to increase it to 10K bytes but that does not help. Something takes a lot of memory here. The biggest taker is memp.o of lwip as far as I can see which also claims about 10K. I expected lwip to use less then 10K total. Hrm see if I can tweek it.
/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */ #define MEM_SIZE 2000