FREE “INTRO TO BLE” BOOK [HARDCOVER] →

The complete cross-platform nRF development tutorial

In a previous blog post (The complete nRF Mac development tutorial), I went over how to set up your nRF development environment using the NetBeans IDE on a Mac. The beauty with NetBeans is that it’s cross-platform and customizable to fit your needs. I had been using NetBeans for over a decade, so I was very comfortable with customizing and modifying the different settings and configurations to make it work. Unfortunately, the setup was quite lengthy and involved many changes to make it work, especially with on-target debugging. Even then, it wouldn’t work quite as well as I would like it to. Not to mention, the setup was different for each of the three main operating systems (Windows, macOS, and Linux).

I started searching for a better, more sustainable solution and I stumbled upon Segger Embedded Studio (SES). SES is a professional cross-platform IDE for ARM Core microcontrollers, including the nRF5x series chipsets from Nordic Semiconductor. Best of all, Nordic and Segger had recently announced a partnership where nRF developers can get a FREE commercial license to use SES without limitations! You can read more about the partnership announcement here.

In this blog post, I will go over:

  • How to set up and install Segger Embedded Studio for nRF development
  • How to enable logging and debug messages
  • How to configure the CMSIS Configuration Wizard plugin for easier sdk_config.h configuration
  • Tips and tricks for developing nRF applications with SES

Segger Embedded Studio (SES)

Segger is a well-known company in the embedded space that provides software, hardware, and development tools for embedded systems. Segger Embedded Studio (SES) is a professional cross-platform IDE for ARM Core microcontrollers. It compares to other professional IDEs in the space including ARM Keil and IAR (LINKs). Some of the advantages of SES include:

  • It provides a turnkey solution for development on the nRF52 series platform with seamless integration for on-target (on the device) debugging using J-Link.
  • It has integrated GCC C/C++ and Clang/LLVM compilers.
  • It provides cross-platform support: runs on Windows, Linux, and macOS.
  • There are no restrictions on code size and compiler optimization.
  • It integrates analysis tools for memory use, static code analysis and more.
  • It has tools for importing projects from other IDEs such as Keil and IAR.

For nRF5x developers, this is the most cost-efficient solution and provides features that compete with other professional IDEs such as Keil and IAR Embedded Workbench for ARM IDEs.

Setup for Windows, Linux, and macOS

Let’s go through the steps for setting up SES for nRF development on the different operating systems (Windows, macOS, and Linux). The steps below are pretty much identical for the three operating systems with minor differences.

Detailed Steps for Setting Up SES

  1. First, download Segger Embedded Studio from their website (look for the download that matches your operating system):
    https://www.segger.com/downloads/embedded-studio
  2. Launch the downloaded installation file and complete the installation.
  3. Download the latest nRF5x SDK:
    https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF5-SDK
  4. Unzip the SDK file to a known location on your computer.
  5. Download the latest version of Java for your computer (for macOS and Windows):
    https://java.com/en/download/
    For Linux, run the following command from a Terminal window:
    sudo apt-get install openjdk-8-jre
    We will need this for a plugin that runs within SES (the CMSIS Configuration Wizard).
  6. Once you have Java and SES installed, go ahead and launch SES.
  7. Now that SES is launched, we will open one of the examples provided with the SDK under the /examples folder.
  8. But before that, let’s enable showing all toolbars in SES to have a better user interface and to be able to perform operations more efficiently:
  9. Now let’s open the example named ble_app_hrs. Navigate to File → Open Solution.
  10. Navigate to this folder, and then select the folder for the nRF5 board that you are using. For this example, I’ll be using the nRF52840 Preview Development Kit which corresponds to the PCA10056 folder.
  11. Inside the folder PCA10056 (or whatever folder you need to choose for your development board), you will find a folder named s1xx which corresponds to the SoftDevice used for the development kit’s chipset. The SoftDevice is Nordic’s proprietary BLE stack (it also includes interfaces for the different hardware components of the chip).
  12. Inside the SoftDevice folder (s140 in my case), there’s a folder named ses. Open this folder and click on the *.emProject file. Click Open.
  13. Once you have the Solution open, you’ll be presented with the following screen:
  14. Now you can attempt to Build the project:
  15. If you do not already have an SES license, you will be prompted to register for a FREE commercial license (for nRF devices only) before you are able to build:
  16. Click the Get a Free License option, and then enter your information needed:
  17. Hit Request License.
  18. You should then receive the License information in your email.
  19. Copy the License key and Paste it into the Activation field:
  20. Once you enter the License key, click Close.
  21. The Project should now start building and (eventually) build successfully:
  22. Now you should be able to flash and run the application on your nRF development kit (nRF52840 in my case).
  23. Make sure you have the development kit connected to your computer with the following configuration:
    Note: I am using a MacBook Pro that does not have a regular USB connection, so the USB cable is connected to a USB-C adapter as you will see in the picture. In your case, you may have the USB cable connecting directly to your computer.

  24.  Once you have the development kit connected to the computer, you can run the application on the board.
    Click on the Start Debugging button:
  25. When the application is flashed to your development kit, it will stop at a breakpoint in main():
  26. Continue execution and run the application by clicking the Play button:
  27. To get a better idea of the state of the running application, we’ll enable logging so we can see any debug messages.

