cancel
Showing results for 
Search instead for 
Did you mean: 

''C'' STM32 ADC Project to ''Cpp'' (CubeMX)

Simon NOWAK
Associate II
Posted on September 12, 2017 at 10:32

Hi everyone,

I'm trying to convert a 'C' generated project with CubeMX in 'Cpp' but I have some problems with that. Indeed with CubeMX I have generate a project to read ADC values. This one work fine. The same project converted in Cpp compile but the value of the ADC is always the same ( 0 ).

Do you have any idea where this problem could come from ?

Thank you for your help and for your time.

Regards

Simon

#stm32l0 #cpp #eclipse #adc #cubemx

Note: this post was migrated and contained many threaded conversations, some content may be missing.
8 REPLIES 8
AvaTar
Lead
Posted on September 12, 2017 at 10:51

I would guess the interrupt routine names don't match.

C++ requires a extern 'C' to not mangle object names.

Posted on September 12, 2017 at 10:56

So I have to add the extern 'C' on all the libraries in my project ? 

Thank you for your help.
Posted on September 12, 2017 at 11:00

No, Specifically the IRQ Handlers described in the vector table, they are in an assembler file with weak linkage, you have to get the names right to use yours, the C++ names will be mangled.

And perhaps other things where the linkage fails.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 12, 2017 at 11:10

Thanks a lot for your help. 

So in my case the file 'stm32l0xx_it.c' contains the interrupt routine. I have to add the 'extern C' here ? 

I'm pretty new in this environment it's not easy ahaha.
Posted on September 12, 2017 at 11:15

C++ behaves like this on PC's too. When you mix C, C++ and Assembler, you need to be aware of name mangling.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 12, 2017 at 11:19

So I have to change some things on the project but also on the computer ?

Posted on September 12, 2017 at 11:26

In my first post, I refrained from commenting this idea to convert auto-generated C code to C++.

But seems it is not the best idea.

Redo all changes on every regeneration of the projects is not the most efficient way ...

I would either wait until Cube can do C++ projects, or stick with C.

Posted on September 12, 2017 at 11:32

Ah ok, scuse me...

I had not understood yourmessage in this way...

So for the moment it is not possible to make the ADC libraries work in a C++ project ?