Developing Apache Mynewt in Clion with quick and accurate indexing

It is not always possible to use a modern IDE for embedded software development. Sometimes your project uses a custom build system or a workflow that is hard to integrate with your favorite IDE. Apache Mynewt project has a modular design with features split into packages, dependencies and configuration files. It simplifies the architecture of the whole system and gives a lot of power to the user but also complicates the build process. To manage all of that a Newt tool was created. It is a smart build and package management system, that can handle multiple source repositories, decide what to include in a build and manage dependencies between components of the system. And one of it’s newer features is an integration with CMake.

Clion is a powerful cross-platform IDE for C and C++. It is easy to use, very responsive and supports tons of integrations. And it comes with vi emulation too! Most importantly, it uses CMake as a build system.

So now you can use Clion to develop Apache Mynewt applications!

We already described in this blog how to configure and use Eclipse with Mynewt. It is possible but requires some configuration. On the other hand, working on Mynewt in Clion requires almost no configuration.

How to work on Mynewt project in Clion

newt target cmake <target> command generates a CMakeLists.txt file for a specific target inside project root directory. This file contains all the CMake configuration options and a list of files to include in a build. You can then open the project inside Clion and the IDE should load the file correctly. Indexing in Clion is lightning fast! It takes just a few seconds and you are ready to start working on your project. You almost don’t notice it. If you need to change the target you are using, just run the command again with the new target and Newt will overwrite the CMakeLists.txt file. Clion will detect a change in this file and reindex your project. Just like that!

Indexing of a Mynewt project in Eclipse takes over a minute! So this is a huge improvement to your workflow. Another very important factor is the quality of indexing. Clion recognizes all the definitions and detects which files are included in the build and even which parts of the file are excluded. So you can jump to definitions, search by file or by symbol, refactor code, find usage and much more.

Building your project in Clion also works but you will still need to build and flash using Newt tool since both build processes are not yet equivalent.

Debugging Mynewt in Clion

You can also debug Mynewt in Clion but it requires a bit more configuration. You will need to create a GDB Remote Debug configuration inside Run/Debug Configurations window. Set the following fields:

  • GDB – a path to your gdb (e.g. /usr/bin/arm-none-eabi-gdb)
  • 'target remote' args – set it to tcp:localhost:3333
  • symbol file – a path to the symbol file for your target (e.g. <project_dir>/bin/targets/<target>/app/apps/<app>/<app>.elf)

Unfortunately, you will need to create a separate configuration for each target you want to debug.

Inside terminal run newt debug <target> -n – this will run gdb in server mode and will wait for the client to connect. Then in Clion select your debug configuration and click Debug button. That’s it!

Now you can develop your Apache Mynewt project inside a modern, powerful IDE with fast and accurate indexing.

Any questions?

Do not hesitate to contact us.

    Codecoup sp. z o.o.
    ul. Strzegomska 138
    54-429 Wrocław
    Poland
    +48 660 540 140
    hello@codecoup.pl
    Copyright © 2021 
    crossmenu