Tutorial: Creating Bare-bare Embedded Projects with CMake, with Eclipse included

MCU vendors offer SDKs and configuration tools: that’s a good thing, because that way I can get started quickly and get something up and running ideally in a few minutes. But this gets you into a dependency on tools, SDK and configuration tools too: changing later from one MCU to another can be difficult and time consuming. So why not get started with a ‘bare’ project, using general available tools, just with a basic initialization (clocking, startup code, CMSIS), even with the silicon vendor provided IDE and basic support files?

In this case, I show how you easily can do this with CMake, make and Eclipse, without the (direct) need of an SDK.

NXP LPC55S69-EVK with LoRa Shield

Outline

In this this tutorial I show how to create a ‘bare-bare’ project for the LPC55S69-EVK board, without the config tools and the SDK. I still use some copied files from the SDK as I don’t want to re-invent things, but these things are very generic and don’t force you to continue using the SDK if you don’t want. But you can continue later on using the SDK files too.

The project can be built from the command line, but I’m using Eclipse here as IDE too. Of course you can substitute Eclipse with anything else, as long as it is supports CMake, for example Visual Studio Code.

I’m using CMake in this tutorial, because in my experience many developers struggle using it, so I want to give them here an easy start as well.

As hardware I’m using the NXP LPC55S69-EVK board:

The project and files for this tutorial are on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_CMake_Template

The files on GitHub are can be used as a template for your own project.

I’m using Windows 10 as host machine, but you can easily use/adapt things for Linux/MacOS too.

If you want to see CMake with Eclipse for the Raspberry Pi Pico RP2040, I have covered you here: Getting Started: Raspberry Pi Pico RP2040 with Eclipse and J-Link. And if you want to use Visual Studio Code instead of Eclipse, I have a full series of tutorial for this as well: Visual Studio Code for C/C++ with ARM Cortex-M: Part 1 – Installation.

Software and Tools

I’m using the following software and tools:

Process

Assuming all the above tools are installed: The process and steps to create the project is very simple:

  • Copy the template folder and files
  • Run CMake initialization file to create make files and project files
  • Import the project into Eclipse

Template Files and Directory Structure

The files on GitHub serve as as template

Template files and folder

The template folder contains following files and folders:

  • src: contains all sources and CMake files for the project.
  • .gitignore: git ignore files
  • cmake.clean.bat: batch file to clean and remove all generated files
  • cmake.init.bat: batch file to create project files to be used with CMake and Eclipse
  • readme.txt: readme file with instructions and links

The ‘src’ folder of the template contains following:

Source Folder of Template

💡 The source folder ‘src’ has to be a sibling of the CMake output folder (e.g. ‘debug’) we will create later.

  • CMSIS: ARM CMSIS Core library files
  • device: device specific files, including linker file
  • startup: startup code files
  • arm-none-eabi-gcc.cmake: CMake toolchain definition
  • CMakeLists.txt: CMake project file
  • main.c: main() implementation

Creating Project

To create a new project from the template, simply copy the folder ‘LPC55S69_CMake_Template’. Of course you can work with that template folder directly too.

Changing Project Settings

The most important file and settings are in arm-none-eabi-gcc.cmake. Depending on your toolchain and location of it, you have to change/update the ARM_TOOLCHAIN_DIR variable in it:

ARM Toolchain Directory

The other thing likely to change is the project name: this is with the project() setting inside the CMakeLists.txt:

CMake Project Name

Initializing CMake project

Then open a console in that folder and run the ‘cmake.init.bat’ batch file: This initializes all the CMake files, creates the Eclipse project file and creates a ‘debug’ folder for the output:

C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake>cmake.init.bat
C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake>mkdir debug
C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake>cd debug
C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake\debug>cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_VERSION="4.5" -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j8 ../src
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Eclipse version is set to 4.5. Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe
-- CMAKE_TOOLCHAIN_FILE is: C:/Users/erich/Data/GitRepos/McuOnEclipse/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_CMake/src/arm-none-eabi-gcc.cmake
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/erich/Data/GitRepos/McuOnEclipse/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_CMake/debug

C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake\debug>cd ..

C:\Users\erich\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\LPC55S69-EVK\LPC55S69_CMake>

Building

To build the project from the command line, ‘cd’ into the ‘debug’ folder and run the make file:

Building with the Console

Eclipse IDE

Beside of building from the command line (which is great for automation of the build process), I can use an IDE like Eclipse.The generated CMake project is usable with an Eclipse based IDE like the NXP MCUXpresso IDE.

The IDE itself is not used to create the CMake project. Instead, the Eclipse CDT project is crated by CMake and then imported into Eclipse.

To import the project into the IDE, use the menu File > Import:

Import Menu in Eclipse

Import as ‘existing project’:

Import existing Project

In the next step, make sure you select the project in the build output (debug) folder and press finish:

Import the generated Eclipse project in the debug folder

With this, the project is added to the Project Explorer:

Imported project in the Eclipse Explorer

To build the project, use the ‘Build Targets’ which then generates all the different output files as specified in the CMakeLists.txt.

Build Makefile targets

For debugging, I can use the Eclipse CDT support for J-Link or the P&E Multilink.

There is a catch: the NXP LinkServer connection cannot be used directly (at least of now), because it depends on the SDK manifest information. So I recommend using a J-Link or P&E Multilink, or using a ‘dummy’ project for a LinkServer connection.

Because the MCU information is not coming from the SDK, I can specify it directly in the launch configuration:

J-Link Device Setting

With this, I can debug my target :-):

Summary

The power of CMake can be easily used with Eclipse, and allows full freedom of software and tools, including the SDK. The limitation of the MCUXpresso SDK to migrate projects between different SDKs can be simplified with the approach not to tie it to any SDK: instead, the project is just based on CMake, startup code and linker file. With this, the project is open to for any software addition or device changes, with simple changes in the CMake files. Best of all: both command line tools (without any IDE) can be used with this approach, but everything is accessible with an IDE too. Kind of using the best of both worlds :-).

Happy bare-baring 🙂

Links

10 thoughts on “Tutorial: Creating Bare-bare Embedded Projects with CMake, with Eclipse included

  1. Thanks Erich, that’s a very useful article.

    If one modifies CMakeLists.txt, perhaps by adding additional source files, is it necessary to reimport the project into Eclipse?

    Liked by 1 person

    • Hi David,
      you only have to import the project one time. If you are adding source files, simply edit the CMakeLists.txt (add it), then run make: the project will be automatically reconfigured, so no need to re-do an import :-).

      Like

      • Hi Erich, thanks for your reply. I’m not able to do the import in the way you show above.

        Your screenshot of the Import Projects dialog shows:

        “Select a directory to search for existing Eclipse projects”

        Instead mine shows:

        “No projects are found to import”

        Mine seems reasonable as the CMake build directory doesn’t contain Eclipse project files. So no import is possible.

        Any thoughts please?

        Liked by 1 person

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.