Skip to main content
Graduate
August 7, 2024
Question

HardFault with exceptions c++

  • August 7, 2024
  • 1 reply
  • 1146 views

Hello ST Community,

I'm working on implementing C++ exceptions in my project. My setup includes an STM32H735 board and I'm using FreeRTOS. Here’s a snippet of my code that involves try and catch blocks:

 

 

 

extern "C" void myTaskFunction(void* pvParameters) noexcept {
 try {
 	//throw exp seems work fine with debug 
 } catch (const std::exception& e) {
 // print something that I cant see in console
 }
 
 // HARDFAULT
	 
}

 

 

 

 

From my research, it seems that I need to disable the --specs=nano.specs option.

However, in the IDE, under Runtime library options, I have the following choices:

 

HispaEmo_0-1723017523728.png

 

  1. Standard C, Standard C++
  2. Standard C, Reduced C++ (--specs=standard_c_nano_cpp.specs)
  3. Reduced C, Standard C++ (--specs=nano_c_standard_cpp.specs)
  4. Reduced C, Reduced C++ (--specs=nano.specs)

With the first option, the compilation fails because it can't find the asserts. I'm currently using the third option, but I encounter a hard fault when exiting the catch block.

I've tried modifying the makefile, but some script seems to re-include the specs after building.

HispaEmo_1-1723017542009.png

 

I need guidance on how to avoid this error and properly handle exceptions. Any help would be greatly appreciated.


Thank you for your assistance.

Best regards,

Emo

    This topic has been closed for replies.

    1 reply

    Super User
    August 7, 2024

    Use Standard C, Standard C++ to enable exception handling. What asserts can it not find?

    Exception handling is typically not used on embedded platforms as it vastly complicates the code.