ESP-32 (FreeRTOS): The serial monitor prints unknown symbols (???) instead of a string

36 Views Asked by At

I'm trying to learn RTOS and am following the lecture in this video: https://www.youtube.com/watch?v=95yUbClyf3E

The program is just an example of Task scheduling. Where two tasks are made, the higher priority task preempts the lower priority task, and eventually the lower priority task is deleted so that only the higher priority task runs (program has 300 baud rate)

/* Task Scheduling */


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

// Pins 
const char msg[] = "Barkdadeer brig Arr booty rum.";

//Task handles
static TaskHandle_t task_1 = NULL;
static TaskHandle_t task_2 = NULL;

//*****************************************************************************

//Task print to Serial Terminal with lower priority
void startTask1(void *parameter){

  // Count number of characters in string
  int msg_len = strlen(msg);

  // Print strings to Terminal
  while (1){
    Serial.println();
    for (int i = 0; i < msg_len; i++){
      Serial.print(msg[i]);
    }

    Serial.println();
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    
  }
}

// Task: print to Serial Terminal with higher priority
void startTask2(void *parameter){
  while(1){
    Serial.print('*');
    vTaskDelay(100 / portTICK_PERIOD_MS);
  }
}

//************************************************

void setup(){

  // Configure Serial baud rate (go slow so we can watch the preemtion)
  Serial.begin(300);

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

  // Print self priority
  Serial.print("Setup and loop task running on core ");
  Serial.print(xPortGetCoreID());
  Serial.print(" with priority ");
  Serial.println(uxTaskPriorityGet(NULL));


  // Task to run forever
  xTaskCreatePinnedToCore(startTask1,
                          "Task 1",
                          1024,
                          NULL,
                          1,
                          &task_1,
                          app_cpu);

  // Task to run once with higher priority 
  xTaskCreatePinnedToCore(startTask2,
                          "Task 2",
                          1024,
                          NULL,
                          2,
                          &task_2,
                          app_cpu);
            

}


void loop() {

  // Suspend the higher proprity task for some intervals
  for (int i = 0; i < 3; i++){
    vTaskSuspend(task_2);
    vTaskDelay(2000 / portTICK_PERIOD_MS);
    vTaskResume(task_2);
    vTaskDelay(2000 / portTICK_PERIOD_MS);
  }

  // Delete the lower priority task

  if (task_1 != NULL) {    //checking if tasks is not NULL, and immedaitely setting it to NULL after deleting it 
    vTaskDelete(task_1);
    task_1 = NULL;
  }

}

The problem is that this is what I'm getting on the serial monitor, the strings is not printed:

enter image description here

Any help is appreciated.

0

There are 0 best solutions below