Development with Eclipse and GCC

Updated version here (21.04.15): https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/

I have noticed that there have been several questions on development with Eclipse and GCC, and I have also been trying myself for quite some time to make it work properly. It finally seems like I have figured out an approach that works for me. I.e., successfully importing and debugging of example projects from the nRF51 SDK. So I thought I could make a blog post to share my setup and hopefully help others who are also new to Eclipse and GCC.

Inspired by other devzone users I found out that the easiest solution to setup Eclipse with debugging is probably by using the GNU ARM eclipse plug-in from http://gnuarmeclipse.livius.net/blog/. Regardless, it still it took me some time to get it all working so I have described my approach for importing and debugging SDK 6.0 exampe projects below.

Required tools:

Setting up Eclipse with register view

  • Start Eclipse

  • Click Help and select Install new software

  • Install embsysreqview

  • To install the register view file for Nordic Semiconductor devices copy file nrf51.xml to the folder eclipse\plugins\org.eclipse.cdt.embsysregview_x.x.x\data\cortex-m0\Nordic. nrf51.xml is located in SDK v.x.x.x\SVD.

Configuration step-by-step:

  1. First step is to make sure that the GNU ARM toolchain and Jlink are installed correctly by building and downloading an example project from SDK to a target. This is done by opening the command line in the gcc directory in one of the projects and type the 'make' command with the -f option to specify which makefile to use. After a successful build you should be able to flash your device by typing "make flash -f filename". Remember to flash softdevice beforehand with nRFgo studio when using example projects located in sXXX(softdevice) folders. image description
  2. Open Eclipse and install the GNU ARM plug-in like shown below. See http://gnuarmeclipse.livius.net/blog/ for more details. In my setup I chose to install the Cross compiler and J-link debugging support only, but the others can also be installed if needed.image description
  3. Import an example project from SDK by making a new "makefile project with existing code". The screenshot below does for instance show how to import the heart rate example. You can also choose the Cross ARM GNU toolchain if you wish to make a Nordic project from scratch with auto-generation of makefiles , just make sure to set the toolchain path is defined in your Eclipse environment. image description
  4. The project should now be visible in your workspace. Then right-click on the project folder and enter properties->C/C++ Build and change the build directory to the gcc folder. Unmark "Use default build command" and type "make" if it is not the default build command. image description
  5. Next we have to tell Eclipse what make option to use during build, which by default is set to 'all'. As defined in the Nordic makefile.common 'all' = 'clean' +'release'. We want to change that to 'debug' in order to enable debugging of the application. It is possible to set the make option by adding new targets to chose what you want to build, but I prefer to set the Build option like shown in screenshot below. This is to ensure that potential auto-build configurations does not suddenly start a build with an unexpected make option.

image description

  1. Next step is to rename the Makefile you want to use in the gcc folder. In my case "ble_app_hrs.Makefile" -> "Makefile". If it is preferred to keep the filename the "-f filename" option can be added to the build command instead. The compiler will otherwise not find the Makefile. Now you should be able to successfully build the project. However, despite the successful build you will see that there are several errors in the Eclipse project. This is because Eclipse is not able to automatically index the include files and symbols declared in the Makefile. I have not found an solution for this besides adding the paths and symbols manually. Debugging will still work without adding the paths and symbols manually as Eclipse is a pure IDE and gcc and gdb take care of the build and debug. However, I prefer to add the paths and symbols in Eclipse to better find declarations,references,etc. located outside main in the project. image description.

  2. Indexing or not, the application should be ready for a debugging now. First build the solution by right clicking on the project folder and press "Build project". Then enter tab Run-> Debug Configurations (Alternatively the bug icon in the toolbar) to set up the debug interface. Make sure that the C/C++ Application path is pointing to the .out file of the built.
    image description

Then set the correct device name in the debugger tab according to your target. See "Supported device name" if you are unsure. Next step is to edit the "jlink_path" variable. Change the path to your latest version of your Segger driver folder (../JLink_Vxx). Then set arm-none-eabi-gdb in the GDB client Setup. SWO can also be disabled under Startup tab as it is not supported by the nRF devices (will only give a warning).

image description

9.That is it. Here is the debug view of the heart rate example:image description

10.Flash downloading can be done with nrfjprog.exe directly from Eclipse. On the run menu, click 'External tools Configuration', select 'program', and then click 'new'. Then set the location of nrfjprog: C:\Program files (x86)\Nordic Semiconductor\nrf51\bin\nrfjprog.exe, and your current working directory: ${workspace_loc}//_build. Then the last step is to provide the nrjprog arguments for programming the hex file: --program{workspace_loc}//_build/.hex --reset. Clicking the 'run' button will then program application to the board.

Troubleshooting

Edit 8.4.2015 - Removed references to deprecated application note.

  • Thanks for the feedback! According to the plug-in webpage there is a bug in CDT that may cause the debug buttons to appear grey/disabled. I have seen it a few times when creating new workspaces, but that's it.

    Edit: I'm using CDT version: 8.4.0.201406111759. If you have an older version I suppose it might help to update it.

  • Thanks Vidar for this post! I installed eclipse a month ago and had many problems to get it to work. I should have had your post...

    I only have one problem left: I can only start and terminate the debugger about 3 times and then I have to restart eclipse all over again. Any sugestions?

    Jan Willem

  • Thanks for putting together this great resource!

    I also used this guide, after buying the book "Intro to BLE". It has this guide to setting up eclipse: github.com/.../nRF51822

    In addition to what you listed, I also took these steps:

    1. install Cygwin, MinGW, or something else so that make can be called. Then make sure the path variable is set to include the folder for make. For example: ;C:/Cygwin64/bin;

    2. Install GNU ARM tools to location with no spaces in the path (to avoid makefile issues). ex: C:\tools\GNU_Tools_ARM_Embedded\4.8_2014q2\bin

    3. Edit F:\Nordic Semiconductor\nRF51 SDK_v6.0.0.43681\Nordic\nrf51822\Source\templates\gcc\Makefile.Windows
      Make sure the the correct path and version is specified for the GNU ARM tools.
      GNU_INSTALL_ROOT := F:/tools/GNU_Tools_ARM_Embedded/4.8_2014q2/bin

    Then I could successfully build the example project.