Tiva C TM4C123 FreeRTOS code with Queue not working

Good day. I decided to run a basic FreeRTOS program on the TM4C123 board. vTask1 is supposed to put the variable ‘count’ into a queue (myqueue) while vTask2 is supposed to read the data from the queue
and print the result on console using the uartstdio utility function UARTprintf. The code doesn’t print anything on the serial terminal and I can’t pinpoint the fault as the same code works on an ESP32.

This is the code:

#include <stdbool.h>
#include <stdint.h>
#include “inc/hw_gpio.h”
#include “inc/hw_memmap.h”
#include “inc/hw_types.h”
#include “driverlib/gpio.h”
#include “driverlib/pin_map.h”
#include “driverlib/rom.h”
#include “driverlib/rom_map.h”
#include “driverlib/sysctl.h”
#include “driverlib/uart.h”
#include “utils/uartstdio.h”
#include “utils/ustdlib.h”
#include “FreeRTOS.h”
#include “task.h”
#include “queue.h”

/*

  • FreeRTOS Queue Management

*/
TaskHandle_t task1Handle = NULL;
TaskHandle_t task2Handle = NULL;

QueueHandle_t myQueue;

uint32_t SystemCoreClock = 16000000;
void ConfigureUART(void);

void vTask1(void *pvParameters){

int count = 5;
myQueue = xQueueCreate(5, sizeof(int));
for (;;){
	
	if(uxQueueMessagesWaiting(myQueue) == 0){
		xQueueSend(myQueue, &count, pdMS_TO_TICKS(5));
	}
}

}

void vTask2(void *pvParameters){

int receive;
for (;;){
	
	if(uxQueueMessagesWaiting(myQueue) != 0){
		if(xQueueReceive(myQueue, &receive, pdMS_TO_TICKS(10))){
			UARTprintf("data received: %d\n",receive);
		}
	}
}

}

int main()
{

ConfigureUART();
xTaskCreate(vTask1, "Task 1", 1024, NULL, 1, &task1Handle);
xTaskCreate(vTask2, "Task 2", 1024, NULL, 1, &task2Handle);

// Startup of the FreeRTOS scheduler.  The program should block here.  
vTaskStartScheduler();
for (;;);

}

void
ConfigureUART(void)
{
/*
Configure the UART and its pins. This must be called before UARTprintf().
*/

//
// Enable the GPIO Peripheral used by the UART.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable UART0
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
MAP_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);

//
// Configure GPIO Pins for UART mode.
//
MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, SystemCoreClock);

}

Can you verify that the systick and scheduler are running ?
Maybe by just printing test output with a vTaskDelay if you have no debugger at hand.

I just did as you said and I noticed the systick wasn’t running. I then modified the xTaskCreate() function’s last parameter. Instead of &task1Handle and &task2Handle, I just used NULL and now its working. Thanks.

Although I have a question, what is the implication of using &taskHandle, it didn’t work for this program but it worked for some other programs I’ve written.

That‘s strange… your original code is correct and also the task handle argument should be completely unrelated. I afraid there is something else not working properly.
So better check the return code of xTaskCreate and enable the various FreeRTOS debug flags (configASSERT, configCHECK_FOR_STACK_OVERFLOW, configUSE_MALLOC_FAILED_HOOK etc. in FreeRTOSConfig.h) to hopefully get an idea what’s going wrong.

I’ve retried the original code and it works. The xTaskCreate() returns pdPASS. I’m guessing the issue was with Keil uVision 5.