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);
}