Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Failed to catch c++ exceptions

Hey guys
I did convert my cubemx generated C project to a c++ project using SW4STM32 convert function.
However i’m not able to catch exceptions.

volatile int test = 0;
try
{
throw 1;
}
catch (const int& ex)
{
for (;;)
{
test++;
test += 99;
}
}

this very simple code always ends up in the termination handler instead of the catch phrase.
I’m using an STM32F429
I removed all noexception flags from the compiler and linker. I even added an exception flag, but still no success.

My GCC compiler flags:
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 ‘-Dweak=attributeweak’ ‘-Dpacked=attributepacked’ -DUSE_HAL_DRIVER -DSTM32F429xx -Og -g3 -pedantic -Wall -Wextra -Wconversion -fmessage-length=0 -fexceptions -ffunction-sections -c -fmessage-length=0 -MMD -MP



My G++ Compiler flags
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 ‘-Dweak=attributeweak’ ‘-Dpacked=attributepacked’ -DUSE_HAL_DRIVER -DSTM32F429xx -Og -g3 -pedantic -Wall -Wextra -Wconversion -fmessage-length=0 -fexceptions -ffunction-sections -c -fno-rtti -MMD -MP
Finished building: ../Core/Src/User/test.cpp


My g++ Linker Flags
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -specs=nano.specs -fexceptions -Wl,--gc-sections -fno-rtti -o “SW4STM32_Exception_Test.elf” @”objects.list” -lm
Finished building target: SW4STM32_Exception_Test.elf


I tested the same code with True Studio. The exception catching works fine there. So the target is able to handle exceptions.
There must be some IDE setting with I missed.
Could you help me out please?

any ideas on my issue because i’d very much like continue using AC6. But this is for me a big issue. Without exceptions there is no decent c++ programming possible :-(

I’m having the same issue, and draw the same conclusion: Can’t do meaningful C++ development in the absence of exception handling.

I figured it out (just forgot to post the answer cry )

Try to remove the -specs=nano.specs from the linker flags. It looks like this is overwriting the exception enabling.
This worked for me ;)

Thanks, Julius, that appears to have done the trick.

 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs