# UART IRQ using Queue example

**URL:** <https://forums.freertos.org/t/uart-irq-using-queue-example/7847>\
**Category:** Kernel\
**Created:** [May 14, 2019, 7:10am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847 "2019-05-14T07:10:55Z")\
**Posts on this page:** 20\
**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:** [May 14, 2019, 7:10am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/1 "2019-05-14T07:10:55Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Tuesday, May 14, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#5325):

Hai every one iam new to RTOS and dont know how to use queue inside IRQ Handler i searched in web for sample programs.I could not find one can any one help me with some sample code for queue inside irq

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 14, 2019, 10:43am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/2 "2019-05-14T10:43:41Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Tuesday, May 14, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#3306):

If you look at the demos that are distributed with FreeRTOS, there are examples of using queue inside of Interrupt handlers. For example, the serial ports in the demos run based on using a queue. The biggest thing to remember is that inside an Interrupt handler, you should only call FreeRTOS functions that end in FromISR, and none of these functions will offer the opertunity to ‘block’ for something, as ISRs shouldn’t want to wait. That means you need to decide what to do if you have data to put into a queue, but the queue is full.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 15, 2019, 4:49am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/3 "2019-05-15T04:49:34Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Wednesday, May 15, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#20dd):

Hi Thank you for your response.  
Can you help me with providing the exact link for that bcs i could not find the correct one.

i have tried with some example in web but it was not working the program get struck insid the queue loop. Below i have attached my sample code

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 15, 2019, 12:05pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/4 "2019-05-15T12:05:36Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Wednesday, May 15, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#a8dd):

There are LOTS of demos provide in the FreeRTOS download, organzed by compiler and processor. Since you haven’t said what processor or compiler you are using, we can’t tell you which one is most appropriate. Most of them will have a serial ISR that sends data to a task via a queue.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 15, 2019, 12:22pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/5 "2019-05-15T12:22:25Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Wednesday, May 15, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#e67b):

Yes i have tried using the some example but i can’t able to achive it…  
when i send some data to the uart it get struck into the queue function.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 15, 2019, 12:22pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/6 "2019-05-15T12:22:28Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Wednesday, May 15, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#a769):

---

<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:** [May 15, 2019, 3:12pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/7 "2019-05-15T15:12:29Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, May 15, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#a769/48b4):

What does ‘getting stuck’ mean? My immediate thought is that your  
interrupt priorities are wrong resulting in you hitting an assert(), but  
you are really going to have to provide more information. Looking at  
your code though, I do notice you are creating a queue that will hold  
4-byte types, and then trying to post 1-byte types - that will cause  
3-bytes of junk to be posted to the queue each time and accessing that  
junk may cause issues. Also, although many of the demos use a queue to  
send individual bytes out of an ISR that is really done just to stress  
the system as a test as it is not very efficient - you would be better  
off using a stream buffer which is much lighter weight.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 16, 2019, 10:58am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/8 "2019-05-16T10:58:58Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Thursday, May 16, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#a247):

Getting struck mean the code get into some loop and not exiting from that loop.

i have tried by change the queue size also but not getting the output

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 16, 2019, 11:35am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/9 "2019-05-16T11:35:20Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Thursday, May 16, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#668b):

IF it is stuck in a loop inside the ISR, then likely you have hit an assert in the code because something is setup wrong, the most likely issue is the priority of the interrupt is impropper.

Can you use a debugger and see what the loop is, and what caused it?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 18, 2019, 12:29pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/10 "2019-05-18T12:29:32Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Saturday, May 18, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#310a):

i cant able to enter into the debugging mode if upoaded the code and enter into the debugging it is giving internal command error and it is only for that code for other codes it is working fine.some time it is entering at that time if the code struct and when i stopped it the code stops inside hardfault handler

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2019, 7:31am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/11 "2019-05-21T07:31:02Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#4fd0):

Hi i have some how managed tried to open debug mode and entered into it. when iam checking it the code struck into the function name vPortValidateInterruptPriority and not comming out of it can you help me to solve this i have attached the code and screenshort below.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2019, 10:59am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/12 "2019-05-21T10:59:23Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#1022):

That likely says your Intterupt has been assigned an invalid interrupt priority. FreeRTOS tends to reserve a few very high priority levels for ISRs that don’t need to use FreeRTOS and that FreeRTOS won’t impact with critical sections (This is dependent on what processor and what port for that processor you are using). Some processors default interrupts to the absolute highest priority, which would not be valid to be used with FreeRTOS. You may need to expicitly set the interrupt priority before you enable the interrupt.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2019, 11:04am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/13 "2019-05-21T11:04:12Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#3c6c):

Iam using STM32F429IGTx microcontroller it has max 15 priority levels.In my FreeRTOS congig i have given max priority of 5

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2019, 11:13am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/14 "2019-05-21T11:13:34Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#28b7):

And if you don’t explicitly assign the priority it will default to priority 0, which is higher than 5.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 21, 2019, 11:47am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/15 "2019-05-21T11:47:12Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#8f96):

For system UART Irq i have given the priority 8 and rtos priority as 10 so RTOS will have the highest priority even though i am geting the same issue .

---

<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:** [May 21, 2019, 2:01pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/16 "2019-05-21T14:01:12Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, May 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#8f96/eee5):

Please familiarise yourself with all the information on this page:  
[https://www.freertos.org/RTOS-Cortex-M3-M4.html](https://www.freertos.org/RTOS-Cortex-M3-M4.html)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 22, 2019, 7:08am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/17 "2019-05-22T07:08:42Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Wednesday, May 22, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#8536):

From this i came to understand that configMAX\_SYSCALL\_INTERRUPT\_PRIORITY should have high priority than other system NVIC piriority is it so…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 22, 2019, 10:56am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/18 "2019-05-22T10:56:41Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Wednesday, May 22, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#36dc):

Your comprehension is perhaps lacking then. configMAX\_SYSCALL\_INTERRUPT\_PRIORITY is a informational define to tell FreeRTOS what the highest priority (lowest value) interupt the user application will use to call FreeRTOS, and that it should not expect calls from/and not block execution of interrupt with a Higher Priority.

The only interrupt priority that FreeRTOS itself will use are configKERNEL\_INTERRUPT\_PRIORITY which is used as the default for the system timer tick and is used for the scheduler service interrupt to force a task swap.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 23, 2019, 6:02am UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/19 "2019-05-23T06:02:02Z")

</div>

**[akashmeras](https://sourceforge.net/u/akashmeras/)** wrote on [Thursday, May 23, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#8b17):

Even i configure kernal priority as high and system priority low having the same issue my code stops inside vPortValidateInterruptPriority() 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:** [May 23, 2019, 2:17pm UTC](https://forums.freertos.org/t/uart-irq-using-queue-example/7847/20 "2019-05-23T14:17:03Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, May 23, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/384ba0acd4/#8b17/0fc4):

Make sure you are using a recent version of FreeRTOS, at least 10.1.1 or  
higher as recent versions have more assert points, and that you have  
configASSERT() defined, then run the code, stop the debugger, see where  
you are. If you are in an assert let us know which assert you are in.

[Next page](https://forums.freertos.org/t/uart-irq-using-queue-example/7847.md?page=2)
