Parameter corruption with xTaskCreate

amalo wrote on Wednesday, June 17, 2009:

Hi,

  I want to create task and retrieve the handle, but when I call the xTaskCreate, the handle parameter get corrupted or is not passed correctly.

void vTDT_Init()
{
   static unsigned char ucParamTrap;
   int result;
   xTaskHandle handle;
  
   /* Start trap demo task */
   result = xTaskCreate(vSendTrapTaskDemo,
                        (signed portCHAR*)"TRAP",
                        TRAP_TASK_STACK_SIZE,
                        &ucParamTrap,
                        TRAP_TASK_PRIO,
                        &handle
                       );
}

when in vTDT_Init() function, handle as a valid address. When pass to xTaskCreate, the address is change and become invalid.

Any idea why I get this behavior? This task is created in the main, so I doubt its a freeRTOS stack size problem…

Thanks

jakbird wrote on Wednesday, June 17, 2009:

The "handle" variable is allocated on the stack when you enter the vTDT_Init routine.  When you exit the routine it no longer exists.  Try making "handle" a global; move it out of the routine block.

amalo wrote on Wednesday, June 17, 2009:

Hi, I have also tried this. It’s not working. There is still corruption

You say it’s allocated on the stack. But wich stack? Is there a way to control that stack you are talking about? I guess it’s the default micro-c stack…

Thanks

amalo wrote on Wednesday, June 17, 2009:

The corruption made when passing the arguments. Right in xTaskCreate the handle point to an invalid memory address.

The function stop there because there is an exception (trying to write to a protected space…)

I must put NULL atm. I can’t use handles…

edwards3 wrote on Wednesday, June 17, 2009:

Which port are you using?  MCU and compiler.

amalo wrote on Wednesday, June 17, 2009:

Im working with CodeWarrior.

My micro-c is MCF5282. (M5282LITE)

edwards3 wrote on Wednesday, June 17, 2009:

In which case check your compiler options. You can configure to use either register based parameter passing or stack based. Sounds like something is messed up somewhere.

amalo wrote on Wednesday, June 17, 2009:

You are right!! Thanks!!

My config was set to compact mode… I guess there was a messed up in the settings… I set it to register and its working…

I’ll optimize later :slight_smile:

Thanks a ton!