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.
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:
- NXP MCUXpresso IDE v11.6.0: mcuxpresso.nxp.com/
- GNU ARM Embedded Toolchain v10 2020-q4-major: https://developer.arm.com/downloads/-/gnu-rm
- CMake version 3.22.5: https://cmake.org/
- GNU Make 4.3.90: https://www.gnu.org/software/make/manual/make.html
- NXP LPC55S69-EVK Rev A1: https://www.nxp.com/design/development-boards/lpcxpresso-boards/lpcxpresso55s69-development-board:LPC55S69-EVK
- Template files on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_CMake_T
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
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:
💡 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
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:
The other thing likely to change is the project name: this is with the project() setting inside the CMakeLists.txt:
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>
To build the project from the command line, ‘cd’ into the ‘debug’ folder and run the make file:
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 as ‘existing project’:
In the next step, make sure you select the project in the build output (debug) folder and press finish:
With this, the project is added to the Project Explorer:
To build the project, use the ‘Build Targets’ which then generates all the different output files as specified in the CMakeLists.txt.
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:
With this, I can debug my target :-):
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 🙂
- NXP MCUXpresso: mcuxpresso.nxp.com/
- NXP LPC55X69-EVK board: https://www.nxp.com/design/development-boards/lpcxpresso-boards/lpcxpresso55s69-development-board:LPC55S69-EVK
- CMake: https://cmake.org/
- Gnu Make: https://www.gnu.org/software/make/manual/make.ht
- Project on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_CMake_Template
- CMake with Raspberry Pi Pico: Getting Started: Raspberry Pi Pico RP2040 with Eclipse and J-Link
- CMake with Visual Studio Code: Visual Studio Code for C/C++ with ARM Cortex-M: Part 1 – Installation