pvPortMalloc returning NULL when there is no doubt I have enough memory (PSOC5LP)


I am very new to FreeRTOS and I keep getting an error on when I try to start the task scheduler (vTaskStartScheduler). pvPortMalloc is returning NULL which causes vApplicationMallocFailedHook to be called but I do not have one defined. I disabled this in the config but when it is disabled it compiles and programs but gets stuck in an infinite loop because I am out of heap space (The infinite loop is in Cm3Start.c).

I have tried allocating more heap space in the config (even though the only task being run turns an LED on so it shouldn’t need anywhere near 64k).

My main.c

#include "project.h"
#include "FreeRTOS.h"
#include "timers.h"
//#include "led_control.h"

void led_stuff( void *pvParams );

int main(void)
    CyGlobalIntEnable; /* Enable global interrupts. */
    TaskHandle_t xHandle = NULL;

    if (xTaskCreate(led_stuff, "led_flicker", ( uint16 ) 64, NULL, 1, &xHandle) == pdPASS) {


void led_stuff( void *pvParams ){
    ( void ) pvParams;

Thank you in advance for help and sorry for bad formatting.

How are you increasing the heap size? If you are using anything other than heap_3.c then the total heap size is set by configTOTAL_HEAP_SIZE and increasing heap anywhere else will just allocate memory to a heap that is not being used. If that is how you are increasing the heap size then perhaps your C startup code is not initialising variables correctly - try stepping into the calls to pvPortMalloc() in the debugger to see why it thinks it has run out of memory.

Also it might be better to use configMINIMAL_STACK_SIZE or more for the stack size of your task instead of literal value 64 except you‘re sure that it‘s ok.