cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up a C++ project for a NUCLEO-F446RE

drtarr
Associate II

Apologies for the newbie question, but I am trying to init a project with the following as starting point:

  • STM32CubeIDE v1.17.0
  • NUCLEO-F446RE
  • C++ Development
  • FreeRTOS
  • CAN Interface

 

When creating projects it looks like there's a lot of options, but I can't seem to get the combination of C++ and STM32CubeMX file for my NUCLEO board.  Two options I've tried for creating a project:

 

The New "C/C++ Project" with "C++ Managed Build" option:

drtarr_0-1733626887547.png

Produces a `hello-world.cpp` with the following contents:

 

 

 

#include <iostream>
using namespace std;

int main() {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	return 0;
}

 

 

However it has on specific build target, no STM32CubeMX .ioc file, or ld linker file.

 

The New "STM32 Project" with "C++" as the "Targeted Language" option:

drtarr_2-1733627144929.png

drtarr_3-1733627575605.png
drtarr_4-1733627678327.png

I get the STM32CubeMX .ioc file for the board but everything otherwise still looks like a C project. All the generated code is in C and the includes don't include anything C++ related.

 

Edit: Looking at the code closer it seems that maybe this is the structure of the C++ project, however, making a simple class definition it chokes on the the keyword 'class' so I suppose something is still wrong.  If someone could steer me towards the right documentation I think that's what I need.

 

Am I missing something? Also - I'm looking for good STM32CubeIDE tutorials but the 'Tutorial' playlist under STMicroelectronics Youtube channel has no voice over and is sorta useless IMO. So please feel free to direct me to the right materials.

Thanks

4 REPLIES 4
drtarr
Associate II

Specifically, the video tutorials linked in Help->Video tutorials are the ones I'm referring to.  They go quite fast and have no voice over, but also the hyperlink for the FreeRTOS one is broken:

drtarr_0-1733629298334.png

Instead it takes you directly to Azure RTOS TraceX

 

Pavel A.
Evangelist III

CubeIDE has user guide where you can find how to set up a C++ project. Just one thing: both .c and .cpp files can be in a c++ project. This is not a problem. In an extreme case, all files in a c++ project can be .c ))  And no, "class" keyword does not work in .c files ))

Please take your time, read and enjoy videos.  If the project is urgent and deadline is close, help can be found here.

 

 

 

Thanks Pavel - One follow up question though.  I understand I can rename main.c as main.cpp and include class objects, however, any changes to the STM32CubeMX configuration regenerates a new main.c, which I have to rename and then copy over all my user code in main.cpp to the new main.cpp and delete it.  Is there any way to avoid these extra steps?  It would be good if it just generated a main.cpp.

drtarr
Associate II

I seem to stumble upon the exact same issue as @Gaston, here:
https://community.st.com/t5/stm32cubeide-mcus/c-project-that-creates-c-main-file/td-p/124124

I 100% agree with him, seems silly that you can't make calls to any of the C++ code from the main loop and there's no workaround than changing the main.c extension, which breaks code generation.  I'm open to other ideas though.