Can't include mbed.h in ISR with compile errors

I have a project where I am combining STM32 HAL libraries and mbed. I have followed the various posts to get this working, and I have a basic example compiling and debugging OK.


I want to use an EventFlag in one of the ISRs (for a DMA). So I add:

#include “mbed.h”

into the ISR file to allow this. Just doing this act alone makes compilation fail with the following error:

I have tried using #include “stdlib.h” like others have suggested. That doesn’t fix the issue.

What should I do?

Hello John,

The “mbed.h” file includes also the “chrono” header file. Unfortunately, since the “chrono” is a C++ header file (a Standard C++ Library header) it’s impossible to include it into a C source file. You can try to rename the “stm32g4xx_it.c” to “stm32g4xx_it.cpp” but then you’ll face other sort of issues …

Best regards, Zoltan


This was indeed the issue. Thanks for the help.

After changing the stm32g4xx_it.c to stm32g4xx_it.cpp, the compilation succeeds, but the flash size of the binary is larger than 128k which exceeds what the G431RB part can support.

Any advice on how to reduce this down? I’m trying to use .mbedignore to take out quite a bit of the OS that I won’t be using, but none of my changes seem to have any effect on the build size.

do you need the RTOS? if not, you can use bare-metal, that will save some space.

@ladislas I would like to have threads for this application if possible.

You could try the new CMake build system, I’ve found that it can save quite a lot of space when compiling.

See mbed cli vs mbed tools bin size comparision · Issue #13974 · ARMmbed/mbed-os · GitHub

I learned a valuable lesson. Pulling out stdio and iostream drastically reduces the size of the binary. Thanks all for the input.