Reading from message queue crashes

I’m trying to set up a task that will regularly check the rx message queue on uart, and I have the ISR working properly, but whenever I try to read the contents of the rx message queue I receive the character, but the mcu crashes immediately afterwards.  Also, if no character is input before xQueuePeek times out (500 ticks in this case) it will also crash.  If I remove the code to check the rx queue, it works fine and happily writes to the uart every 100 ticks as expected. I just ordered the freertos book (hopefully I’ll get it today), but if there something that I’m doing in this task code that I obviously shouldn’t be?  (All I’m trying to do it send the char back out to the UART just to see if it works or not.)     static portTASK_FUNCTION(vUART1Task, pvParameters __attribute__((unused)))
    {
      static xQueueHandle rxQueue = NULL;
      uart1GetRxQueue (&rxQueue);
      signed portCHAR rxChar;
   
      for (;;)
      {
        /* Check if anything is available in the rx queue */
        if (rxQueue)
        {
          if (xQueuePeek(rxQueue, &rxChar, (portTickType)500))
          {
             /* Print the result on the uart port */
             char *feedback;
             sprintf(feedback, "Received: %crn", rxChar);
             uart1PutString(feedback, 10);
          }
        }
   
        // Transmit current tick on UART1
        char *output;
        sprintf(output, "Ticks: %drn", xTaskGetTickCount());
        uart1PutString(output, 10);
        vTaskDelay(100);
      }
    }

Reading from message queue crashes

It seems that it isn’t actually the queues, but the sprintf that’s causing the problems.  The following code seems to work as expected:     /* Check if anything is available in the rx queue */
    if (rxQueue)
    {
      if (xQueueReceive(rxQueue, &rxChar, (portTickType)500)) // portMAX_DELAY))
      {
         /* Print the result on the uart port */
         uart1PutString("Received: ", portMAX_DELAY);
         uart1PutChar(rxChar, portMAX_DELAY);
         uart1PutString("rn", portMAX_DELAY);
      }
    }

Reading from message queue crashes

char *feedback;
With this line you allocate a character pointer, but no memory to hold the string to which it points. The pointer is uninitialized. sprintf(feedback, "Received: %crn", rxChar);
With this line you are writing a dozen characters into an address pointed to by an uninitialized pointer, so it will more than likely crash.

Reading from message queue crashes

Ooops … so busy looking at the queues that I don’t pay attention to what’s right in front of my eyes :)          /* Print the result on the uart port */
         char feedback;
         sprintf(feedback, "Received: %crn", rxChar);
         uart1PutString(feedback, 10);

Reading from message queue crashes

that should be better, but make sure you have enough stack space to hold the 80 character array.