vTaskStartScheduler() jumps to FaultISR(void)

Hi,
vTaskStartScheduler() jumps to FaultISR(void) when I use WORK_HANDLE data structure. When I use single variable to pass void vATask( void *pvParameters ),
it works fine. I’m using heap_2.c. Even if I use Heap_4.c , it doesn’t work.
I’m using FreeRTOS V8.2.3 and CCS74.

typedef struct A_Message{
char ucMessageID;
char ucData[2];
} AMessage;

typedef struct {
QueueHandle_t xQueue;
TaskHandle_t xHandle;
}WORK_HANDLE;

int main( void )
{
    WORK_HANDLE Handle;
    
    Handle.xQueue = xQueueCreate(QUEUE_LENGTH, QUEUE_ITEM_SIZE);
    if (Handle.xQueue == NULL)
    {
        return 1; 
    }

    xTaskCreate(vATask, "TaskA", 200, (void *)&Handle, 1, &Handle.xHandle);
    
    xTaskCreate(vBTask, "TaskB", 200, (void *)&Handle, 1, NULL);
    
    vTaskStartScheduler();
    for (;;)
  
}
void vATask( void *pvParameters )
{
    QueueHandle_t xQueue;
    TaskHandle_t xHandleTA;
    AMessage xMessage;
    WORK_HANDLE *pSt;

    pSt=(WORK_HANDLE*)pvParameters;
    xQueue = pSt->xQueue;
    xHandleTA=pSt->xHandle;

    xMessage.ucMessageID = 2;
    for( ;; )
    {
        if( xQueueSendToBack( xQueue, &xMessage, pdMS_TO_TICKS( 100 ) ) != pdPASS )
        {
        }
        vTaskDelay( pdMS_TO_TICKS(500 ) ); 
        xMessage.ucMessageID++;
    }
}
void vBTask( void *pvParameters )
{
    QueueHandle_t xQueue;
    TaskHandle_t xHandleTB;
    AMessage xMessage;
    WORK_HANDLE *pSt;

    pSt=(WORK_HANDLE*)pvParameters;
    xQueue = pSt->xQueue;
    xHandleTB=pSt->xHandle;

    xQueue = ( QueueHandle_t )pvParameters;

    for( ;; )
    {
        if( xQueueReceive( xQueue, &xMessage, portMAX_DELAY ) != pdPASS )
        {
        
        }
        else
        {

        }

    }
}

It’s good practice to add the information which MCU you’re using. Sometimes issues are HW or port related. Also it’s better to markdown code blocks for readability by enclosing it in 3 tildes (optionally with a language tag appended to the lead-in mark.
E.g. markdown of C-code: ~~~c ...code block... ~~~

The main stack must not be used for variables given as arguments for tasks because the main stack is reset and reused as ISR stack e.g. for Cortex-M3/4/7 MCUs.
static, global or heap allocated variables can be used, of course.
See for example this post here in the forums. There are some more - it’s a pitfall :wink:

Thanks Hartmut,
I’m using M4 (TM4C123) MCU.
Is it only allowed to pass one variable to the task’s function, other variables pass through a global structure ?

Your approach is fine to pass multiple parameters to vTaskCreate :+1:
The only thing is the struct can’t be a main stack variable because it gets destroyed as soon as the scheduler starts because the main stack is (completely) reused as ISR stack for Cortex-M ports/MCUs by FreeRTOS.
In your case I’d just use a static variable static WORK_HANDLE Handle; which is persistent and not allocated from main stack.
Note that this restriction applies to all kinds of variables provided by reference/pointer.

Hi Hartmut,

With this declaration it worked fine.
B.regards