cancel
Showing results for 
Search instead for 
Did you mean: 

There is a plan to allow STM32cubeMX for generating main.cpp instead of .c only ?

dodonny
Associate III

Hi, I know this question have been asked several time, but STM32CubeIDE and STM32CubeMx are only generating .c file... this is very frustriating, time consuming and source of multiples error when working with cpp environment. We have to manually rename .c to .cpp file and vice et versa after each modification... this is so 1990 workflow.

Does this implementation have been planned in the future or shall I forget about it ?

Thanks for your reply.

16 REPLIES 16

I'm not opposing anything. I'm just pragmatic trying to work smoothly with material I've.

I'm ok could be more flexible and would be happy about for sure. On the other side sounds like to me like automation "drawback". Automation is very helpful but forcing some structure / way of working. Asking for automation and flexibility is most often leading to gaz plant (increasing options & buttons count, ... and in sync. bugs ...).

As summary what's important to me today is I'm not stucked despite I'm taking benefit of automation.

Thanks for your comments. ;)

dodonny
Associate III

My best workaround for the moment in eclipse STM32CubeIDE :

1) create main.cpp and main.hpp file right next to main.c and main.h (it's ugly, I know it)

1.1) don't forget to change your include "main.h" to "main.hpp"

2) exclude main.c from the compilation (right click on it > resource config > Exclude from build > check debug and release) > OK )

3) for any change made to you cubeMX config and applied to the file main.c (and main.h) you can use the compare function in eclipse to maintain the two files consistent

4 ) Select main.h and main.hpp for instance, and right clic on them > Compare with > Each other.

doddonny
Associate II

flag

jose luu
Associate III

Workaround starting with CubeMX 6.9.0 in Project Manager -> Code generator -> After code generation

 

 

Specify a .bat script located in Core/Src containing:

 

 

set SCRIPT_DIR=%~dp0%
cd %SCRIPT_DIR%
copy main.c main.cpp
del main.c

 

 

In -> Before code generation you also need the converse script, otherwise CubeMX will regenerate from scratch and will not take into account the modifications you may have done

 

set SCRIPT_DIR=%~dp0%
cd %SCRIPT_DIR%
copy main.cpp main.c
del main.cpp

 

 

As of 6.9.2 the script path as to be absolute (eg. C:\Users\...)

 

Is there a workaround for CubeIDE ?

Where can I insert the renaming scripts in the CubeIDE ?

RobertGrizilo
Associate II

This is my workaround and It's working fine.

Lets assume you have already renamed original main.c / main.h into main.cpp / main.hpp files.

1) in shell go to directory where your main.cpp is located

2) (on windows) mklink main.c main.cpp (you have to be admin)
    (on linux) ln -s main.cpp main.c

3) goto main.hpp directory

4) (on windows) mklink main.h main.hpp (you have to be admin)
    (on linux) ln -s main.hpp main.h

5) in STMCubeIDE after refreshing the project find main.c file and:
Right click on it > Resource config > Exclude from build > check debug and release) > OK

So now the compiler still works with fine as C++ project, and in Device Configuration Tool which uses only main.c/main.h files, it sees and modifies the original main.cpp/main.hpp file trough symlinks.