Unlike CodeWarrior, the Kinetis Design Studio (at least in V1.1.1) does not offer a choice between C and C++ projects. That makes sense with the GNU ARM Eclipse plugins, other than the CodeWarrior gcc integration, there is no need for setting up a special tool chain for C++ (see “Compiling C Files with GNU ARM G++“). While this is great, things are not perfect yet, so I’m providing in this post the information needed to properly setup a C++ project with Kinetis Design Studio V1.1.1.
With Kinetis Design Studio, I can create four types of project using the menu File > New > Kinetis Design Studio:
❗ The usual way in Eclipse to create a project with File > New > C Project of File > New C++ Project is not supported, as KDS is has implemented its own wizard.
The project type selection is implemented with two check boxes:
- Kinetis SDK
- Processor Expert
The combination of the two check boxes gives four different project types:
- Bare projects: no Kinetis SDK, no Processor Expert, just a plain project, available for all Kinetis devices: Both options
- Processor Expert projects, available for all Kinetis Devices listed
- Kinetis SDK projects (for devices where the Kinetis is supported)
- Processor Expert projects with Kinetis SDK (for Kinetis SDK devices)
Bare Projects with C++
If using C++ with a bare project type, then everything is setup correctly. You only need to make sure that header files included for C++ files are listed in the compiler include path settings:
If you are *NOT* seeing the C++ Compiler and Linker options (like below), then you probably have loaded a project from the KDS beta version. As the beta projects are not fully supported in the non-beta version of KDS, I recommend you create a new project in KDS V1.1.1.
Processor Expert Projects
The same point as above (C++ Include Path settings) apply to Processor Expert projects as well. However, there is the first issue with the provided startup code that the constructors for the static class objects are not called in startup.c:
Simply enabling __call_static_initializers() will not help, as this function is not defined :-(. Instead, the usual _start() function of the GNU library needs to be called. For this, I’m doing the following changes to the Processor Expert startup code:
- Add a prototype to _start() function
- Remove the zero_fill_bss() call, as this will be performed by the library in _start()
- Instead of calling main(), call _start() from the GNU library
That should it be. But wait! You might run into a hard fault 😦
💡 See “Oh my! An Interrupt…” how to generate an interupt handler for each interrupt vector, and “A Processor Expert Component to Help with Hard Faults” how to debug hard faults.
The issue is with the newlib-nano libraries in KDS which need an excessive amount of heap memory (see “Switching ARM GNU Tool Chain and Libraries in Kinetis Design Studio“). The solution is to add at least 1 KByte of Heap memory. This is configured in the Build options tab of the CPU component of the project:
With this, the project runs as expected and initializes all static object constructors.
Kinetis SDK Projects and Kinetis SDK with Processor Expert Projects
For Kinetis SDK projects (with or without Processor Expert), no other changes are needed as adding the C++ header file include paths, as for the bare projects. The Kinetis SDK startup code already calls _start(), and a heap size should be already configured. All good :-).
KDS with Launchpad and C++
If using KDS with the launchpad tools (see “Switching ARM GNU Tool Chain and Libraries in Kinetis Design Studio“), the GNU library code, it is necessary to add the following symbol __stack to the linker file:
__stack = _estack;
Otherwise there will be a crash during _start() function in the library.
While I do not need to select C or C++ project type during project creation, the current V1.1.1 Kinetis Design Studio created projects still need some tweaking to properly support C++ projects, most for the Processor Expert (only) projects as they use a different startup code. It is not clear why, but for sure the SDK startup code is handling things as it should be done. I hope the above steps help you to get C++ projects running with Kinetis Design Studio.
Happy C++ Constructing 🙂