cancel
Showing results for 
Search instead for 
Did you mean: 

FREERTOS Default CubeMX Project HardFault

JCOrtiz
Associate II

Hi, I'm trying to execute a default CubeMX project for STM32F407 Disco with FreeRTOS. However, when I debug, it crashes with Hard Fault Handler, at the point of this function:

prvPortStartFirstTask();

So I can't start the system. I don't know why, if it's all by default.

1 ACCEPTED SOLUTION

Accepted Solutions
ZZida.1
Associate II

I've the same error. I tried to debug, what should be the problem, and I found the location of error in port.c prvPortStartFirstTask() function. Unfortunately it is an assembler function. I think so it is a stack problem,:

__asm volatile(

" ldr r0, =0xE000ED08 " /* Use the NVIC offset register to locate the stack. */

" ldr r0, [r0] "

" ldr r0, [r0] "

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

" mov r0, #0 " /* Clear the bit that indicates the FPU is in use, see comment above. */

" msr control, r0 "

" cpsie i " /* Globally enable interrupts. */

" cpsie f "

" dsb "

" isb "

" svc 0 " /* System call to start first task. */

" nop "

);

my fw version is 1.25.0. I tried with 1.24.0 also.

And finally I found this:

https://community.st.com/s/question/0D53W00000EmtEASAZ/stm32f407gdisc1-the-project-template-doesnt-work-with-rtos-stm32cubemx-60-lib-125

and that is the solution.

View solution in original post

4 REPLIES 4
JCOrtiz
Associate II

Up please. I need help with this.

>>So I can't start the system. I don't know why, if it's all by default.

Look at the processor registers and disassembly at the fault, not the C code.

Understand specifically what it is objecting too.

Use a Hard Fault handler that can output actionable data.

Most likely an address or function pointer that is incorrect.

Check task structure initialization.

Check stack pointer addresses and alignments.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ZZida.1
Associate II

I've the same error. I tried to debug, what should be the problem, and I found the location of error in port.c prvPortStartFirstTask() function. Unfortunately it is an assembler function. I think so it is a stack problem,:

__asm volatile(

" ldr r0, =0xE000ED08 " /* Use the NVIC offset register to locate the stack. */

" ldr r0, [r0] "

" ldr r0, [r0] "

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

" mov r0, #0 " /* Clear the bit that indicates the FPU is in use, see comment above. */

" msr control, r0 "

" cpsie i " /* Globally enable interrupts. */

" cpsie f "

" dsb "

" isb "

" svc 0 " /* System call to start first task. */

" nop "

);

my fw version is 1.25.0. I tried with 1.24.0 also.

And finally I found this:

https://community.st.com/s/question/0D53W00000EmtEASAZ/stm32f407gdisc1-the-project-template-doesnt-work-with-rtos-stm32cubemx-60-lib-125

and that is the solution.

Thank you a lot!!! Thanks!!! Now it's working.:grinning_face: