CPP Problems with STM32Cube Library?

Hi there, I’m hoping someone can help me

I (misguidedly?) purchased a Nucleo L031K6 and was gratified to see that it had some level of support in PlatformIO but then went on to discover it’s so tiny that running Mbed framework is pretty much unfeasible (even bare-metal configuration doesn’t leave a lot of room for playing!)

So I thought I’d explore STM32Cube - it would be nice to have a few basic libraries and (ab)use the hardware - dump a few eeproms or use it as an SPI interface to a development board - I dunno. I’m just playing.

I met a really strange issue - I ported the STM32F… blinky project without too much hassle (code can be found on github: GitHub - majic79/Nucleo_L031K6_Blinky_C)

But I’m a C++ programmer - so I started to throw together a simple LED library to make a blinky CPP project and for the life of me I cannot get it to work. I took a step back and renamed my main.c to main.cpp and low and behold - same strange behaviour. It initialises but that’s about as far as it goes. It looks to me like HAL_Delay never increments, maybe Timer21 is not being started up?

If anyone would like to tell me which bonehead mistake I’ve made this time, please feel free - I’ve provided CPP source on github also: GitHub - majic79/Nucleo_L031K6_Blinky_CPP

Start with this example: platform-ststm32/examples/stm32cube-hal-blink at master · platformio/platform-ststm32 · GitHub

And when you switch from C to C++, you will have to declare all interrupt handlers and all other overridable functions as extern "C", e.g.:

extern "C" void SysTick_Handler(void)
{
  HAL_IncTick();
}
1 Like

Thank you @manuelbl - that was just the nugget of information I was looking for!

As soon as I updated, it started working perfectly! I’ve updated my project - so if anyone wants an example blinky, feel free to take a fork or abuse for your own needs