Need help running a simple FreeRTOS task on TM4C123GH6PM ( Tiva C Launchpad )

I basically have everything set up and the code runs without any errors but the task is not started in the following code:

#include "FreeRTOS.h"

#include "task.h"

uint32_t redTicks = 500U / 100U;


#define LED_RED 0x02;

static void vRTask(void *pvParameters);


int main(void)
{
    	// -- Initialization Code Start --
	SYSCTL->RCGCGPIO = 0x20U; // Enables Port F Clock
	GPIOF->DIR = 0x0EU;  // Sets Pins 1,2, and 3 as outputs
	GPIOF->DEN = 0x0EU; // Enables digital functions for pins 1,2, and 3
	SysTick->LOAD = 0x1869FF; // Systick Timer is 24 bits. -- Set to interrupt each 100ms
	SysTick->CTRL = 7;          // Enable Systick, Enable interrupt generation, CLKSOURCE = 1 [ System Clock ]
	// -- Initialization Code End --
	
	xTaskCreate(vRTask, /* Pointer To Task Implementation */
	"Task 1", /* Task Name */
	250, // Stack Depth in Words  */
	NULL,// Task Parameter  */ 
	1, // Task Priority 
	NULL ); // Task Handle
	
	xPortGetFreeHeapSize(); 
	
	
	vTaskStartScheduler();

	
	
	
	for ( ; ; );
	
	
}


static void vRTask(void *pvParameters)
{
	for ( ; ; )
	{
		GPIOF->DATA ^= LED_RED;
		vTaskDelay(1000);
	}
}

When I put a breakpoint at vRTask, It is never reached and this is because the following exception occurs in the tasks.c file:

    else
    {
        /* This line will only be reached if the kernel could not be started,
         * because there was not enough FreeRTOS heap to create the idle task
         * or the timer task. */
        configASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY );
    }

I tried changing the heapsize from the FreeRTOS config file but the result stayed the same… Can anyone help me find a solution?

Which memory manager (heap_1/2/3/4/5.c) do you use and what’s the heap size ?
See also FreeRTOS - Memory management options for the FreeRTOS small footprint, professional grade, real time kernel (scheduler)
What’s the return code of xTaskCreate ?
BTW The SysTick is by default configured internally by FreeRTOS. Or do you use it for another purpose (and use another timer for FreeRTOS) ?

I am using heap_1.c, The heap size is the default set in FreeRTOSConfig.h which is 4096. ( I tried increasing it to 2 * 4096 but it also didn’t work. )

I did not know that the SysTick is by default configured so I have removed the lines related to that, Thanks.

How can I get the return code of xTaskCreate?

Edit : If it helps, The code does reach vTaskStartScheduler(); → Then it goes to the exception mentioned in the original post.

The FreeRTOS API is very well documented e.g. This page describes the RTOS xTaskCreate() FreeRTOS API function which is part of the RTOS task control API. FreeRTOS is a professional grade, small footprint, open source RTOS for microcontrollers.
including return codes and examples. 4096 bytes heap is pretty small but could be sufficient for your initial test.
I’d also recommend to define configASSERT and enable stack checking during development (once you get your task(s) running).

Alright I used the documentation linked, The return code of xTaskCreate is 1.

Then it repeats a similar process where it goes to the vTaskStartScheduler(); → Then it goes to the exception mentioned in the post.

Here is my current code :

#include "tm4c123gh6pm.h"

#include "FreeRTOS.h"

#include "task.h"
#include <stddef.h> // for NULL


#define LED_RED 0x02;

static void vRTask(void *pvParameters);
void vOtherFunction(void);


void vOtherFunction( void )
{
BaseType_t xReturned;
TaskHandle_t xHandle = NULL;


    xReturned = xTaskCreate(vRTask, /* Pointer To Task Implementation */
	"Task 1", /* Task Name */
	250, // Stack Depth in Words  */
	NULL,// Task Parameter  */ 
	1, // Task Priority 
	NULL ); // Task Handle

    if( xReturned == pdPASS )
    {
        /* The task was created.  Use the task's handle to delete the task. */
        vTaskDelete( xHandle );
    }
}


int main(void)
{
    // -- Initialization Code Start --
	SYSCTL->RCGCGPIO = 0x20U; // Enables Port F Clock
	GPIOF->DIR = 0x0EU;  // Sets Pins 1,2, and 3 as outputs
	GPIOF->DEN = 0x0EU; // Enables digital functions for pins 1,2, and 3
	// -- Initialization Code End --
	
	vOtherFunction();
	
	
	vTaskStartScheduler(); // Starts The Task

	for ( ; ; ); // Never Reached
	
	
}


static void vRTask(void *pvParameters)
{
	for ( ; ; )
	{
		GPIOF->DATA ^= LED_RED;
		vTaskDelay(1000); // Delays The Task by 1000ms
	}
}

My Professor actually temporarily fixed this issue by giving me a preprocessor line to insert in the project settings but I can’t remember it at the moment ( perhaps it fiddled with the heap size? ) and sadly I can’t contact him currently.

what is the idea behind deleting a null task handle?

I don’t know to be honest… I just followed the code from the documentation linked above.

well, I don’ know how that code made it into the docs, but it should be removed from there asap. Complete rubbish. Since you happen not to use xHandle, it shouldn’t make a difference, but if you had copied it 1:1, it would necessarily have broken…

Well, the example code is just a demo how the calls are used including the usage of the valid task handle if the task creation was successful to delete a task. The example in itself makes no sense to be used in a real application. I’m sure that gets clear if you think about the example code a little bit.
Good luck with your homework and have fun experimenting with FreeRTOS :+1:

In the docs, the handle is passed to the 6th parameter of xTaskCreate, and is thus set to the task handle.

vTaskStartScheduler creates the idle and timer tasks (see FreeRTOS/tasks.c at a5402eb0bd608531ceb504cecb0fde59ea32dc21 · orientlu/FreeRTOS · GitHub).

If you are hitting the assert, likely one of those allocations is failing. You could increase the heap size further or try using static allocations for those tasks.

I’d like to add that with
#define configUSE_TIMERS 0 in your FreeRTOSConfig.h
the timer task can be omitted if you don’t need software timers to save memory / heap space.

yes, I know. It’s even worse because in that case, a running task is deleted which is very bad practice as we point out at least once a week on this forum.