# vTaskDelay()/vTaskDelayUntil() not yielding on NXP LPC1769 using MCUXpresso IDE  v11.0.1 \[Build 2563\] \[2019-09-01\] 

**URL:** <https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098>\
**Category:** Kernel\
**Created:** [October 9, 2019, 3:02pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098 "2019-10-09T15:02:13Z")\
**Posts on this page:** 11\
**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:** [October 9, 2019, 3:02pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/1 "2019-10-09T15:02:13Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#bb02):

Hello,

I have three tasks to flash Red, Green and Blue LEDs on the board. The objective is to get the colours to blink periodically (all flashing at the same period) but out of phase so that no two colours are on at the same time.

I am trying to do this using a task for each LED colour, with task priorities 3 for red, 2 for green and 1 for blue. The tasks use vTaskDelayUntil() to synchronize their operations, i.e., while one LED is on, the other LEDs are off and delaying (presumably in blocked states).

However, I am having the problem that the highest priority task (Red LED Task) does not seem to enter the blocked state. Only the Red LED flashes. Using the debugger (and setting breakpoints within each task’s while (1) loop), I notice that the the lower priority tasks have the opportunity to run only once! After that, the highest priority task never yields (the scheduler stays in the Red task’s loop, even while executing the vTaskDelayUntil() API function).

And I attach the code and my FreeRTOSConfig.h file.

Any feedback would be appreciated.

Thanks,  
Takis

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 9, 2019, 3:03pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/2 "2019-10-09T15:03:16Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#70a4):

Sorry, the source code is attached here…

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 9, 2019, 3:22pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/3 "2019-10-09T15:22:05Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#70a4/8153):

Not looked at code in detail yet, but have you checked the value of  
delayTicks inside the functions?

Start with one task only, and a long delay time to make it obvious when  
the LED is toggling. With just a single task, if the LED does not seem  
to be toggle at the frequency you think, set a break point in that task  
and check the values are as you expect. Once you have that one task  
working as expected you can add in the others.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 9, 2019, 4:02pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/4 "2019-10-09T16:02:56Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#70a4/8153/1c83):

Richard,

First of all thanks for responding so quickly!

Second, you figured out my problem! I set numticks manually, and the whole application works now.

I will now have to determine why my parameter passing through pvParameters is not working correctly. Pointers are the bane of my existence!

Thanks again

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 9, 2019, 6:12pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/5 "2019-10-09T18:12:14Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#ba1c):

The problem may be that you are creating the structures you pass on the main stack. The main stack is reused in some ports for the interrupt stack, so its contents might not be preserved. Make those structures globals instead of function locals in main to see if that makes things work.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 9, 2019, 8:55pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/6 "2019-10-09T20:55:08Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Wednesday, October 09, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#ba1c/21a6):

Richard,

Thanks for this point. I think it is spot on! I could not understand why the parameters were not being passed into the task functions. I wrote the code in this way to illustrate to my students that it is possible to pass in fairly complex data structures using type casting of void pointers within the task function.

Everything works now!

Cheers

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 10, 2019, 1:03am UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/7 "2019-10-10T01:03:09Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Thursday, October 10, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#780c):

And if you put just a bit more data into the structures, you could make all three task use the same function to show the real power of it.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 10, 2019, 11:26pm UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/8 "2019-10-10T23:26:45Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Thursday, October 10, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#780c/9a9f):

Thanks again, to both Richards!

I added a mutex and now there is just a single task function! 🙂

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 11, 2019, 12:35am UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/9 "2019-10-11T00:35:12Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, October 11, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#780c/9a9f/81d2):

A couple of comments:

1. A mutex is a very heavy object to use here, a simple and fast  
critical section is all that is needed.

2. You are holding the mutex across the vTaskDelay() call - that should  
not be necessary especially if toggling will interleave with other tasks  
in which case you will serialise access by holding the mutex that long.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 11, 2019, 1:48am UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/10 "2019-10-11T01:48:11Z")

</div>

**[takiszoo](https://sourceforge.net/u/takiszoo/)** wrote on [Friday, October 11, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#780c/9a9f/81d2/5ac2):

Richard, thank you for taking the time to look over the code and provide feedback! I cannot argue with your assessment because no one knows this kernel better than you.

However, I was hesitant to use taskENTER\_CRITICAL()/taskEXIT\_CRITICAL() because I thought all context switches are suspended during that section of code, whereas the mutex localizes the impact on context switching to a single resource (in this case, we are trying to have only one LED colour displaying at any time).

This example is admittedly contrived, but we are intentionally serializing access to prevent colour mixing, which is why I was using the mutex across the vTaskDelay()…

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 11, 2019, 2:15am UTC](https://forums.freertos.org/t/vtaskdelay-vtaskdelayuntil-not-yielding-on-nxp-lpc1769-using-mcuxpresso-ide-v11-0-1-build-2563-2019-09-01/8098/11 "2019-10-11T02:15:12Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, October 11, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9ca89b052e/#780c/9a9f/81d2/5ac2/32c7):

You are right in that you cannot call vTaskDelay() inside a critical  
section created with taskENTER/EXIT\_CRITICAL(), so my suggestion was not  
clear, in that I only meant to protect accessing the LED with the  
critical section. However from your last reply it sounds like you want  
to protect access across the delay too.
