FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2009 Threads] Reading from message queue crashesPosted by specialk on September 22, 2009 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: %c\r\n", rxChar); uart1PutString(feedback, 10); } } // Transmit current tick on UART1 char *output; sprintf(output, "Ticks: %d\r\n", xTaskGetTickCount()); uart1PutString(output, 10); vTaskDelay(100); } }
RE: Reading from message queue crashesPosted by specialk on September 22, 2009 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("\r\n", portMAX_DELAY); } }
RE: Reading from message queue crashesPosted by woops_ on September 22, 2009 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: %c\r\n", 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.
RE: Reading from message queue crashesPosted by specialk on September 22, 2009 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[80]; sprintf(feedback, "Received: %c\r\n", rxChar); uart1PutString(feedback, 10);
RE: Reading from message queue crashesPosted by woops_ on September 22, 2009 that should be better, but make sure you have enough stack space to hold the 80 character array.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|