EmbeddedRelated.com
Forums

Fixes to use C++ with Code Composer Essentials

Started by John Heenan June 13, 2007
No one took me up on my offer to post information on using C++ with
CCE. Here they are anyway.

The interrupt macros with CCE V2.0 as shipped don't work in C++
files. Also C++ global class instances with constructors will cause
failure without a JTAG debugger with CCE V2.0 as shipped.

Also using C++ template classes causes a warning about a
missing .template section.

Below are the fixes.

By default CCE does not enable RTTI (run time type information) and
C++ exception handling.

If you use your own classes and avoid the C++ library and STL then
overhead with using C++ can be managed and the huge benefits of using
C++ for managing complexity can be taken advantage of.

All that is required to use C++ is to rename your file with .cpp
extension. CCE C++ will warn if the main definition is 'void main'
instead of 'int main' but does not complain if there is no return at
the end of main.

1. Fix for interrupt macros

Add the following after calling the include file for the processor
#if defined __TI_COMPILER_VERSION__ && defined __cplusplus
#undef CREATE_VECTOR
#undef PLACE_VECTOR
#undef ISR_VECTOR
#define CREATE_VECTOR(name) extern void (* const VECTOR_NAME
(name))(void) = &name
#define PLACE_VECTOR(vector,section) EMIT_PRAGMA(DATA_SECTION
(section))
#define ISR_VECTOR(func,offset) PLACE_VECTOR(VECTOR_NAME(func),
offset) \
CREATE_VECTOR(func);
#endif
2. Fix for failure for global C++ class instances with constructors.

Edit the linker .cmd file to change

.pinit : {} > RAM /* C++ CONSTRUCTOR
TABLES */

to

.pinit : {} > FLASH /* C++ CONSTRUCTOR
TABLES */
3. The fix for the missing .template section is to add the following
line to .cmd linker file
.template : {} > FLASH

John Heenan

Beginning Microcontrollers with the MSP430