UART Receive and Transmit Using FreeRTOS, Queue and Semaphore

hi,

i’m trying to receive string from computer then transmit to another device by using freertos. when i start on proteus, i only see one message although i’m sending different things. here is my code and screenshot:

int main()
{
  uart_start();
  uart_sendstr(uart0, "hello, i'm a transmitter\n\r");
  if ( xSerialSemaphore == NULL )  // Check to confirm that the Serial Semaphore has not already been created.
  {
    xSerialSemaphore = xSemaphoreCreateMutex();  // Create a mutex semaphore we will use to manage the Serial Port
    if ( ( xSerialSemaphore ) != NULL )
      xSemaphoreGive( ( xSerialSemaphore ) );  // Make the Serial Port available for use, by "Giving" the Semaphore.
  }

  queue = xQueueCreate(10, sizeof(char));
  if (queue == NULL) {
    uart_sendstr(uart0, "Queue can not be created");
  }
 
  xTaskCreate(
    TaskRead
    ,  "Receive"  // A name just for humans
    ,  128  // This stack size can be checked & adjusted by reading the Stack Highwater
    ,  NULL
    ,  1  // Priority, with 1 being the highest, and 4 being the lowest.
    ,  NULL );

  xTaskCreate(
    TaskTransmit
    ,  "Transmit"
    ,  128  // Stack size
    ,  NULL
    ,  2  // Priority
    ,  NULL );
  vTaskStartScheduler();
 /* while(1)
  {
     uart_sendstr(uart0, uart_getstring(uart1, 1));
     _delay_ms(100);
  }*/
}

void loop()
{
  // put your main code here, to run repeatedly:
}

void TaskRead(void *pvParameters)
{
  while(1)
  {
    char* receive;
    if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
    {
     receive = uart_getstring(uart1, 10);
     xQueueSend(queue, &receive, portMAX_DELAY);
     xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
    }
    vTaskDelay(1);
  }
}

void TaskTransmit(void *pvParameters)
{
  char* received;
  while(1){
    if (xSemaphoreTake (xSerialSemaphore, (TickType_t)5) == pdTRUE)
    {
      if(xQueueReceive(queue, &received, portMAX_DELAY) == pdPASS)
      {
        uart_sendstr(uart1, received);
      }
      xSemaphoreGive(xSerialSemaphore);
    }
    vTaskDelay(1);
  }
}

Untitled

Looking at your code:

TaskTransmit() waits in xQueueReceive() for ever ( portMAX_DELAY ), or until there is a message in queue. But while waiting, the task holds the semaphore, and so the other task can not do anything. In a loop, tt will execute vTaskDelay() and try to get the semaphore, which is bound to fail.
Could that be?
Also, I do not see why you need both a queue and a semaphore?

Just an additional hint:
Your xTaskCreate comment regarding task priority is incorrect.
FreeRTOS task priorities correspond to the given value - a higher value means higher priority.

I think this misunderstanding also leads to a deadlock when starting the scheduler i.e. the created tasks.
TaskTransmit with (higher) prio 2 runs first, takes the semaphore and blocks forever on the queue.
TaskRead (with lower prio) then starts to run and loops forever failing to grab the semaphore already taken by TaskTransmit which in turn is blocked forever waiting for the queue…