# vPortStartFirstTask() generates Hard Fault Exception

**URL:** <https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385>\
**Category:** ST\
**Created:** [July 29, 2020, 3:48pm UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385 "2020-07-29T15:48:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RiccardoPalma](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@RiccardoPalma](https://forums.freertos.org/u/RiccardoPalma)\
**Post date:** [July 29, 2020, 3:48pm UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385/1 "2020-07-29T15:48:08Z")

</div>

Hi, i’m working on STM32CubeIDE platform to program STM32F407 Discovery Kit with FreeRTOS. I set the default configuration of FREERTOS and I select TIM1 as Timebase Source as suggested. I want to test a simple blinking LED routine in the default task, but during debug the software generates Hard Fault Exception on osKernalStart() call. The exception is generated here:

void vPortStartFirstTask( void )  
{  
\_\_asm volatile(  
" ldr r0, =0xE000ED08 \n" /\* Use the NVIC offset register to locate the stack. _/  
" ldr r0, [r0] \n"  
" ldr r0, [r0] \n"  
" msr msp, r0\n" /_ Set the msp back to the start of the stack. _/  
" cpsie i\n" /_ Globally enable interrupts. _/  
" svc 0\n" /_ System call to start first task. \*/  
" nop\n"  
);  
}

I have read in other posts the problem could be solved by adding these lines, but in my version of FreeRTOS and STM32CubeIDE they were already present.  
#define vPortSVCHandler SVC\_Handler  
#define xPortPendSVHandler PendSV\_Handler  
#define xPortSysTickHandler SysTick\_Handler

Any suggestions?

Thanks for helping.

Riccardo Palma, Giacomo Melai

---

<div class="post-metadata">

**Author:** ![jefftenney](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/jefftenney/32/1314_2.png) [@jefftenney](https://forums.freertos.org/u/jefftenney)\
**Post date:** [July 29, 2020, 4:16pm UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385/2 "2020-07-29T16:16:12Z")

</div>

Maybe an odd question for you, but are you using CubeIDE v1.4.0? This post may be related.

> [@Simple Project FreeRTOS with new update fail](https://forums.freertos.org/t/bug-report-simple-project-freertos-with-new-update-fail/10370):
>
> Hi, i have some trouble with the new update at firmware on NUCLEO-F446RE. The ST launched a new update to CubeMX and CubeIDE. I updated to the new version and created a simple project with FreeRTOS. When the processor executes the instruction “svc 0” to start the first task, the command fail and a Hard Fault is detected. I have see the same issue with Fedora, Manjaro OS and Windows. My conf: STM32CubeIDE Version: 1.4.0 Build: 7511\_20200720\_0928 (UTC) OS: Linux, v.5.7.10-201.fc32.x86\_64, x…

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [July 29, 2020, 4:19pm UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385/3 "2020-07-29T16:19:15Z")

</div>

There is a doc provided by STM which could be helpful:  
[Developing applications on STM32Cube with RTOS](https://www.st.com/resource/en/user_manual/dm00105262-developing-applications-on-stm32cube-with-rtos-stmicroelectronics.pdf)  
I guess there are also official _Blinky_ demos for comparison…

---

<div class="post-metadata">

**Author:** ![RealtimeRik](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/realtimerik/32/581_2.png) [@RealtimeRik](https://forums.freertos.org/u/RealtimeRik)\
**Post date:** [July 29, 2020, 5:25pm UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385/4 "2020-07-29T17:25:25Z")

</div>

Try instruction level single step through vPortStartFirstTask. See if you end up in the correct SVC handler when SVC 0 is executed.

---

<div class="post-metadata">

**Author:** ![RiccardoPalma](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@RiccardoPalma](https://forums.freertos.org/u/RiccardoPalma)\
**Post date:** [July 30, 2020, 7:56am UTC](https://forums.freertos.org/t/vportstartfirsttask-generates-hard-fault-exception/10385/5 "2020-07-30T07:56:47Z")

</div>

Yes i was using CubeIDE v1.4.0. I have downloaded CubeIDE v1.3.0 and now everything works.  
Thanks everybody.
