cancel
Showing results for 
Search instead for 
Did you mean: 

SW4STM32 and C++

mbmail4
Associate II
Posted on October 23, 2017 at 00:32

Hi Everyone.

I mostly work with a C environment when I create a STM32 project but in the last few days I have been

creating STM32 C++ projects by selecting a C++ project instead of a C project, and I can see in the

properties, tool settings, C++ parameters are there. Also I have created very simple classes and so far

the simple stuff works, but I have to rename my files from .C to .CPP extension otherwise

I cant include code from a (.c) file? and I cant call a function located in a (.cpp) file from a (.c) file?

The project I have created now has a uart serial class that has the usual transmit and receive routines plus the

interrupt handler. The problem is if I leave the interrupt service routine in the traditional stm32f0xx_it.c file

I can see that the ISR handler will be executed, but if I transfer the handler in one of the .C++ files

like within the serial class, I cant get it to work?

Similarly if I rename the stm32f0xx_it.c to stm32f0xx_it.cpp, again the handle will not executed.

Can anyone help out with a solution on how to call other functions from either file type or how to get

the ISR handler to be executed from within the serial class, or any c++ file?

Cheers

martin
2 REPLIES 2
Posted on October 23, 2017 at 01:26

C++ mangles names so you need to define your handlers thusly so they are bound to the Vector Table entries by the Linker

extern 'C' void USART1_IRQHandler(void)

{

  // Insert your code

}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mbmail4
Associate II
Posted on October 24, 2017 at 02:53

Thanks Clive, that did it, in fact it prompted me to look into this, so it was a good outcome.

Cheers

mb