# HardFault \_Handler STM32F2 prvPortStartFirstTask

**URL:** <https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455>\
**Category:** Kernel\
**Created:** [March 6, 2024, 12:02pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455 "2024-03-06T12:02:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 6, 2024, 12:02pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/1 "2024-03-06T12:02:43Z")

</div>

I am just calling vTaskStartScheduler() after creating my tasks and get Hard\_Fault\_Handler when caused by prvPortStartFirstTask

 ![Captura de pantalla 2024-03-06 125810](https://d2v6vdsk2p900z.cloudfront.net/original/2X/4/4a4a3f2fb746a52760399fe76f5e7ccdd79fb985.png)  
I am compiling my project with Eclipse STM32F2, FreeRTOS202212.01 lwip1.3.2

Does anybody hace an idea of why is this happening?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 6, 2024, 12:50pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/2 "2024-03-06T12:50:11Z")

</div>

Do you change the priority of SVC? If yes, can you either not do so or ensure that it is highest priority? If not, can you step through the [prvPortStartFirstTask](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM3/port.c#L248) and see which line is causing the fault?

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 6, 2024, 1:12pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/3 "2024-03-06T13:12:13Z")

</div>

Hello, Yes I have the priority changed . Those are my values defined in FreeRTOSConfig.h

```auto
 /* This is the raw value as per the Cortex-M3 NVIC. Values can be 255
(lowest) to 0 (1?) (highest). */
#define configKERNEL_INTERRUPT_PRIORITY 255
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xb0, or priority 11. */
#if FREERTOS_V100400
#define configMAX_API_CALL_INTERRUPT_PRIORITY	191 //Same as configMAX_SYSCALL_INTERRUPT_PRIORITY renamed
#endif
/* This is the value being used as per the ST library which permits 16
priority values, 0 to 15. This must correspond to the
configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest
NVIC value of 255. */
#define configLIBRARY_KERNEL_INTERRUPT_PRIORITY	15

/* Stack overflow checking */
//#define configCHECK_FOR_STACK_OVERFLOW 2 //99? comprobar
#define INCLUDE_uxTaskGetStackHighWaterMark 1

#if FREERTOS_V100400

/* FreeRTOS MPU specific definitions. */
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
#define configTOTAL_MPU_REGIONS 8 /* Default value. */
#define configTEX_S_C_B_FLASH 0x07UL /* Default value. */
#define configTEX_S_C_B_SRAM 0x07UL /* Default value. */
#define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 1

#endif

```

In my module main.c I have the following:

```auto
 /* Pass the array into vPortDefineHeapRegions(). */
  vPortDefineHeapRegions( xHeapRegions );

  /* Relocate Vector Table in the FW address 0x08060000 0x08040000, after BOOT area */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, MAP_OFFSET); //0x60000 0x40000
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

```

When debugging I can see that the HardFault\_handler occurs when executing prvPortStartFirstTask() a SVC\_Handler() is executed and there my code call to vPortSVHandler() an occurrs de HardFault.

Previously I have the project working fine with FreeRTOS8.2.3 but the problems started when trying to upgrade…

Please tell me if I can provide more information to you to clarify what is happening.  
Thansk a lot in advance!

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 6, 2024, 1:23pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/4 "2024-03-06T13:23:46Z")

</div>

