I'm road testing the  Ultra-Low Power Arm Cortex-M4 Darwin MCU EVM.

In this posts I show how to create a C++ project.

 

 

Maxim has a tutorial that explains how to create an Eclipse project from scratch. It is for the MAX3263X but works perfectly for the MAX32660.

When you follow the instructions, you get a brand new C project.

I would like to create an object oriented example, so I tried the procedure, with as only difference choosing a new C++ Project instead of C project.

There are a few fixes you have to do to make the build and debug system work with the C++ sources.

 

Differences

 

The MAXIM tutorial tells you to create a C project. Create a C++ Project instead:

 

Perform all other steps as indicated in the tutorial. For the debug configuration, it's easier to just copy one from another MAX32660 project and edit all project references.

 

Makefile fixes

 

An obvious difference is that you have to replace main.c with main.cpp:

 

# Source files for this test (add path to VPATH below)
SRCS  = main.cpp

 

More subtle is that, when you try to debug the project, the debugger can't find the debug symbols and source file.

That's because in the MAXIM toolchain, there are a few inconsistencies between how C and C++ files are compiled.

The one that bites us, is that the C++ settings don't include debug symbols (-g3 -ggdb -DDEBUG).

 

It took me a while to find out why the debug info was not there for C++ files.

MAXIM uses a custom make file, so most settings in the Eclipse project are ignored and are defined in the make configuration.

 

I saw in the build console that the 3 switches were omitted for my .cpp file:

 

switches used for C++:

arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -O1 -ffunction-sections -fdata-sections -MD -Wall -Wno-format -fno-rtti -fno-exceptions -std=c++11 -c  -DTARGET=32660 -DTARGET_REV=0x4131                  -DMXC_ASSERT_ENABLE -DRO_FREQ=80000000 -I. -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/Include -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/../Include -ID:/Maxim/Firmware/MAX32660/Libraries/MAX32660PeriphDriver/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Device/Maxim/MAX32660/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Include -o /d/users/jancu/workspace_eclipse_maxim/max32660_barometer_cpp/build/main.o main.cpp

 

switches used for C:

arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -O1 -fsingle-precision-constant -ffunction-sections -fdata-sections -MD -Wall -Wdouble-promotion -Wno-format -c -fno-isolate-erroneous-paths-dereference -DTARGET=32660 -DTARGET_REV=0x4131 -g3 -ggdb -DDEBUG -DMXC_ASSERT_ENABLE -DRO_FREQ=80000000 -I. -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/Include -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/../Include -ID:/Maxim/Firmware/MAX32660/Libraries/MAX32660PeriphDriver/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Device/Maxim/MAX32660/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Include  -o /d/users/jancu/workspace_eclipse_maxim/max32660_barometer_cpp/build/board.o /D/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/Source/board.c

 

Then it took me a while to find out why this was different.

The project's make file does not have anything that can influence this.

But that makefile includes a MAXIM specific makefile:

 

################################################################################
# Include the rules for building for this target. All other makefiles should be
# included before this one.
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk

 

This resolves to <your drive>:\Maxim\Firmware\MAX32660\Libraries\CMSIS\Device\Maxim\MAX32660\Source\GCC\max32660.mk.

Again, in that file there's nothing to explain this behavior. But this one also includes a makefile:

 

# Include the rules and goals for building
include $(CMSIS_ROOT)/Device/Maxim/MAX32660/Source/GCC/gcc.mk

 

And that makefile, in the same directory as the one above, is the bad guy:

 

ifneq "$(TARGET_REV)" ""
CFLAGS+=-DTARGET_REV=$(TARGET_REV)
CXXFLAGS+=-DTARGET_REV=$(TARGET_REV)
endif

# Exclude debug for 'release' builds
ifneq (${MAKECMDGOALS},release)
ifneq (${DEBUG},0)
CFLAGS+=-g3 -ggdb -DDEBUG
endif
endif


CFLAGS+=$(PROJ_CFLAGS)
CXXFLAGS+=$(PROJ_CFLAGS)

 

On line 09 above, you can see that the debug options are only set for the C compiler variable CFLAGS.

They forgot to also do this for CXXFLAGS.

 

This can be fixed without changing MAXIM's SDK. You can adapt the projec's makefile to add the switches:

 

###############################################################################
# Include the rules for building for this target. All other makefiles should be
# included before this one.
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk

#jc 20181216: also enable debug info for C++
# Exclude debug for 'release' builds
ifneq (${MAKECMDGOALS},release)
ifneq (${DEBUG},0)
CXXFLAGS+=-g3 -ggdb -DDEBUG
endif
endif

 

After doing that, everything works:

 

arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wa,-mimplicit-it=thumb -O1 -ffunction-sections -fdata-sections -MD -Wall -Wno-format -fno-rtti -fno-exceptions -std=c++11 -c -DTARGET=32660 -DTARGET_REV=0x4131 -DMXC_ASSERT_ENABLE -DRO_FREQ=80000000 -I. -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/Include -ID:/Maxim/Firmware/MAX32660/Libraries/Boards/EvKit_V1/../Include -ID:/Maxim/Firmware/MAX32660/Libraries/MAX32660PeriphDriver/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Device/Maxim/MAX32660/Include -ID:/Maxim/Firmware/MAX32660/Libraries/CMSIS/Include -g3 -ggdb -DDEBUG -o /d/users/jancu/workspace_eclipse_maxim/max32660_barometer_cpp/build/main.o main.cpp

 

The debug symbols are found and you can step through the code.

 

 

The binary - with debug symbols - is 10 K bigger than the C version. 568 K vs 558 K.

I haven't built a release version. I don't know how big the difference will be.

 

part 1: IDE install and Build First Example
part 2: Mod the PCB for Power Measurement
part 3: Power Measurement
part 4a: Low Power Sensor design - Barometer Hardware
part 4b: Low Power Sensor design - Barometer i2c and Init
part 4c: Low Power Sensor design - Barometer, Not Yet Power Optimised
MAX32660 Evaluation Kit - part 5: FreeRTOS Example
side note A: C++ Eclipse Project
side note B: Create a Release Configuration