# Parameter corruption with xTaskCreate

**URL:** <https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486>\
**Category:** Kernel\
**Created:** [June 17, 2009, 3:48pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486 "2009-06-17T15:48:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 3:48pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/1 "2009-06-17T15:48:41Z")

</div>

**[amalo](https://sourceforge.net/u/amalo/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a):

Hi,

&nbsp; 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()  
{  
&nbsp;&nbsp; static unsigned char ucParamTrap;  
&nbsp;&nbsp; int result;  
&nbsp;&nbsp; xTaskHandle handle;  
&nbsp;&nbsp;  
&nbsp;&nbsp; /\* Start trap demo task \*/  
&nbsp;&nbsp; result = xTaskCreate(vSendTrapTaskDemo,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (signed portCHAR\*)"TRAP",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRAP\_TASK\_STACK\_SIZE,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &ucParamTrap,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRAP\_TASK\_PRIO,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &handle  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );  
}

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

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 4:05pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/2 "2009-06-17T16:05:38Z")

</div>

**[jakbird](https://sourceforge.net/u/jakbird/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/3a74):

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

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 4:11pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/3 "2009-06-17T16:11:30Z")

</div>

**[amalo](https://sourceforge.net/u/amalo/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/92bf):

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

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 5:12pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/4 "2009-06-17T17:12:26Z")

</div>

**[amalo](https://sourceforge.net/u/amalo/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/9e53):

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…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 7:16pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/5 "2009-06-17T19:16:29Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/9e53/c0fc):

Which port are you using?&nbsp; MCU and compiler.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 7:21pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/6 "2009-06-17T19:21:28Z")

</div>

**[amalo](https://sourceforge.net/u/amalo/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/59a0):

Im working with CodeWarrior.

My micro-c is MCF5282. (M5282LITE)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 7:24pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/7 "2009-06-17T19:24:05Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/59a0/60ce):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 17, 2009, 7:37pm UTC](https://forums.freertos.org/t/parameter-corruption-with-xtaskcreate/4486/8 "2009-06-17T19:37:52Z")

</div>

**[amalo](https://sourceforge.net/u/amalo/)** wrote on [Wednesday, June 17, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/c57aade3/#469a/0d1d):

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 🙂

Thanks a ton!
