# Problems with xTaskDelay()

**URL:** <https://forums.freertos.org/t/problems-with-xtaskdelay/4658>\
**Category:** Kernel\
**Created:** [March 1, 2007, 2:29pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658 "2007-03-01T14:29:19Z")\
**Posts on this page:** 5\
**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:** [March 1, 2007, 2:29pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658/1 "2007-03-01T14:29:19Z")

</div>

**nobody** wrote on [Thursday, March 01, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/cdca6275/#cd3a):

Hello,

I’ve some mysterious problems with the xTaskDelay function. I start a task an everything runs until the xTaskDelay()-function is called and never returns.  
But if I create a “do-only-i++”-task with a priority set to tskIDLE\_PRIORITY+1 and set the other task to tskIDLE\_PRIORITY+2, everything runs normal.

I don’t know, that isn’t the way it should work, is it?  
By the way, I use a LPC2106 Board, GCC4.1.1 and FreeRTOS V3.2.3.

So, if someone have a good guess, what might be wrong, all answers are welcome.  
Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 1, 2007, 2:36pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658/2 "2007-03-01T14:36:42Z")

</div>

**nobody** wrote on [Thursday, March 01, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/cdca6275/#cd3a/c0b5):

I don’t understand your explanation.&nbsp; Can you try rewording or giving an example simple bit of code.

If xTaskDelay() does not return are you sure the tick interrupt is running correctly?

Are you using an idle hook that calls a blocking function?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 1, 2007, 3:49pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658/3 "2007-03-01T15:49:00Z")

</div>

**nobody** wrote on [Thursday, March 01, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/cdca6275/#cd3a/ab38):

I hope this time it is more understandable:

I create a task:  
-\> xTaskCreate(v\_task\_Heartbeat,(const signed portCHAR \* const) "heartbeat", configMINIMAL\_STACK\_SIZE, NULL, tskIDLE\_PRIORITY + 1, &x\_task\_Heartbeat\_Handle);  
which should do:  
-\>void v\_task\_Heartbeat(void \*pvParameters)  
{  
&nbsp;&nbsp;&nbsp; pvParameters = 0;  
&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; HEARTBEAT\_LED\_PORT = HEARTBEAT\_LED;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // set to output  
&nbsp;&nbsp;&nbsp; // endless loop  
&nbsp;&nbsp;&nbsp; for(;😉  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vTaskDelay(HEARTBEAT\_LED\_DELAY);&nbsp;&nbsp;&nbsp; // wait for 500 ticks (0.5s)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HEARTBEAT\_LED\_PORT\_CLR = HEARTBEAT\_LED;&nbsp; // turn on LED  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vTaskDelay(HEARTBEAT\_LED\_DELAY);&nbsp;&nbsp;&nbsp; // wait for 500 ticks (0.5s)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HEARTBEAT\_LED\_PORT\_SET = HEARTBEAT\_LED;&nbsp; // turn off LED  
&nbsp;&nbsp;&nbsp; }  
}

I use openocd to debug the program and when i reach the line: vTaskDelay(…), the programm jumps into the function. My task get delayed, but never wake up. When i step further the programm calls the Idle-Task an check if there are other task ready to run. Then i let the programm continue and after a short time i hold it. The programm now has reached an abort-error-loop.  
Now i increase the Task-Priority to 2 and create a new task:  
-\>void v\_task\_idle\_2(void \*pvParameters)  
{  
&nbsp;&nbsp;&nbsp; pvParameters = 0;  
&nbsp;&nbsp;&nbsp; u32 i;

&nbsp;&nbsp;&nbsp; // endless loop  
&nbsp;&nbsp;&nbsp; for(;😉  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;  
&nbsp;&nbsp;&nbsp; }  
}  
with a Priotity of tskIDLE\_PRIRITY+1. If i run this programm, everything seems to run normal an my LED is blinking.  
I don’t use an idle hook.

Some more settings:  
-\>  
#define configUSE\_PREEMPTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define configUSE\_IDLE\_HOOK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
#define configCPU\_CLOCK\_HZ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( unsigned portLONG ) 58982400 )&nbsp;&nbsp;&nbsp; /\* =12Mhz xtal multiplied by 4 using the PLL. \*/  
#define configTICK\_RATE\_HZ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( portTickType ) 1000 )  
#define configMAX\_PRIORITIES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( unsigned portBASE\_TYPE ) 8 )  
#define configMINIMAL\_STACK\_SIZE&nbsp;&nbsp;&nbsp; ( ( unsigned portSHORT ) 150 )  
#define configTOTAL\_HEAP\_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( ( size\_t ) ( 10 \* 1024 ) )  
#define configMAX\_TASK\_NAME\_LEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( 16 )  
#define configUSE\_TRACE\_FACILITY&nbsp;&nbsp;&nbsp; 0  
#define configUSE\_16\_BIT\_TICKS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
#define configIDLE\_SHOULD\_YIELD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1

/\* Set the following definitions to 1 to include the API function, or zero  
to exclude the API function. \*/

#define INCLUDE\_vTaskPrioritySet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define INCLUDE\_uxTaskPriorityGet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define INCLUDE\_vTaskDelete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
#define INCLUDE\_vTaskCleanUpResources&nbsp;&nbsp;&nbsp; 0  
#define INCLUDE\_vTaskSuspend&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define INCLUDE\_vTaskDelayUntil&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1  
#define INCLUDE\_vTaskDelay&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 1, 2007, 4:24pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658/4 "2007-03-01T16:24:45Z")

</div>

**nobody** wrote on [Thursday, March 01, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/cdca6275/#cd3a/30da):

By creating a second idle task that never blocks, you are soaking up all the available CPU so prvIdleTask is never executed.&nbsp; That seems to make it work.&nbsp; So I would then guess that the problem lies in prvIdleTask.

But in your configuration the prvIdleTask in tasks.c will do nothing at all if you create no tasks at tskIDLE\_PRIORITY - are you sure you don’t have such tasks also defined?

It all sounds like either an interrupt going astray or perhaps your SWI handler not being setup properly and thus you’re getting aborts when trying to execute garbage?

Robin

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 1, 2007, 6:34pm UTC](https://forums.freertos.org/t/problems-with-xtaskdelay/4658/5 "2007-03-01T18:34:53Z")

</div>

**nobody** wrote on [Thursday, March 01, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/cdca6275/#cd3a/5c0e):

Hello Robin,  
thanks for your answer. I checked the tasks.c, the interrupt routines and a few other functions, and there was nothing. While searching the code, i found a bug in my own code. (Actually i searched my own code a few times but didn’t saw it before). Now everything seems to work fine. (until the next bug 🙂 )

Again, thanks to all for helping me out.&nbsp;
