cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler when call prvPortStartFirstTask() in STM32H753

EddiePark
Associate II

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);
1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

13 REPLIES 13
Saket_Om
ST Employee

Hello @EddiePark 

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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

Hi,

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

Thanks

Hello @EddiePark 

Please refer to the article below to debug hardfault: 

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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
Pavel A.
Super User

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?

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

 

Pavel A.
Super User

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.

 

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

 

 

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.

 

Hi Pavel.

I am using "STM32H753_SBSFU" demo project which is downloaded from ST.

But I want to use xTaskCreate api of freertos in this demo project.

Hardfault happens as the below.

Could you please me know how to resolve this issue?

svc.jpg