Skip to main content
JCOrtiz
Associate II
August 31, 2020
Solved

FREERTOS Default CubeMX Project HardFault

  • August 31, 2020
  • 3 replies
  • 2975 views

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.

This topic has been closed for replies.
Best answer by ZZida.1

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.

3 replies

JCOrtiz
JCOrtizAuthor
Associate II
September 1, 2020

Up please. I need help with this.

Tesla DeLorean
Guru
September 1, 2020

>>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 VenmoUp vote any posts that you find helpful, it shows what's working..
ZZida.1
ZZida.1Answer
Associate II
September 3, 2020

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.

JCOrtiz
JCOrtizAuthor
Associate II
September 3, 2020

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