# FreeRTOS: HardFault in VListInsertEnd() - Stack Crash ?

**URL:** <https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656>\
**Category:** Kernel\
**Created:** [February 6, 2019, 6:59pm UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656 "2019-02-06T18:59:50Z")\
**Posts on this page:** 6\
**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:** [February 6, 2019, 6:59pm UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/1 "2019-02-06T18:59:50Z")

</div>

**[paulromero](https://sourceforge.net/u/paulromero/)** wrote on [Wednesday, February 06, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#9fb2):

Dear Staff:

I am using FreeRTOS Kernel Version V8.0.1 with version 3.2 of the Roweley Crossworks for ARM  
toolchain which uses the GCC compiler. The target environment for the code is the Embedded  
Artist’s LPC4088 dev. board with an NXP LPC4088 Cortex M4 MCU. The Crossworks toolchain is  
running under Debian Linux. (NOTE: configASSERT() is defined in the normal way in  
FreeRTOSConfig.h()) Also, the following problem does not occur with version XXX of Crossworks.

The problem is that after using xTimerStart() to start a timer the following  
completely reproducable HardFault crash occurs during a call to vListInsertEnd().

```
149 DEFAULT_ISR_HANDLER HardFault_Handler

```

It occurs in VListInsertEnd() at the line labled CRASH below.

```
void VListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex;

	/* Insert a new list item into pxList, but rather than sort the list,
	makes the new list item the last item to be removed by a call to
	listGET_OWNER_OF_NEXT_ENTRY(). */
	pxNewListItem->pxNext = pxIndex;
	pxNewListItem->pxPrevious = pxIndex->pxPrevious;	// CRASH

```

The attached file, stack.png, shows the stack trace.  
These are some other relevant clues.

- pxPortInitialize() stack appears to have executed many times at the time of the crash  
and the last instance is as follows:

- In VlistInsertEnd(), all fields of pxIndex have the value 0xaaaaaaaa.

I think, but don’t know, the problem is something technical rather than a normal stack crash.

Best Regards,

Paul R.

---

<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:** [February 7, 2019, 2:39am UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/2 "2019-02-07T02:39:27Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, February 07, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#9fb2/0fd3):

> I am using FreeRTOS Kernel Version V8.0.1

Gosh, why are you using such an old version?

> with version 3.2 of the  
> Roweley Crossworks for ARM  
> toolchain which uses the GCC compiler. The target environment for the  
> code is the Embedded  
> Artist’s LPC4088 dev. board with an NXP LPC4088 Cortex M4 MCU. The  
> Crossworks toolchain is  
> running under Debian Linux. (NOTE: configASSERT() is defined in the  
> normal way in  
> FreeRTOSConfig.h()) Also, the following problem does not occur with  
> version XXX of Crossworks.

Ok, so I think what you have just said is the problem exists with one  
version of GCC, but not another, but you haven’t said whether it is the  
older or the newer version of GCC that you have success with.

Looks like stack corruption, but it is difficult to say if the problem  
is the kernel code, or the compiler, as you indicate it works fine with  
a different version of the compiler.

My first suggestion would be to read through all the points in this page  
from the FAQ [FreeRTOS - Open Source RTOS Kernel for small embedded systems](https://www.freertos.org/FAQHelp.html) then, if that does  
not help, to update to the very latest version of FreeRTOS. It is not  
that I’m aware of any bugs in older versions, but the newer the version  
the more configASSERT() points there are to catch misconfigurations that  
could result in critical sections not functioning correctly. The latest  
version will catch nearly all, if not all, errors in configuration the  
kernel to match the NVIC implementation in your FreeRTOS configuration.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 7, 2019, 3:18am UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/3 "2019-02-07T03:18:45Z")

</div>

**[paulromero](https://sourceforge.net/u/paulromero/)** wrote on [Thursday, February 07, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#07e3):

Hi Richard:

I looked at the FAQHelp document and think the only thing I am doing  
that does not conform is how I disable and enable particular interrupts.  
When I need to enable or disable a particular interrupt I use  
NVIC\_EnableIRQ() and NVIC\_DisableIRQ() which I think is correct.  
I think the FAQHelp document is referring to enabling or disabling  
all interrupts.

Best Regards,

Paul R.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 7, 2019, 3:53pm UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/4 "2019-02-07T15:53:23Z")

</div>

**[paulromero](https://sourceforge.net/u/paulromero/)** wrote on [Thursday, February 07, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#a056):

More technical information: The same code works on Crossworks Version 4.2 running  
on a Ubuntu Linux system. The GCC version on that system is 4.9.2 and the Ubuntu  
version is 4.9.2. The GCC version on the Debian system is 4.7.2 and the Debian version  
is 4.7.2.

---

<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:** [February 7, 2019, 4:44pm UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/5 "2019-02-07T16:44:37Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, February 07, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#a056/e243):

I know its an obvious question - but I have to ask - if it works with  
the later GCC version then why not use that? I know there were some  
changes in GCC that required some code updates in the FreeRTOS port layer.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 7, 2019, 4:44pm UTC](https://forums.freertos.org/t/freertos-hardfault-in-vlistinsertend-stack-crash/7656/6 "2019-02-07T16:44:59Z")

</div>

**[paulromero](https://sourceforge.net/u/paulromero/)** wrote on [Thursday, February 07, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/f294b9569a/#4427):

Additional Detail: I have stack overflow checking enabled and the hook function–  
vApplicationStackOverflowHook() is not being called.
