cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and Atollic: C++ possible?

JOF
Associate II

Hello,

We are currently evaluating a replacement solution for our current microcontroller. STM32 is currently one of the favorite contestants.

The current software is written in C++ and uses alot of code that is pure C++, so no relation to the actual hardware used. In case of a replacement, we only would have to adjust the hardware commands like SPI Transmission command, if the new MCU would support C++. In case of only C support, we would have to re-write all of the C++ libraries followed by extensive testing. This would result in weeks of work and therefore cost.

When i took a look at Atollic, i noticed that is advertised as "Highly optimized C/C++". Sadly i noticed that CubeMx only creates C code, and the HAL-Libraries are all C. There are a lot of different tutorials on the internet that claim making Atollic Projects C++, but alot of them are get no response if its truly working.

So it tried the following steps:

1.) Generate Emtpy project with CubeMX

2.) Edit the .cproject file and add

<nature>org.eclipse.cdt.core.ccnature</nature>

3.) Edit the Projects->Properties->C/C++ General ->Paths and Symbols; copy all links from GNU C to GNU C++

4.) Rename Main.c to Main.cpp

5.) Restart, then build

I get alot of errors: just a few examples:

../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:253:25: error: 'GPIO_TypeDef' was not declared in this scope

../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:253:55: error: expected primary-expression before 'GPIO_Pin'

../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:254:74: error: expression list treated as compound expression in initializer [-fpermissive]

So it does not seem to work at all.

I tried to make a new project via File->New->C++ project and selected the microcontroller of choice. Then i'm getting a compilable C++ project but without the structure and the HAL-Library. It seems just to be another library there and the main looks very different.

It would be very good if it would be possible to convert a CubeMX Project to C++. The cube functionality doesn't have to work after the first start, since in case of change one could just use a text-diff to manually insert changes made in the cube project.

Hopefully someone here can help me with this. It would be superb to get C++ Project with Atollic :)

4 REPLIES 4

The compiler/linker should be capable, the startup code for the constructors might not be viable, or commented out.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

Cube-generated C stuff is just a small amount of low-level setup code. Leave it alone and write most of your application in beautiful C++.

C++ has been designed backward compatible with C exactly for this, so that you can use existing C code and libraries.

Unfortunately this backward compatibility does not work 100% because of various good reasons, so the C stuff must remain C and be compiled by the C compiler, not C++. Use extern "C" where needed.

Good luck.

-- pa

Bill Dempsey
Senior

Just wondering if you looked at the mbed implementation? ST supports most of their devices in C++ in mbed with low-level drivers remaining in ST HAL format. I prefer the agnostic mbed structure in general and use it for my ST projects. mbed lets you export the full project to other toolchains such as Atollic, GNU, IAR, etc.. Take a look and see if it works for you.

LKunz
Associate

Hi,

Did you take the test?

I am thinking on trying the same.

Best regards,