Hacking Mynewt in Eclipse

Do you want to hack Apache Mynewt but do not know which IDE to use? Here is a short tutorial on how to configure Eclipse for working with Mynewt.

Using this setup you will have nicely working code indexer, integrated debugger and some other tools. Actually you will probably not need to use console anymore except for project configuration 🙂

Before you start, make sure you have Mynewt environment set properly and Eclipse CDT installed. This tutorial was created with Eclipse 4.21 (2021-09), but previous versions should work as well.

And final important note: it was tested on develop branch only.

Create project

First, you need to create new project in Eclipse:

  • Go to File → New → Project... and select Makefile Project with Existing Code
  • Enter project name and select location of your project created with Newt tool
  • Select <none> as toolchain
  • Click Finish

Now you should see your project in Project Explorer window.

I recommend to change default build configuration name to one matching target name in your Newt project. This makes working with multiple targets easier later in the process, but you can skip this if you e.g. work with only one target. In this case remember to adjust configuration accordingly (I mention this in the description where applicable). Build configurations name can be changed by going to Project → Propertes → C/C++ Build → Manage Configurations...:

Build and index

Now we can setup new project to build and index properly:

  • Go to Project → Properties
  • Go to C/C++ Build section
  • Open Builder Settings tab
  • Uncheck Use default build command
  • Set Build command to path to newt binary (can be newt only if tool is available in system search path)
  • Open Behavior tab
  • Set Build (incremental build) to build -l debug ${ConfigName}
  • Set Clean to clean ${ConfigName}
  • Click Apply

${ConfigName} will be replaced with the name of current build configuration so this will only work if you named build configurations as I suggested at the beginning. If you decided not to do this, simply replace ${ConfigName} with any valid target of your Newt project.

The -l debug option in the build command is important as it makes newt print debug logs during build process. These logs also include a complete command line for each command invoked. This is then used by build output parser to figure out build options for each file in the project so indexer can index file properly. The build output parser needs to be configured before it can understand debug logs from Newt:

  • Go to C/C++ General → Preprocessor Include Paths, Macros etc. section
  • Open Providers tab
  • Select CDT GCC Build Output Parser provider
  • Set Compiler command pattern to .*[DEBUG] arm-none-eabi-gcc
  • Select CDT GCC Built-in Compiler Settings provider
  • In Command to get compiler specs replace ${COMMAND} with arm-none-eabi-gcc

This step is necessary only if you decided to use multiple targets, as it fixes some issues with indexing when more then one target exist in your project:

  • Go to Entries tab
  • Select GNU C in Languages field
  • Select CDT User Settings Entries and click Add...
  • In drop-down selection on the left select Include Directory and on the right select Project Path
  • Set path field to bin/targets/${ConfigName}/generated/include (enter valid target name instead of ${ConfigName} if not using build configurations) and click OK

Finally, you may also tune some indexer settings to make sure only files included in the current build are indexed:

  • Go to C/C++ General → Indexer section
  • Check Enable project specific settings
  • Uncheck Index source files not included in the build
  • Uncheck Index unused headers
  • Uncheck Allow heuristic resolution of includes
  • Select Use active build configuration (this actually makes difference only if you use multiple build configurations, but it is worth checking it anyway)

And that's all. You can build and clean (Project → Clean...) your project as any other project in Eclipse. If everything was configured properly, you should see that .c files included in the build have custom settings captured from the build output parser and this means project should be nicely indexed:

No more errors due to unresolved stuff in code 🙂


Once you can write and build your code, it is time to debug. Start with creating new debug configuration for your project:

  • Go to Run → Debug Configurations...
  • Create new C/C++ Remote Application
  • Click Select other... link at the bottom to switch to manual GDB launcher
  • In the C/C++ Application you need to specify .elf for your application (which should be already filled in if you built your project already). However, you may want to make this one a bit more generic and let Eclipse figure out application binary configuration (i.e. current target ). In this case set it to bin/targets/${config_name:${project_name}}/app/apps/${config_name:${project_name}}/${config_name:${project_name}}.elf (yes, this is a single line of text 🙂 )
  • Select Disable auto build (optional, but soon you will see that having auto build enabled is not necessary)
  • Open Debugger tab
  • On Main sub-tab set GDB Debugger to arm-none-eabi-gdb
  • On Connection sub-tab set Port number to 3333

Before starting debug session in Eclipse you need to run GDB Server for selected target in shell console. This can be done in two ways:

  • newt run -n <target> 0 will build and load new image to your device, then start GDB Server
  • newt debug -n <target> will just start GDB Server

Note the -n parameter in both cases – this will stop Newt from running GDB in shell console.

Click Debug now and you will be switched to debug session. You may now want to reset your device to start debugging from beginning. To do this use Debugger Console window and execute interrupt, monitor reset and then continue (or just suspend from UI, execute monitor reset and then continue from UI).

To make things even easier, it is possible to launch both newt run and debug session with a single click in Eclipse – this way you do not need to switch to shell console every time you want to start debugging. Start by creating launcher for newt run:

  • Go to Run → External Tools → External Tools Configurations...
  • Create new program
  • Set Location to path to newt binary
  • Set Working Directory to location of your project, e.g. ${workspace_loc:/newt} (or use Browse Workspace... button)
  • Set Arguments to run -n ${config_name:${project_name}} 0 (enter valid target name instead of ${config_name:${project_name}} if not using build configurations)
  • On Build tab uncheck Build before launch option

Now you just need to define launch group which runs both newt run external tool and debug configuration:

  • Go to Run → Debug Configurations...
  • Create new launch group
  • Use Add... button to add two launch configurations
  • First add newt_run external tool
  • Secondly add debug configuration

Your final setup should look as on image below:

Now just use this launch group instead of plain debug configuration and you will not need to open shell when debugging Mynewt anymore 🙂

Any questions?

Do not hesitate to contact us.

    Codecoup sp. z o.o.
    ul. Strzegomska 138
    54-429 Wrocław
    +48 660 540 140
    Copyright © 2021