MQX C++ project in CodeWarrior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX C++ project in CodeWarrior

2,964 Views
neerav
Contributor II

Hello,

I want to develop a C++ project with TWR-K60D100M (MK60DN512VMD10 Kinetics MCU), using MQX(version 4.0.2). I am using the CodeWarrior v10.5. I have followed the procedure from this thread (EWL C++ in MQX.) and am able to build and run the cplus example application. I would now like to create a new project with the same settings and I am unable to do that so far. I have the following doubts regarding this problem:

1. Do I need to select the GCC or the Freescale option in the ARM build tools option while creating the project? What's the difference between the two? Is one better than the other for a c++ project?

2. I selected the GCC option because the cplus example project uses that. But there is no option to select the language while creating a new project and by default, project properties -> C/C++ build -> Settings -> tool settings shows the GCC C compiler instead of the GCC C++ compiler in the example cplus project. How can this be changed?

3. I tried doing what use c++ with/in mqx thread says, but there is no 'Force C++ compilation' option when the GCC compiler is selected and merely changing the filename from .h to .hpp seems rather hacky (or is it?).

Also, are there any other known issues of using MQX to write C++ projects (As this Re: Bug: Cpp Example - Global Object with new/malloc in Construct thread seems to suggest)?

I will be immensely grateful for any leads on these issues.

Thanks and regards,

Neerav

Tags (2)
5 Replies

1,187 Views
Carlos_Musich
NXP Employee
NXP Employee

HI Neerav,

Below you can find what worked for me.

1) Add the following macros in C:\Freescale\Freescale_MQX_4_1\config\<board>\user_config.h

o   #define MQX_SUPPRESS_FILE_DEF                      1

o   #define BSPCFG_ENABLE_CPP                                1

o   #define MQX_SUPPRESS_STDIO_MACROS        1 

MQX_SUPRESS_FILE_DEF disables definition of FILE. EWL has its own FILE with different meaning, thus, EWL should link with EWL’s FILE, MQX should link with MQX_FILE, but the linking order is only one – you either take FILE from MQX or from EWL. Therefore we disable, with this macro, MQX to define FILE. Then MQX has to use MQX_FILE and EWL can continue using EWL FILE.

BSPCFG_ENABLE_CPP enables EWL functions required when using c++.

MQX_SUPRESS_STDIO_MACROS  Similar as MQX_SUPRESS_FILE_DEF, stdio macros are different files (MQX_FILE) than EWL definitions, different pointer in memory and different structure members. Then, MQX must use its own definitions.

2) Now, stdin, stdout and stderr definitions must be redefined. To do this there are 2 options.

A)     The correct way would be to add the following macros in C:\Freescale\Freescale_MQX_4_1\mqx\source\include\fio.h. Recompile BSP and PSP (C:\Freescale\Freescale_MQX_4_1\mqx\build\cw10gcc\bsp_<board> and C:\Freescale\Freescale_MQX_4_1\mqx\build\cw10gcc\psp_<board>). Errors will appear, go to each of them and replace stdin for _mqxio_stdin and stdout  for _mqxio_stdout. Recompile again, no errors should appear this time.

o   #define _mqxio_stdin     (MQX_FILE_PTR)_io_get_handle(IO_STDIN)

o   #define _mqxio_stdout    (MQX_FILE_PTR)_io_get_handle(IO_STDOUT)

o   #define _mqxio_stderr    (MQX_FILE_PTR)_io_get_handle(IO_STDERR)

 

B)      A work around would be to force the project to use stdin, stdout and stderr by taking these defines out of the #if directive. With the default build settings the linker will use the MQX definitions, the side effect is that after recompiling BSP and PSP warnings will appear alerting that these macros are redefined.

1)   3) Now you can create a new C++ project. Go to menu > File > New > MQX4.1 Project and in the Wizard “Select Application type and template” window select Examples Application > Basic examples > cplus

     4) In menu Project > Properties > C/C++ Build > Settings > ARM Ltd Windows GCC C++ Compiler > Directories add "${MCUToolsBaseDir}/ARM_EABI_Support/ewl/EWL_C++/include" and put the below paths at the end of the Compiler Directories list.

o   "${MCUToolsBaseDir}/ARM_EABI_Support/ewl/EWL_C++/include"

o   "${MCUToolsBaseDir}/ARM_EABI_Support/ewl/EWL_C/include"

5) Then in menu Project > Properties > C/C++ Build > Librarian  check "Enable automatic library configurations" and choose "Model" = ewl_c++ / int / int.

6) Finally, if you replaced stdout  for _mqxio_stdout (in step 2) you need to do the same in cplus.cpp and build the project.

Hope this helps.

Carlos

1,187 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi,

I created a document with this information.

Creating a new MQX project using GCC C++

Regards,

Carlos

1,187 Views
charliemmao
Contributor II

Hi Carlos

I followed instructions recompiled libraries. When I create a project and import codes from IAREW project, I encounter many problems, such as "'printf' was not declared in this scope" for instance. How to resolve it please help!

Thanks and regards!

Charlie

1,187 Views
maciejwdowiarz-
Contributor III

I followed the same steps as above and also encountered problems with printf, e.g. inside FFS library.

Actually it should be

#define MQX_SUPPRESS_STDIO_MACROS 0

inside user_config.h. Otherwise there will be errors with printf functions (few libraries won't compile).

0 Kudos
Reply

1,187 Views
dkh
NXP Employee
NXP Employee

Hello,

I also would like to do this. I'm pretty sure you should select the GCC option it will be the compiler of preference moving forward.

Regards,

Dennis

0 Kudos
Reply