In order to do that, we’ll first set up a plugin that helps enable different settings within the SDK.

The sdk_config.h file

The sdk_config.h file includes different configurations and macro definitions that allow you to customize the SDK and application to enable various features. This file includes configurations such as:

  • Flags to enable certain modules to be included in an application (e.g. Central role, Peripheral role, Battery Service Client, and more).
  • Flags to configure and enable different hardware peripherals.
  • Flags to configure and enable logging and debugging.
  • Many others…

The file can be modified directly from the SES IDE Editor, using any generic text editor or via a plugin called the CMSIS Configuration Wizard (a Java-based add-on). This tool enables you to edit the options within the sdk_config.h file from a user-friendly interface instead of editing it within the raw source code. You will only have to do this step once.

To enable the CMSIS Configuration Wizard, follow these steps:

  1. Navigate to File → Open Studio File → External Tools Configuration
  2.  Once you’ve clicked on External Tools Configuration, the tools.xml file should now be open:
  3. After you have the tools.xml file open, add the following XML code before the </tools> tag:
    <item name="Tool.CMSIS_Config_Wizard" wait="no">
        <menu>&amp;CMSIS Configuration Wizard</menu>
        <text>CMSIS Configuration Wizard</text>
        <tip>Open a configuration file in CMSIS Configuration Wizard</tip>
        <key>Ctrl+Y</key>
        <match>*config*.h</match>
        <message>CMSIS Config</message>
        <commands>
          java -jar &quot;$(CMSIS_CONFIG_TOOL)&quot; &quot;$(InputPath)&quot;
        </commands>
    </item>
  4. Make sure to place it outside the <if host_os=….>…</if> statement:
  5. Now, quit and restart SES.
  6. After SES restarts, you can now right-click on the sdk_config.h file within the Application folder and you will see the option “CMSIS Configuration Wizard”:
  7. Click on CMSIS Configuration Wizard” and it will present you with the following window:
  8. From here, we can enable logging. Make sure you have the following options enabled (checked)
    NRF_LOG_ENABLED
    NRF_LOG_BACKEND_RTT_ENABLED
  9. Now, rebuild the application, and start debugging again. You should now see debug messages displayed in the Debug Terminal window:

Now, we’re able to debug the application and see debug messages!

Useful nRF development tips and tricks

RAM Size and RAM Start

