Queue Task Crashing – Please Help

Hi, My function and/or call to the queue task is crashing, and I cannot understand why. I am using the same, identical code in other applications and it works fine there. I checked the FreeRTOS config file, and all looks OK, including stack size. This is being compiled in Atollic TrueStudio. Please see below for how I am using the calls. I have tried queueing messages from different tasks, but the same result. The task I am currently calling it from cycles every 225ms, and if there’s a new message to send, it places it (or tries to) on the queue. From the debug code, it never reaches there, as it appears to crash somewhere between the start of the scheduler and before queueing the message. I have also set the queue delay to some other value, i.e., ( TickType_t ) 10, but no luck there. It must be crashing before it even gets to the first call to queue, because it never prints the message just before it – see code. FreeRTOS version 8.2.0 Can someone please advise as to where the issue might be? I really need this to work, and I can’t beleive that it is not functioning as it should – again, having used it in other applications I know it works very well. Thank you! //message task will wait forever for queue to clear

define rxQueueRATE ( portMAX_DELAY )

static void vTxQueueFunction( void *pvParameters ); QueueHandle_t xQueueTask;
 //create transmit queue
 xQueueTask = xQueueCreate( 1, sizeof(uint8_t) );
 if(xQueueTask == 0) 
     printf("Failed to create xQueueTaskn");
 if( xTaskCreate( vTxQueueFunction, "rxDataQueue", 80, NULL, 2, &xQueueTask ) != pdPASS )
     printf("Cannot create queue taskn");
 printf("Scheduler starting, free heap size = %in", xPortGetFreeHeapSize());
 vTaskStartScheduler();
 while(1)
 {
     i++;
 }

 ///* queue function *////
static void vTxQueueFunction( void *pvParameters ) { uint8_t rxValue; portBASE_TYPE xStatus; for(;;) { if( uxQueueMessagesWaiting( xQueueTask ) != 0 ) { ///printf(“Queue should be empty, but %i messages in queuen”, uxQueueMessagesWaiting( xQueueTask ) ); }
    xStatus = xQueueReceive( xQueueTask, &rxValue, rxQueueRATE );

    if( xStatus == pdPASS )
    {
        printf("Rcvd in signal active queue: %in", rxValue);

        if( rxValue == 1 )
        {
            //do this
            printf("Received 1 in message queuen");

        }
        else if(rxValue == 2)
        {
            //do that
            printf("Received 2 in message queuen");
        }
        else
        {
            printf("received junkn");
        }
    }
    else
    {
        printf("Could not receive from queuen");
    }


}
} /* the call to queue a message */ uint8_t typeVal = 1; printf(“Going to queuen”); if( xQueueSendToBack(xQueueTask, &typeVal, rxQueueRATE ) != pdPASS ) { printf(“Failed to insert to queuen”); } else { printf(“Queuedn”); }

Queue Task Crashing – Please Help

Hi Roger, There is probably a typo in your code: ~~~~~ //create transmit queue xQueueTask = xQueueCreate( 1, sizeof(uint8_t) ); if(xQueueTask == 0) { printf(“Failed to create xQueueTaskn”); } if( xTaskCreate( vTxQueueFunction, “rxDataQueue”, 80, NULL, 2, &xQueueTask ) != pdPASS ) ~~~~~ You are passing the address of ‘xQueueTask‘ to xTaskCreate(), which wlll fill that variable with the task handle. See tasks.h for the correct syntax of xTaskCreate() Regards.

Queue Task Crashing – Please Help

Hi Roger, A bit more about your code fragment. Here below the queue handle is passed as a task parameter to the vTxQueueFunction. You can pass any data of the size of a pointer. In fact TaskHandle_t is also a pointer. It also declares TaskHandle_t xTaskHandle. The address of this handle is passed to xTaskCreate which fills in the handle of the newly created task. ~~~~~ //message task will wait forever for queue to clear

define rxQueueRATE portMAX_DELAY

static void vTxQueueFunction( void *pvParameters ); TaskHandle_t xTaskHandle; int main() { QueueHandle_t xQueueHandle;
//create transmit queue
xQueueHandle = xQueueCreate( 1, sizeof(uint8_t) );
xTaskCreate( vTxQueueFunction, "rxDataQueue", 80,
    ( void * ) xQueueHandle, 2, &xTaskHandle );

vTaskStartScheduler();

while(1)
{
    i++;
}
} /* queue function */ static void vTxQueueFunction( void pvParameters ) { uint8_t rxValue; portBASE_TYPE xStatus; / The queue handle has been passed as a task parameter. */ QueueHandle_t xQueueHandle = ( QueueHandle_t ) pvParameters;
for(;;)
{
    xStatus = xQueueReceive( xQueueHandle, &rxValue, rxQueueRATE );
    if( xStatus == pdPASS )
    {
    }
}
} ~~~~~ Regards.

Queue Task Crashing – Please Help

Fantastic, thanks for your help. Stupid me….I was using the queue handle in the task, no wonder it was breaking!