Skip to main content
Associate II
January 15, 2026
Solved

STM32G484 HardFault_Handler

  • January 15, 2026
  • 4 replies
  • 316 views

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

Best answer by CTapp.1

@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.

4 replies

mƎALLEm
Technical Moderator
January 15, 2026
"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
January 15, 2026

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
January 15, 2026

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
CTapp.1Best answer
Senior III
January 15, 2026

@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 capacityMISRA C++ ChairMISRA C WG MemberDirector The MISRA Consortium Limited (TMCL)