cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G484 HardFault_Handler

ErX
Associate II

Hi,

I got stuck in the HardFault_Handler every time after editing some code.

I'm using FreeRTOS in c++ combination with classes. First I thought this would be a memory issue.

After increasing configTOTAL_HEAP_SIZE and configMINIMAL_STACK_SIZE, I was still stuck in the HardFault_Handler. Even by jumping into a function, before I returned from this function the HardFault_Handler was tripped again.

I really tried a number of things...

I made a function (bool Controller::DefaultConfig()) to set the default configuration when nothing was available in the flash and I forgot the return true or false. When adding the return with a result, the problem with HardFault was solved.

 

Is this a logical behavior? (A compiler error would make more sense)

Greetings,

ErX

1 ACCEPTED SOLUTION

Accepted Solutions
CTapp.1
Senior III

@ErX wrote:

I made a function (bool Controller::DefaultConfig()) to set the default configuration when nothing was available in the flash and I forgot the return true or false. When adding the return with a result, the problem with HardFault was solved.

Is this a logical behavior? (A compiler error would make more sense)


You should get a compiler warning for this, but you may need to enable it in the project's settings.

  • -Wall (which I would recommend be turned on for all projects)
  • -Wreturn-type to catch only this issue.

As you are probably already aware, not having a return statement leads to undefined behaviour - which is one of the things that can lead to a hard fault being signalled.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)

View solution in original post

4 REPLIES 4
mƎALLEm
ST Employee

Hello,

How to debug a HardFault on an Arm® Cortex®-M STM32

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.
KnarfB
Super User

There is a fault analyzer in STM32CubeIDE and STM32Cube VS Code extension (Fault Status Register View) that gives you detailed insight about what exactly happened.

Segger has excellent stuff here Cortex-M Fault - SEGGER Knowledge Base.

FreeRTOS has options to get stack usage high watermarks during runtime (uxTaskGetStackHighWaterMark, uxTaskGetStackHighWaterMark2 - FreeRTOS™).

hth

KnarfB

Andrew Neil
Super User

In addition to the STM32-specific link from @mƎALLEm, here are some more general Cortex-M resources:

https://community.arm.com/support-forums/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
CTapp.1
Senior III

@ErX wrote:

I made a function (bool Controller::DefaultConfig()) to set the default configuration when nothing was available in the flash and I forgot the return true or false. When adding the return with a result, the problem with HardFault was solved.

Is this a logical behavior? (A compiler error would make more sense)


You should get a compiler warning for this, but you may need to enable it in the project's settings.

  • -Wall (which I would recommend be turned on for all projects)
  • -Wreturn-type to catch only this issue.

As you are probably already aware, not having a return statement leads to undefined behaviour - which is one of the things that can lead to a hard fault being signalled.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)