# FreeRTOS STM32F429i-DISCOVERY HardFault

**URL:** <https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374>\
**Category:** Kernel\
**Created:** [January 16, 2015, 2:45pm UTC](https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374 "2015-01-16T14:45:29Z")\
**Posts on this page:** 4\
**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:** [January 16, 2015, 2:45pm UTC](https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374/1 "2015-01-16T14:45:29Z")

</div>

**[alexanderbaev](https://sourceforge.net/u/alexanderbaev/)** wrote on [Friday, January 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/3d7ebd6d/#6d72):

Dear friends.  
I have the following problem – my program ends in the HardFault\_Handler.  
I use STM32F429i-discovery board.  
On the first place I took the demo project (CORTEX\_M4F\_STM32F407ZG-SK). I substituted several files and managed to run the kernel. Then I changed something (I really do not remember what) – and the problem occurred. I tried to do everything from scratch – nothing changed. Then I took template project presented by ST and added I suppose all necessary files for FreeRTOS (again from the ST package). All the code works properly before vTaskStartScheduler(); (I just display test string on the lcd).  
I tried to use the code by Joseph Yiu and it helped me to determine the place in which the program goes to the HardFault. It is in the file – port\_cm4.c

portBASE\_TYPE xPortStartScheduler( void )  
{  
/\* Make PendSV and SysTick the lowest priority interrupts. \*/  
\*(portNVIC\_SYSPRI2) |= portNVIC\_PENDSV\_PRI;  
\*(portNVIC\_SYSPRI2) |= portNVIC\_SYSTICK\_PRI;

```
/* Start the timer that generates the tick ISR. Interrupts are disabled
here already. */
prvSetupTimerInterrupt();

/* Initialise the critical nesting count ready for the first task. */
uxCriticalNesting = 0;

/* Ensure the VFP is enabled - it should be anyway. */
vPortEnableVFP();

/* Lazy save always. */
*( portFPCCR ) |= portASPEN_AND_LSPEN_BITS;

/* Start the first task. */
vPortStartFirstTask();

/* Should not get here! */
return 0;

```

}

After stepping through return 0 – program goes to the HardFault.  
In the disassembly window returne 0 is represented by the following:  
MOVS R0, #0  
POP {R1, PC}

The value in the register R1 (again thanks to Joseph Yiu program) which then is loaded to PC points to the empty region (B55F38B9) – if I determined correctly it is 512 MB Block 5 FMC.

What should I check next?

PS: Demo project of ST with FreeRTOS works great, but it has much more then I need, and when I tried to remove certain parts I finished with compilation problems.  
PPS. In the current project I had to add the following to the main.c module to pass the compilation:  
void EndIdleMonitor(void)  
{  
}

void StartIdleMonitor(void)  
{  
}

void vApplicationTickHook(void)  
{  
}

void vApplicationMallocFailedHook(void)  
{  
}

void vApplicationIdleHook(void)  
{  
}

---

<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:** [January 16, 2015, 2:54pm UTC](https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374/2 "2015-01-16T14:54:41Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, January 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/3d7ebd6d/#be0d):

You code should not return from the call to vPortStartFirstTask(); (the clue is on the next line, where the comment says “should not get here”).

vPortStartFirstTask() calls SVC 0, and I am guessing your problem is related to not have an SVC handler installed.

Normally FreeRTOS uses vPortSVCHandler() as the SVC handler, which can be mapped to its CMSIS name using a #define as described on this page: [http://www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html)

What is installed as the SVC handler? It might be an ST handler that needs to chain with the FreeRTOS handler, but I think you can just install the FreeRTOS handler outright.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 16, 2015, 6:02pm UTC](https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374/3 "2015-01-16T18:02:54Z")

</div>

**[alexanderbaev](https://sourceforge.net/u/alexanderbaev/)** wrote on [Friday, January 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/3d7ebd6d/#9dd3):

Thank you for the quick respond. The problem was exactly as you explained.  
What I did:

1. I added #define vPortSVCHandler SVC\_Handler  
#define xPortPendSVHandler PendSV\_Handler  
#define xPortSysTickHandler SysTick\_Handler  
to the FreeRTOSConfig.h file
2. Commented PendSV\_Handler, SysTick\_Handler, and SVC\_Handler in the stm32f4xx\_it.c file.  
Did I do right?

---

<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:** [January 16, 2015, 6:08pm UTC](https://forums.freertos.org/t/freertos-stm32f429i-discovery-hardfault/1374/4 "2015-01-16T18:08:23Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, January 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/3d7ebd6d/#9dd3/b004):

Provided none of the ST libraries are relying on those handlers then  
that is fine.

Regards.