> [@Natara](#):
>
> Those are my values defined in FreeRTOSConfig.h

Can you share your complete FreeRTOSConfig.h?

> [@Natara](#):
>
> when executing prvPortStartFirstTask() a SVC\_Handler() is executed and there my code call to vPortSVHandler() an occurrs de HardFault.

Do you mean to say that prvPortStartFirstTask executes `svc` instruction and as a result, the control should to SVC handler (which is vPortSVHandler) but instead it goes to Hard Fault handler?

Can you try setting the SVC priority to 0? Should be possible by doing something like the following:

```auto
 NVIC_SetPriority(SVCall_IRQn, 0);

```

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 6, 2024, 3:00pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/5 "2024-03-06T15:00:33Z")

</div>

I am sorry but I am not sure I am undertanding properly I have the follwoing configuration

const HeapRegion\_t xHeapRegions =  
{  
{ ( uint8\_t \* ) 0x20002710UL, 0x1CCF0 }, // 118K  
{ ( uint8\_t \* ) 0x68000000UL+XRAM\_OFFSET, 0x1C000 }, // 112K  
{ NULL, 0 } /\* Terminates the array. \*/  
};

// Pass the array into vPortDefineHeapRegions().  
vPortDefineHeapRegions( xHeapRegions );

/\* Relocate Vector Table in the FW address 0x08060000 0x08040000, after BOOT area \*/  
NVIC\_SetVectorTable(NVIC\_VectTab\_FLASH, MAP\_OFFSET); //0x60000 0x40000  
NVIC\_PriorityGroupConfig(NVIC\_PriorityGroup\_4);

I am afraid that I can not share the file but I will try to paste the code here  
I have removed the comments to minimize the size…  
There are some sentences  
#if FREERTOS\_V100400  
#if FREERTOS\_2022  
are both symbols defined for the entire project that I created to be able to compile my project with different versions of FreeRTOS

#ifndef FREERTOS\_CONFIG\_H  
#define FREERTOS\_CONFIG\_H

#define configUSE\_PREEMPTION 1  
#if FREERTOS\_V100400

#define configUSE\_PORT\_OPTIMISED\_TASK\_SELECTION 0  
#define configUSE\_TICKLESS\_IDLE 0  
//#define configSYSTICK\_CLOCK\_HZ not needed //para micro ARM M3 no me hace falta  
//#define configIDLE\_SHOULD\_YIELD 1 //de momento no utilizo  
#define configUSE\_TASK\_NOTIFICATIONS 0 //can send receive task array notifications. New functionality not used yet

#define configTASK\_NOTIFICATION\_ARRAY\_ENTRIES 1 //for backward compatibility  
#define configUSE\_RECURSIVE\_MUTEXES 1

#define configQUEUE\_REGISTRY\_SIZE 0 //set 1 for debuggin queues adding names to queues…  
#define configUSE\_QUEUE\_SETS 1 //for block/pend multiple queues and semphores  
#define configUSE\_TIME\_SLICING 0 //Task scheduler executes highest priority task bat not switch between task of equal priority  
#define configUSE\_NEWLIB\_REENTRANT 0 //set to 1 if requiered. OJO Newlib is included in FreeRTOS but is not used by the FreeRTOS maintainers themselves

#define configENABLE\_BACKWARD\_COMPATIBILITY 1 //redefine vbles y funciones q se han cambiado de normbresi no compila poner a 1 es para declarar los defines para q sea compatible con ver pre 8.0.0

#define configNUM\_THREAD\_LOCAL\_STORAGE\_POINTERS 0 //new funtionality not used. Can be used to keep data in a task  
#if FREERTOS\_2022

#define configUSE\_MINI\_LIST\_ITEM 1  
#endif

#define configSTACK\_DEPTH\_TYPE uint16\_t //no need to use it.Can be used to define stack size when create a task

#define configMESSAGE\_BUFFER\_LENGTH\_TYPE size\_t  
#endif  
#if FREERTOS\_2022  
#define configHEAP\_CLEAR\_MEMORY\_ON\_FREE 1  
#define configSTATS\_BUFFER\_MAX\_LENGTH 0xFFFF

#define configUSE\_NEWLIB\_REENTRANT 0

#endif  
#define configUSE\_IDLE\_HOOK 0  
#define configUSE\_TICK\_HOOK 0

#define configCPU\_CLOCK\_HZ 120000000  
#define configTICK\_RATE\_HZ ( ( portTickType ) 1000 )  
#define configMAX\_PRIORITIES 7  
#define configMINIMAL\_STACK\_SIZE 256  
//#define configTOTAL\_HEAP\_SIZE ( ( size\_t ) ( 119 \* 1024 ) )  
#define configMAX\_TASK\_NAME\_LEN 16  
#if FREERTOS\_2022  
#define configTICK\_TYPE\_WIDTH\_IN\_BITS TICK\_TYPE\_WIDTH\_64\_BITS  
#endif

#define configUSE\_TRACE\_FACILITY 1  
#define configUSE\_STATS\_FORMATTING\_FUNCTIONS 1  
#define configUSE\_16\_BIT\_TICKS 0  
#define configIDLE\_SHOULD\_YIELD 1  
#define configUSE\_MUTEXES 1  
#define configUSE\_COUNTING\_SEMAPHORES 1

#define HEAP\_MINIMUM\_SIZE 0x500

#define configUSE\_MALLOC\_FAILED\_HOOK 0  
//#if FREERTOS\_V100400  
#if FREERTOS\_2022  
#define configSUPPORT\_STATIC\_ALLOCATION 0  
#define configSUPPORT\_DYNAMIC\_ALLOCATION 1  
#define configAPPLICATION\_ALLOCATED\_HEAP 0 //if used  
//#define configTOTAL\_HEAP\_SIZE 10240 not need for use of heap\_5.c  
#define configSTACK\_ALLOCATION\_FROM\_SEPARATE\_HEAP 0 //Natalia estaba a 0 pero puede venir bien No poner a 1 no compila  
#define configUSE\_IDLE\_HOOK 0  
#define configUSE\_TICK\_HOOK 0  
#define configUSE\_MALLOC\_FAILED\_HOOK 0  
#define configUSE\_DAEMON\_TASK\_STARTUP\_HOOK 0  
#define configUSE\_SB\_COMPLETED\_CALLBACK 0  
#define configCHECK\_FOR\_STACK\_OVERFLOW 2

#define configGENERATE\_RUN\_TIME\_STATS 0

#endif

#define configUSE\_CO\_ROUTINES 0  
#define configMAX\_CO\_ROUTINE\_PRIORITIES 0  
#if FREERTOS\_2022

#define configASSERT( x )   
if( ( x ) == 0 )   
{   
taskDISABLE\_INTERRUPTS();   
for( ; ; )   
;   
}  
#define configINCLUDE\_APPLICATION\_DEFINED\_PRIVILEGED\_FUNCTIONS 0

#define configTOTAL\_MPU\_REGIONS 8

#define configTEX\_S\_C\_B\_FLASH 0x07UL

#define configTEX\_S\_C\_B\_SRAM 0x07UL

#define configENFORCE\_SYSTEM\_CALLS\_FROM\_KERNEL\_ONLY 1

#define configALLOW\_UNPRIVILEGED\_CRITICAL\_SECTIONS 0

#define configUSE\_MPU\_WRAPPERS\_V1 0

#define configPROTECTED\_KERNEL\_OBJECT\_POOL\_SIZE 10

#define configSYSTEM\_CALL\_STACK\_SIZE 128

#define configENABLE\_ACCESS\_CONTROL\_LIST 1

#define configRUN\_MULTIPLE\_PRIORITIES 0  
#define configUSE\_CORE\_AFFINITY 0

#define configTASK\_DEFAULT\_CORE\_AFFINITY tskNO\_AFFINITY

#define configUSE\_TASK\_PREEMPTION\_DISABLE 0

#define configUSE\_PASSIVE\_IDLE\_HOOK 0

#define configTIMER\_SERVICE\_TASK\_CORE\_AFFINITY tskNO\_AFFINITY

#define secureconfigMAX\_SECURE\_CONTEXTS 5

#define configKERNEL\_PROVIDED\_STATIC\_MEMORY 1  
#endif

//#if FREERTOS\_V100400  
#if FREERTOS\_2022  
#define configUSE\_TIMERS 1 //1  
#define configTIMER\_TASK\_PRIORITY (configMAX\_PRIORITIES-1) //0 //3  
#define configTIMER\_QUEUE\_LENGTH 10 //0//10  
#define configTIMER\_TASK\_STACK\_DEPTH configMINIMAL\_STACK\_SIZE //0  
#endif

#define INCLUDE\_vTaskPrioritySet 1  
#define INCLUDE\_uxTaskPriorityGet 1  
#define INCLUDE\_vTaskDelete 1  
#define INCLUDE\_vTaskCleanUpResources 0  
#define INCLUDE\_vTaskSuspend 1  
#define INCLUDE\_vTaskDelayUntil 1  
#define INCLUDE\_vTaskDelay 1

#if FREERTOS\_V100400  
#define INCLUDE\_xResumeFromISR 0  
#define INCLUDE\_xTaskGetSchedulerState 0  
#define INCLUDE\_xTaskGetCurrentTaskHandle 0  
//#define INCLUDE\_uxTaskGetStackHighWaterMark 0  
#define INCLUDE\_xTaskGetIdleTaskHandle 0  
#define INCLUDE\_eTaskGetState 0  
#define INCLUDE\_xEventGroupSetBitFromISR 0  
#define INCLUDE\_xTimerPendFunctionCall 0  
#define INCLUDE\_xTaskAbortDelay 0  
#define INCLUDE\_xTaskGetHandle 0  
#define INCLUDE\_xTaskResumeFromISR 0  
#endif  
#define configKERNEL\_INTERRUPT\_PRIORITY 255  
#define configMAX\_SYSCALL\_INTERRUPT\_PRIORITY 191 /\* equivalent to 0xb0, or priority 11. \*/  
#if FREERTOS\_V100400  
#define configMAX\_API\_CALL\_INTERRUPT\_PRIORITY 191 //Same as configMAX\_SYSCALL\_INTERRUPT\_PRIORITY renamed  
#endif  
#define configLIBRARY\_KERNEL\_INTERRUPT\_PRIORITY 15

/\* Stack overflow checking \*/  
//#define configCHECK\_FOR\_STACK\_OVERFLOW 2 //99? comprobar  
#define INCLUDE\_uxTaskGetStackHighWaterMark 1

#if FREERTOS\_V100400

/\* FreeRTOS MPU specific definitions. _/  
 #define configINCLUDE\_APPLICATION\_DEFINED\_PRIVILEGED\_FUNCTIONS 0  
 #define configTOTAL\_MPU\_REGIONS 8 /_ Default value. _/  
 #define configTEX\_S\_C\_B\_FLASH 0x07UL /_ Default value. _/  
 #define configTEX\_S\_C\_B\_SRAM 0x07UL /_ Default value. \*/  
#define configENFORCE\_SYSTEM\_CALLS\_FROM\_KERNEL\_ONLY 1

#endif

#endif

Thanks in advance.  
I don’t know if is relevant or not but just to let you know I am compiling the project with Eclipse/arm-none-eabi-gcc and I am using WolfSSL and LWIP1.3.2

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 6, 2024, 3:23pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/6 "2024-03-06T15:23:44Z")