For some of the modifications to the sdk_config.h file, the RAM size used by the SoftDevice will change causing the RAM offset and size of the user application to shift. This causes the application to halt and not work properly (sometimes causing an early exception). Fortunately, the SoftDevice prints out an error message in the debug messages log indicating the correct RAM start and size for the application. Make sure you have logging enabled with the following settings:

  • NRF_LOG_DEFAULT_LEVEL set to ≥ 3.
  • NRF_SDH_BLE_LOG_ENABLED set to 1.
  • NRF_SDH_BLE_LOG_LEVEL set to ≥ 2.
  • Logger configured to use the Segger RTT backend.

All of these can be set from the CMSIS Configuration Wizard plugin we mentioned earlier.

The error message will look like this:

The error can be fixed by modifying the RAM start and size of the application from within SES:

  • Right-click on the Project, then click on “Edit options”.
    Make sure you right-click on the Project name and not the Solution.
  • From the Configurations drop-down menu, choose “Common”:
  • Select “Linker”:
  • Double click on “Section Placement Macros”, then modify the RAM start and RAM size to match the values provided by the SoftDevice in the Debug Terminal output:
  • Once you change the RAM Size and Start settings, go ahead and rebuild the application and flash it to your target development board.
  • The application should now run correctly and it should not show any debug messages indicating a RAM Size/Start error.
  • Here are a couple of YouTube videos by Nordic Semiconductor that are helpful to better understand the different Build Options of a project:

Projects and Solutions

Solution in SES is a grouping of one or more Projects. A Project is a singular application that can be compiled and flashed to your device, and they contain the source files that are used within the application. Solutions, on the other hand, are used to group related Projects together while still being able to switch between them within the same view. Other benefits of including multiple Projects within a single Solution is the ability to build all the included Projects at once.

A Solution is stored as a .emProject file in your filesystem. Projects, on the other hand, do not have separate files. Instead, they are contained within the Solution file.

The one thing that I’ve found interesting is that all of Nordic’s example Projects include the source files relative to their root directories in the filesystem. This causes issues when trying to move that folder (e.g. outside of the SDK folder) to another location in your filesystem. The only solution that I’ve found to this problem is to manually edit the *.emProject file and switch from using relative paths to absolute paths.

To do this, open the Solution (.emProject) file in an editor of your choice and change all the paths to absolute paths.

You could do this by searching for and placing certain length strings like “………….” with the base SDK dir.

For example, looking at the Solution file for the ble_app_hrs example, we notice that all paths listed are relative paths instead of absolute: 

Yes, it will be a pain to change all these paths to absolute, but I recommend doing this for a template Solution (or a Solution for the example that you will be using as your base Solution), and then re-using that Solution for the different applications that you will be developing from thereon.

Summary

In this post, we covered how to set up Segger Embedded Studio for nRF development, as well as a couple of tips and tricks. The steps we went through should work on all the major operating systems (Windows, macOS, and Linux). As mentioned previously, the best part is that you can get a FREE License for SES when developing nRF applications. This gives you access to a professional cross-platform IDE that compares to other (costly) IDEs at no charge!

In an upcoming blog post, we’ll go through building a simple nRF BLE application and learn how to debug it using SES. We’ll also go over some tips and tricks that can help you develop and test BLE applications faster.

“Learn The Basics of Bluetooth Low Energy EVEN If You Have No Coding Or Wireless Experience!"

Don't miss out on the latest articles & tutorials. Sign-up for our newsletter today!

Take your BLE knowledge to the next level.

If you’re looking to get access to full video courses covering more topics, then check out the Bluetooth Developer Academy.

As part of all the courses within the Academy, you’ll also be able to download the full source code to use as a reference or use within your own application.

By joining the Bluetooth Developer Academy, you will get access to a growing library of video courses.

The Academy also features access to a private community of Bluetooth experts, developers, and innovators. You’ll get to connect and interact with me and other experts in the Bluetooth space, learn from others’ experiences and knowledge, and share yours as well.

So, what are you waiting for?? Join today!

You may also be interested in these articles.

Get the new "Intro to Bluetooth Low Energy" hardcover book for FREE

This new & updated edition of my best-selling book is specially crafted to help you learn everything you need to get started with BLE development.

Grab your copy for FREE today!