Program goes into an infinite loop upon new task creation

I’m trying to create a new task in a sensor class constructor but as soon as the task scheduler runs, it goes into a forever loop

  /* Loop forever */
  b exit_loop

when it’s not created, the program seems to run fine. What is it about this new task that might possibly be causing the program into an infinite loop?

The callstack goes like:

Unknown function at 0xFFFFFFFC
void prvCheckForValidListAndQueue()

I am ASSUMING exit_loop gets called if the program attempts to exit, either by calling exit or running off the end of the program. In the latter case it may be due to running out of heap memory. When you call vTaskStartScheduler() the kernel creates the idle task, and optionally the timer task. Each task requires a stack. The only time vTaskStartScheduler() should ever return is if there is insufficient heap memory remaining to allocate the stack of one or both of those tasks.

See the description of the Malloc Failed Hook function here:

Spot on. Just added vApplicationMallocFailedHook and it gets called.

So I added some prints to determine how much heap is being used by each task (3 so far each allocating 256 bytes which I randomly picked) via xPortGetFreeHeapSize() and I notice that before the allocation of the first task, heap size = 4000 bytes, and after the last task, the only remaining heap size is 600 bytes. And I guess that’s mostly used up by the idle task and the timer task after calling the scheduler?

How do I know if 256 bytes per task is sufficient or too much for my needs?

Best way is to look at the code that gets generated and figure out how much stack is really needed. One thing to watch out for is that stack size is specified in WORDS not BYTES.