AnsweredAssumed Answered

Problem building SDK example with c++

Question asked by Nikolaj Rahbek on Feb 14, 2020
Latest reply on Feb 16, 2020 by jeremyzhou

Hello experts


I have problem building one of the demos form the LPC845 MAX SDK with cmake. Actually, everything works fine if I run the project as pure C. I have followed thie tutorial (see 'changes to the code' ad. 1 and ad. 2 below):

Tutorial: MCUXpresso SDK with Linux, Part 1: Installation and Build with Make | MCU on Eclipse 


I build the led_blink demo project, flash the elf with the "GUI flash Tool" in MCUXpresso IDE, and the led blinks as expected.


Then I have changed the name of the led_blinky.c to led_blinky.cpp, and update the cmake file accordingly. The project builds, but when I load the elf, the led just turns on, and stays on.


If I 'size' the two elf files, the text size of the elf generated from cpp is 4 bytes smaller.


When I dump the assembler code from the two elfs, it is very similar... I know similar is not good enough, unfortunatly my assembler skills are inadequate to tell anything from what I see. Two things though, the cpp version tends to have add some 'sxtb' around the code, and then there seem to be chunk of about 10 lines missing in 'SysTick_Handler()' (see 'Changes to the code' ad. 3).


Any ideas what is wrong and/or where I should look?




Changes to the code from the SDK

1) Since i'm running cmake version 3, I have added the following lines to the top of the cmake file:


cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
project(led_blinky VERSION 0.1.0 LANGUAGES C ASM)


2) For the newst cortex toolchain I had to remove the '--specs' options from the cmake file. All observation in this question is the is based on this change applied in both the C and C++ version.

Reference: ST Community 


3) The SDK does not build with c++. The problem is a de-reference of a null pointer that is allowed in C but not in c++. This error/feature is is fsl_clock.h. All observation in this question is the is based on this change applied in both the C and C++ version.

Reference: Problem building C++ projects with SDK 2.6.0? 


I changed from:

#define CLK_MUX_DEFINE(reg, mux) (((((uint32_t)(&((SYSCON_Type *)dummy_syscon)->reg)) & 0xFFU) << 8U) | ((mux)&0xFFU))
#define CLK_DIV_DEFINE(reg) (((uint32_t)(&((SYSCON_Type *)dummy_syscon)->reg)) & 0xFFFU)


#define CLK_MUX_DEFINE(reg, mux) (((offsetof(SYSCON_Type, reg) & 0xFFU) << 8U) | ((mux)&0xFFU))
#define CLK_DIV_DEFINE(reg) (offsetof(SYSCON_Type, reg) & 0xFFFU)