Skip to main content
Visitor II
July 11, 2025
Solved

HardFault_Handler when call prvPortStartFirstTask() in STM32H753

  • July 11, 2025
  • 3 replies
  • 958 views

I’m using NUCLEO STM32H753ZI.
I use ST ID: STM32cudeIDE
I have HardFault_Handler when call vTaskStart_Scheduler() using FreeRTOS

Could you please let me know how to resolve this issue?

hardfault.jpg

Below is the sample code

int main(void)
{

(void) HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Enable the CPU Cache */
CPU_CACHE_Enable();

BaseType_t xReturned;
TaskHandle_t xHandle = NULL;

/* Create tasks /
xReturned = xTaskCreate(
Task_Code,
“SB”,
configMINIMAL_STACK_SIZE,
(void) NULL,
tskIDLE_PRIORITY+2U,
&xHandle
);
if( xReturned == pdPASS )
{
vTaskStartScheduler();
}
else
{
}
while(1);
    This topic has been closed for replies.
    Best answer by EddiePark

    Hi.

    What should I do when I change like below?

    #define SFU_ISOLATE_SE_WITH_MPU -> #undef SFU_ISOLATE_SE_WITH_MPU

    Hardfault happens when I change like above.

     

    1.jpg

    3 replies

    Technical Moderator
    July 11, 2025

    Hello @EddiePark 

    Could you increase your heap and stack size and try again?

    EddieParkAuthor
    Visitor II
    July 11, 2025

    Hi,

    I increase the heap and stack size. but the result is same.

    Thanks

    Technical Moderator
    July 11, 2025

    Hello @EddiePark 

    Please refer to the article below to debug hardfault: 

    How to debug a HardFault on an Arm® Cortex®-M STM3... - STMicroelectronics Community

    Super User
    July 12, 2025

    From the screenshot it looks like SFU software is involved, and the hard fault is expected. Have you tried to continue and let it recover?

    EddieParkAuthor
    Visitor II
    July 12, 2025

    Hi.

    I know what is problem for this issue.

    But I don't know how to resolve this issue.

    In case of normal, the api is called as the below.

    Could you please let me know how to resolve this issue?

    vTaskStartScheduler -> xPortStartScheduler -> vPortSVCHandler

    void vPortSVCHandler( void )

    {

    __asm volatile (

    " ldr r3, pxCurrentTCBConst2 \n"/* Restore the context. */

    " ldr r1, [r3] \n"/* Use pxCurrentTCBConst to get the pxCurrentTCB address. */

    " ldr r0, [r1] \n"/* The first item in pxCurrentTCB is the task top of stack. */

    " ldmia r0!, {r4-r11, r14} \n"/* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */

    " msr psp, r0 \n"/* Restore the task stack pointer. */

    " isb \n"

    " mov r0, #0 \n"

    " msr basepri, r0 \n"

    " bx r14 \n"

    " \n"

    " .align 4 \n"

    "pxCurrentTCBConst2: .word pxCurrentTCB \n"

    );

    }

    But hard fault happens when SVC_Handler api is called in sfu_se_mpu.s file

    ===sfu_se_mpu.s======

     

    .section .text,"ax",%progbits

    .syntax unified

    .weak MPU_SVC_Handler

    .global SVC_Handler

    .type SVC_Handler, %function

    SVC_Handler:

    MRS r0, PSP

    B MPU_SVC_Handler

     

    Super User
    July 12, 2025

    Then there's some confusion between the SFU software you're using and FreeRTOS. I am not very familiar with SFU, perhaps it is not compatible with FreeRTOS, or assumes another flavor of FreeRTOS. In plain FreeRTOS the SVC handler vPortSVCHandler is invoked once, to start the scheduler. Here in sfu_se_mpu.s you have something different.

     

    EddieParkAuthor
    Visitor II
    July 14, 2025

    Hi.

    In current, I use "STM32H753_SBSFU\Projects\NUCLEO-H753ZI" demo project.

    I want to use xTaskCreate api from FreeRTOS.

    so I apply freertos to demo project.

    But vPortSVCHandler is not called in port.c of Freertos in when vTaskStartScheduler is called, 

    and hard fault happens "SVC_Hanlder" api is called in sfu_se_mpu.s

    Is there any way to resolve this issue?

    BRs.

    Eddie Park

     

     

    Super User
    July 15, 2025

    Yes this alone is easy to resolve: in FreeRTOS use some other unused interrupt vector instead of SVC. Not sure how this will interact with SFU.