PIC32MX795 & heap_3.c malloc/free

petermeier wrote on Monday, March 01, 2010:


i have two issues:

Issue 1:  I’ve experiencing a strange issue when using heap_3.c. I’ve decided to use heap_3.c for being compatible with the USB Stack provided by Microchip. For testing i have create one task which just shows the current tasks defined in the system and also created a vApplicationMallocFailedHook() function to see if iam running out of available memory.  My application task and the idle task will be created without any problems and even the scheduler runs as expected. But the sprintf() function used in vTaskList just returns an empty string. I have reserved 40kB heap memory by the linker and 0 bytes for the stack (as done in the demo application provided with FreeRTOS). Both tasks do not use more than 4 kBytes.

UINT8 recbuf;

void Task1(void * pvParameters)
  while(1) {

If iam using heap_1.c or heap_2.c sprintf is working as expected. Does someone has an idea what iam doing wrong?

Issue 2: If other functions use malloc/free (like the USB stack from Microchip). And if this stack is running within a task, shall i replace the malloc()/free() function by the thread safe functions pvPortMalloc/vPortFree?!

Thanks in advance for the help,

edwards3 wrote on Monday, March 01, 2010:

Cant help with your first problem, but for the second I would say yes if the functions are called from more than one task then convert to use pvPortMalloc and vPortFree. I think microchip have an application note on integrating their software with FreeRTOS that goes through these things.