cancel
Showing results for 
Search instead for 
Did you mean: 

HAL and C++

Alexey Prokopyev
Associate II
Posted on January 25, 2015 at 01:02

Hello.

When do you plan to support C++ for HAL library STM32L1xx ?

#hal #stm32l1xx #c++
9 REPLIES 9
carl2399
Associate II
Posted on January 25, 2015 at 07:10

C code (in compiled object form) can be linked to C++, so in some ways this seems to be not a question, as there is nothing to do.

The only requirement for C header files is to have the function headers wrapped in extern ''C'', but this is already done in the HAL headers. This tells the C++ compiler to not use the name mangling. 

childresss
Associate II
Posted on January 25, 2015 at 07:24

For example, in IAR's EWARM, a compiler option for automatic compilation and linking of a mix of C and C++ programs is commonly used. The file names give the code type, i.e., .c versus .cpp.

Alexey Prokopyev
Associate II
Posted on January 25, 2015 at 09:57

Of course I know that. The cause of the problem was that I2C stops working if you use C ++ compiler (IAR 7.3).

After sending the slave address and receiving ACK, the controller pulls SCL to ground - and said that BUS BUSY. If the same code compiled with C, it works.

childresss
Associate II
Posted on January 25, 2015 at 10:10

Please clarify... ''when compiled with C'' rather than c++... do you mean you change the file's name to .c from .cpp? Or is the file named cpp and you have an extern ''C'' {} around the code in question?

Alexey Prokopyev
Associate II
Posted on January 25, 2015 at 10:43

HAL 1.0.0 for stm32l1xx already have extern ''C''. I just  change in the IAR project options Language: C to C ++. 

Alexey Prokopyev
Associate II
Posted on January 25, 2015 at 10:49

I do not rename sources to .cpp. Some of them (HAL and CMSIS files) are .c, my sources are .cpp.

In general, it is strange that it does not work I2C. Other HAL features - Timers, GPIO, NVIC, ADC work properly. Even USB CDC!

childresss
Associate II
Posted on January 25, 2015 at 19:46

Yes, I too have a mix of CMSIS/HAL .c sources and my own .cpp files.

With IAR, I leave the compiler configuration in ''auto' mode for C/C++ so the IDE will tell the compiler which mode to use. I don't try to force C or C++ mode rather than auto mode when there is a mix of C/C++ files.

Posted on January 25, 2015 at 22:12

When do you plan to support C++ for HAL library STM32L1xx ?

When a large commercial customer demands it?

With respect to your failure I'd suggest combing over the .MAP file and seeing if there are any I2C related name mangling issues that would break functionality.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Alexey Prokopyev
Associate II
Posted on January 26, 2015 at 18:27

Yes, auto mode solve the problem :)

Thank you,

0690X0000060Mn5QAE.gif