</div>

I am happy to inform that I am just allowed to add files. So please find attached FreeRTOSConfig.h- There you can fing FreeRTOS\_2022 and FREERTOS\_V100400 that are symbols globally defined for my whole project  
Please find attached as well port.c and portmacro.h files to integrate FreeRTOS with my ARM M3 micro: STM32F2 and project compiled with Eclipse arm-none-eabi-gcc  
[port.c](https://forums.freertos.org/uploads/short-url/224ZexfE0nroqKnyUSze4j2dlUM.c) (35.5 KB)  
[portmacro.h](https://forums.freertos.org/uploads/short-url/sZn2a4uNHfCAEqvsSMfb3nsyatM.h) (9.9 KB)  
[FreeRTOSConfig.h](https://forums.freertos.org/uploads/short-url/r9ii8Artu2Y1xY9Lb2Z8K6hQ88f.h) (30.5 KB)

Some of files of my project that may be relevant  
main.c /HWConf.c  
I would like to add that I am using LWIP and WolfSSL in my project as well  
[main.c](https://forums.freertos.org/uploads/short-url/hWgbtFX4PzilcnngpSf3KzRNSht.c) (22.4 KB)

[HWConf.c](https://forums.freertos.org/uploads/short-url/f8HJe3Ofosv5R3s6cnOva7uUP1U.c) (76.9 KB)  
Anymore information that could be useful please don’t doubt to ask.  
Thanks a million

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 6, 2024, 4:59pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/7 "2024-03-06T16:59:32Z")

</div>

Thanks for sharing these files. Nothing looks off at a first glance. Can you try the following:

1. Try executing SVC after relocating the vector table in main.c:

```auto
  /*Initialize Hardware System */
  InitializeSystem(ENABLE);
  __asm volatile( "svc 0" );

```

Step through the assembly and see if the control reaches vPortSVCHandler.
2. If the control reaches vPortSVCHandler in the first step and you do not see Hard Fault, remove the svc instruction and add it before starting the scheduler in main.c:

```auto
__asm volatile( "svc 0" );
/* Start the scheduler */
vTaskStartScheduler();

```

Step through the assembly and see if the control reaches vPortSVCHandler.
3. Remove the svc instruction.
4. Add the following code before starting the scheduler in main.c:

```auto
NVIC_SetPriority(SVCall_IRQn, 0);
/* Start the scheduler */
vTaskStartScheduler();

```

See if you still get Hard Fault.

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 7, 2024, 8:50am UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/8 "2024-03-07T08:50:39Z")

</div>

> [@aggarg](#):
>
> `__asm volatile( "svc 0" );`

Hello, thanks for your help

The first and the second try worked fine adding \_\_asm volatile(“svc 0”); but the last one I am sorry to tell you that I still get Hard Fault… When debuggin the SVCall\_IRQn has got the value -5

It seems to get Hard\_Fault and continue but it is not true has I see that the task are not really started… I add here a capture of what I can see may help you know what could be happening…

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/f/fdf6d332724ad1071e40986f8fb111578e9e1cfd.png)

Thanks a lot. I continue trying

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 7, 2024, 1:35pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/9 "2024-03-07T13:35:14Z")

</div>

I have tried to write NVIC\_SetPriority(SVCall\_IRQn, configMAX\_PRIORITIES); or NVIC\_SetPriority(SVCall\_IRQn, 0); before calling vTaskStartScheduler() but it is not working. I am still getting Hard\_Fault…  
Have you got any idea of why this could be happening? Could I give you more information about my project to help you know what I am doing wrong? I am a little bit lost

Thansk in advance

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [March 7, 2024, 2:25pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/10 "2024-03-07T14:25:37Z")

</div>

I would recommend reducing your application to blinky, ie deactivate everything related to Networking, peripheral etc, then make sure you get a single dummy task to work, then build up your sytem until you get the error. My suspicion is that one of your isrs faults as soon as interrupts are enabled.

Also, you can inspect the fault stack frame by dumping the memory r13 points to at fault handler entry. That gives you a little more info what happened.

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 7, 2024, 4:03pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/11 "2024-03-07T16:03:44Z")

</div>

Hello, I am trying to do what you are saying. I have created a small project with minimum initialized removing ethernet… and using FreeRTOS10.4.0 instead of FreeRTOS202212.0.01 but I having the same Hard\_Fault.

Does anybody knows it could be the compiling options?

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [March 7, 2024, 4:33pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/12 "2024-03-07T16:33:20Z")

</div>

When you are at the entry of the hard fault handler, dump your registers and dump the memory r13 points to. It contains the fault stack frame, among other things the address where it faulted. You can look up that address in your symbol table to determine the symptomatic fault cause.

You can look here fo reference: [How to debug a HardFault on an ARM Cortex-M MCU | Interrupt (memfault.com)](https://interrupt.memfault.com/blog/cortex-m-hardfault-debug)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 8, 2024, 9:13am UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/13 "2024-03-08T09:13:07Z")

</div>

This page also describes how to dump register in fault handler - [Debugging and diagnosing hard faults on ARM Cortex-M CPUs](https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html).

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 13, 2024, 2:01pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/14 "2024-03-13T14:01:52Z")

</div>

Hello, I have been looking at the pages you suggested trying to solve the problem, but I am stuck…  
I am thinking that the problem may be due to the heap configuration, could be?  
I wouls like to share with you the way I have it configurated is you could please have a look?  
[EditorIP\_WolfSSL\_Eclipse.7z](https://forums.freertos.org/uploads/short-url/jkzb3f9J4pOTEZL3YsI3ViBP9o0.7z) (156.9 KB)  
[HW\_UES\_ENCODER\_FP1.7z](https://forums.freertos.org/uploads/short-url/j6YSxcmJoq5aoW2A8ZXgTBEGYVa.7z) (17.4 KB)

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [March 13, 2024, 2:07pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/15 "2024-03-13T14:07:58Z")

</div>

is that the minimum code you reduced your system to to repro the problem, or again the full blown suite? If you want us to find the needle in your hay stack, make sure to make your hay stack as small as possible.

What exactly happened that made you discard the stack frame analysis?

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 13, 2024, 2:11pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/16 "2024-03-13T14:11:51Z")

</div>

I have shared the full project because I have created a reduced project with the minimun and it is not working but it is worst because I can not debug… that’s why I am sharing the whole one

OK. I am going to reduce and share a reduce version, without the ethernet part

---

<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:** [March 13, 2024, 9:20pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/17 "2024-03-13T21:20:24Z")

</div>

> [@Natara](#):
>
> Previously I have the project working fine with FreeRTOS8.2.3 but the problems started when trying to upgrade…

> [@Natara](#):
>
> #if FREERTOS\_V100400  
> #if FREERTOS\_2022  
> are both symbols defined for the entire project that I created to be able to compile my project with different versions of FreeRTOS

After all your changes to upgrade FreeRTOS, can you still build this codebase for kernel v8.2.3? And if so, does the application still work properly?

Just before executing `SVC 0`, function `prvPortStartFirstTask()` attempts to reset the main stack pointer MSP from the vector table. However, your application seems to be using a different vector table from the one the processor boots from. Does this application-specific vector table have a suitable value for MSP at offset 0 in the table?

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 20, 2024, 3:17pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/18 "2024-03-20T15:17:04Z")

</div>

Hi jefft,

Thanks for you help.

1. I have gone back to FreeRTOS v8.2.3 and it happens to me the same.

I changed my PC a month ago and I tried to put the same Eclipse Compiler,using arm-none-  
eabi-gcc compiler… but I am afraid that I have something wrong in my compiler.

When trying to compile for release: I am able to compile the problem but for being able to obtain the hex file “I have had to remove two keywords from the make file “-map” and “-info” and maybe there are important. but otherwise I get some problem”.

And if i try to compile for debug I see that the scheduller doesn’t start properly.  
unfortunately I am not able to recover my last configuration, as I haven’t got my old PC anymore…

1. Refering to what you are talking about MSP

I have the following code at my main.c  
/\* Allocate two blocks of RAM for use by the heap. The first is a block of  
0x10000 bytes starting from address 0x80000000, and the second a block of  
0xa0000 bytes starting from address 0x90000000. The block starting at  
0x80000000 has the lower start address so appears in the array fist. _/  
const HeapRegion\_t xHeapRegions[] =  
{  
{ ( uint8\_t \* ) 0x20002710UL, 0x1CCF0 }, // 118K  
{ ( uint8\_t \* ) 0x68000000UL+XRAM\_OFFSET, 0x1C000 }, // 112K  
{ NULL, 0 } /_ Terminates the array. \*/  
};

/\* Pass the array into vPortDefineHeapRegions(). \*/  
vPortDefineHeapRegions( xHeapRegions );

/\* Relocate Vector Table in the FW address 0x08060000 0x08040000, after BOOT area \*/  
NVIC\_SetVectorTable(NVIC\_VectTab\_FLASH, MAP\_OFFSET); //0x60000 0x40000  
NVIC\_PriorityGroupConfig(NVIC\_PriorityGroup\_4);

where I hope I tell the Compiler where is place my vector table:  
NVIC\_VectTab\_FLASH 0x08000000  
MAP\_OFFSET 0x00060000

so I think that should be right?

I am including here my compiler configuration …just in case you could find something wrong…  
[HW\_UES\_ENCODER\_FP1.7z](https://forums.freertos.org/uploads/short-url/8xQNj5KbnPD81a2S4d9sT7DgzOb.7z) (12.2 KB)

 ![-map -info removed](https://d2v6vdsk2p900z.cloudfront.net/original/2X/7/781f6dae8c91f05242253b5f0f0a58ce90441674.png)

Any more information please ask  
Thanks a million  
kind regards  
Natalia

---

<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:** [March 20, 2024, 6:08pm UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/19 "2024-03-20T18:08:25Z")

</div>

In `startup_stm32f2xx-XRAM.s`, there is some strange handling of the initial MSP value. (I assume you are using that file and not `startup_stm32f2xx.S`.)

As an experiment can you try removing [this line](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/625b24a104dd901d86759668b6b272590d154308/portable/GCC/ARM_CM3/port.c#L254) in `prvPortStartFirstTask()`. Or just comment it out like this:

` // " msr msp, r0 \n" /* Set the msp back to the start of the stack. */`

---

<div class="post-metadata">

**Author:** ![Natara](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/natara/32/4310_2.png) [@Natara](https://forums.freertos.org/u/Natara)\
**Post date:** [March 22, 2024, 7:30am UTC](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455/20 "2024-03-22T07:30:07Z")

</div>

> [@jefftenney](#):
>
> startup

Hi Jeff,

I am looking at my project definition an I think that I tell the linker use this -T"${ ProjDirPath }\startup\stm32\_flash\_xram\_4Mb.ld" file.

Please find attached the linker options I have…

 ![Linker_startup file](https://d2v6vdsk2p900z.cloudfront.net/original/2X/0/0d17b71701ca719ff9c3838a1e83d4d81d401309.png)

I don’t know how to check if I am using startuo\_stm32f2xx.S or startup\_stm32f2xx-XRAM.s… I will try to discover

I have just tried to debug the project removing //“msr msp, r0 \n” as you suggested for not setting the msp back to the start of stack

[Next page](https://forums.freertos.org/t/hardfault-handler-stm32f2-prvportstartfirsttask/19455.md?page=2)
