2019-10-10 12:12 PM
2020-08-11 04:33 AM
I would also like to know this, I'm using a library that is C++ and you can change the main.c to main.cpp but if you have some functionality in main.cpp already it's a bit of a pain..
2020-08-11 04:35 AM
I guess the work around would be to change the cpp file to a c file then changing it back to a cpp file using F2(rename) after you have made the changes in .ioc
2020-08-11 05:02 AM
When creating your project, choose C++ as targeted language for your STM32 project.
Add 2 new files to your project. maincpp.h and maincpp.cpp. In maincpp.h you include main.h and declare two extern "C" functions: setup() and loop() which you implement in maincpp.cpp using C++. In main.c include maincpp.h and call setup() in a user code section right before the main loop and loop() in a user code section within the main loop. Now you have separated generated C code from your own C++ code.
Note that C++ may generate more code and some C++ libs use dynamic memory heavily which might cause issues.
2020-09-03 05:10 AM
I opened up a vote here: https://community.st.com/s/ideazone#0873W000000PAsrQAG
2020-09-03 05:16 AM
Hi,
I am using this approach even vor my C projects at work. I have an appmain.c/h and just call their app_init() and app_loop() from CubeMX's main.c.
I still need to test this with C++ at home.
And of course you need to be careful with what C++ features you use. E.g. most of the STL data structures are off the table ... There are some people writing or talking about this topic on the internet. ... I hope I can get my hands on that topic for real soon. :)
Cheers