FreeRTOS: Simple Queue program, values of Queue are not being printed on Serial Monitor

37 views Asked by At

I'm using FreeRTOS on the Adafruit HUZZAH32 – ESP32 Feather Board, and programming on the Arduino IDE.

The goal of this simple Queue program is to create a Queue, populate it sending values of an integer counter num (0, 1 , 2, ... ) into it until the the Queue is full.

This while printing into the Serial monitor the values that are on the Queue, if the Queue is full it'll print 'Queue full'.

// Use only core 1 
#if CONFIG_FREERTOS_UNICORE
  static const BaseType_t app_cpu = 0;
#else
  static const BaseType_t app_cpu = 1;
#endif

// Settings
static const uint8_t msg_queue_len = 5;

// Globals
static QueueHandle_t msg_queue;


// Task: wait for item and print it
void printMessages(void *parameters)
{
  int item;

  // Loop forever
  while(1)
  {
    
    // See if there's a message in the queue (do not block)
    if (xQueueReceive(msg_queue, (void *)&item, 0) == pdTRUE)
    {
      Serial.println(item);
    }

    // Wait before trying again
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

// main (runs as its own task with priority  1 on core 1)
void setup() 
{

  // Configure Serial
  Serial.begin(115200);

  // Wait a moment to start (so we don't miss Serial output)
  vTaskDelay(1000 / portTICK_PERIOD_MS);
  Serial.println();
  Serial.println("---FreeRTOS Heap Demo---");

  // Create queue
  msg_queue = xQueueCreate( msg_queue_len, sizeof(int) );

  // Start Serial receive task
  xTaskCreatePinnedToCore(printMessages,
                          "Print Message",
                          1024,
                          NULL,
                          1,
                          NULL,
                          app_cpu);

  vTaskDelete(NULL);
}

void loop() 
{
  static int num = 0;

  // Try to add item to queue for 10 ticks,  fail if queue is full
  if (xQueueSend(msg_queue, (void *)&num, 10) != pdTRUE)
  {
    Serial.println("Queue full");
  }
  num++;

  // Wait before trying again
  vTaskDelay(1000 / portTICK_PERIOD_MS);
}

Output:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4

---FreeRTOS Heap Demo---

Ideally I should get the following:

    ---FreeRTOS Heap Demo---
0
1
2
3
4
5
Queue full

I have been trying to understand why It's not printing any of the counter values for hours. Any help is greatly appreciated.

0

There are 0 answers