# freertos hanging on vListInsert

**URL:** <https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217>\
**Category:** Kernel\
**Created:** [July 7, 2009, 12:44pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217 "2009-07-07T12:44:09Z")\
**Posts on this page:** 7\
**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:** [July 7, 2009, 12:44pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/1 "2009-07-07T12:44:09Z")

</div>

**[spsider](https://sourceforge.net/u/spsider/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495):

Hi All,

I think you will nail my problem easily

I am still new to FreeRTOS, and my program is hanging always in the same line of code after random times (minutes or hours), generally with ethernet traffic.  
I am using Cortex-M3 from luminary, with lwip raw.

The code always hangs on this line:

for( pxIterator = ( xListItem \* ) &( pxList-\>xListEnd ); pxIterator-\>pxNext-\>xItemValue \<= xValueOfInsertion; pxIterator = pxIterator-\>pxNext )

in vListInsert , filename: list.c

pxIterator-\>pxNext points to itself, so it hangs there.

As this code is "inside" freeRTOS, what could have causing this? Where should I look for?

Thank you very much, and sorry if it is a stupid question.  
Sergio P. Sider

---

<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:** [July 7, 2009, 12:49pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/2 "2009-07-07T12:49:34Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/be45):

Just by reading the subject of your post I would guess you are using a Cortex M3 and have your interrupt priorities wrong.&nbsp; I would say though - read the comment directly above the line that is crashing.&nbsp; I have replicated it below for your convenience.

/\* \*\*\* NOTE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
If you find your application is crashing here then likely causes are:  
1) Stack overflow -  
&nbsp;&nbsp; see [http://www.freertos.org/Stacks-and-stack-overflow-checking.html](http://www.freertos.org/Stacks-and-stack-overflow-checking.html)  
2) Incorrect interrupt priority assignment, especially on Cortex M3  
&nbsp;&nbsp; parts where numerically high priority values denote low actual  
&nbsp;&nbsp; interrupt priories, which can seem counter intuitive.&nbsp; See  
&nbsp;&nbsp; configMAX\_SYSCALL\_INTERRUPT\_PRIORITY on [http://www.freertos.org/a00110.html](http://www.freertos.org/a00110.html)  
3) Calling an API function from within a critical section or when  
&nbsp;&nbsp; the scheduler is suspended.  
4) Using a queue or semaphore before it has been initialised or  
&nbsp;&nbsp; before the scheduler has been started (are interrupts firing  
&nbsp;&nbsp; before vTaskStartScheduler() has been called?).  
See [http://www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html) for more tips.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
for( pxIterator = ( xListItem \* ) &( pxList-\>xListEnd ); pxIterator-\>pxNext-\>xItemValue \<= xValueOfInsertion; pxIterator = pxIterator-\>pxNext )

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 7, 2009, 1:31pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/3 "2009-07-07T13:31:43Z")

</div>

**[spsider](https://sourceforge.net/u/spsider/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/0c3d):

HI RIchard,

Thanks… I think my version is outdated, because these comments do not exist on my version…  
I will check it all (all I know for now it´s not a stack overflow).

Thanks again,  
Sergio Sider.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 7, 2009, 5:47pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/4 "2009-07-07T17:47:29Z")

</div>

**[utezduyar](https://sourceforge.net/u/utezduyar/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/551f):

Hi

I am having the exact same problem. Code stays in the for loop and never comes out. I was also suspicious about the stack overflow but that is not the case.

In my system, other than operating system tasks, I have one UART task and 5 more tasks with priority 1. Other than uart task, all other tasks just suspend the execution with vTaskDelay.

One final note is, just like Sergio’s code, my FreeRTOS code doesn’t have the comments shown by Richard.

Thanks a lot.

---

<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:** [July 7, 2009, 5:55pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/5 "2009-07-07T17:55:06Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/551f/de34):

With the risk of just repeating myself "Just by reading the subject of your post I would guess you are using a Cortex M3 and have your interrupt priorities wrong".&nbsp; Neither respondent has indicated whether this is the case or not.&nbsp; Without further information all I can do is give you the same advice as the original poster.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 7, 2009, 9:39pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/6 "2009-07-07T21:39:11Z")

</div>

**[spsider](https://sourceforge.net/u/spsider/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/ac50):

Hi Richard,

I just confirmed that was the interrupt priority as you suggested. I forgot to set the interrupt priority of one of my interrupt handlers, so it defaults to ‘whatever’ and this handler was calling a API function.

BTW, I will update my version to the current one… I probably would not have to bother you if I the comments were there… 😉

Thanks again!!!  
Sergio P. SIder

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 7, 2009, 11:24pm UTC](https://forums.freertos.org/t/freertos-hanging-on-vlistinsert/4217/7 "2009-07-07T23:24:27Z")

</div>

**[utezduyar](https://sourceforge.net/u/utezduyar/)** wrote on [Tuesday, July 07, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/b9f623d4/#7495/84c0):

I tried another way and it worked too.

If you are not sure about the priorities of your system yet, set configMAX\_SYSCALL\_INTERRUPT\_PRIORITY to 0. Which will disable interrupt masking. The function that uses configMAX\_SYSCALL\_INTERRUPT\_PRIORITY is xPortPendSVHandler.

The inliner assembler will look like this:

…  
…  
…  
mov r0, %0  
msr basepri, r0  
bl vTaskSwitchContext  
mov r0, #0  
msr basepri, r0  
ldmia sp!, {r3, r14}  
…  
…  
…

where %0 is configMAX\_SYSCALL\_INTERRUPT\_PRIORITY. Setting configMAX\_SYSCALL\_INTERRUPT\_PRIORITY to 0 will execute the same instruction (msr basepri, r0) twice.

Also, I haven’t seen a usage of configKERNEL\_INTERRUPT\_PRIORITY variable other than assigning to a constant variable in GCC port file.

Thanks Richard!
