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
- First, download Segger Embedded Studio from their website (look for the download that matches your operating system):
- Launch the downloaded installation file and complete the installation.
- Download the latest nRF5x SDK:
- Unzip the SDK file to a known location on your computer.
- Download the latest version of Java for your computer (for macOS and Windows):
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).
- Once you have Java and SES installed, go ahead and launch SES.
- Now that SES is launched, we will open one of the examples provided with the SDK under the /examples folder.
- 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:
- Now let’s open the example named ble_app_hrs. Navigate to File → Open Solution.
- 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.
- 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).
- 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.
- Once you have the Solution open, you’ll be presented with the following screen:
- Now you can attempt to Build the project:
- 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:
- Click the Get a Free License option, and then enter your information needed:
- Hit Request License.
- You should then receive the License information in your email.
- Copy the License key and Paste it into the Activation field:
- Once you enter the License key, click Close.
- The Project should now start building and (eventually) build successfully:
- Now you should be able to flash and run the application on your nRF development kit (nRF52840 in my case).
- 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.
- Once you have the development kit connected to the computer, you can run the application on the board.
Click on the Start Debugging button:
- When the application is flashed to your development kit, it will stop at a breakpoint in main():
- Continue execution and run the application by clicking the Play button:
- 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:
- Navigate to File → Open Studio File → External Tools Configuration
- Once you’ve clicked on External Tools Configuration, the tools.xml file should now be open:
- After you have the tools.xml file open, add the following XML code before the </tools> tag:
XHTML1234567891011<item name="Tool.CMSIS_Config_Wizard" wait="no"><menu>&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 "$(CMSIS_CONFIG_TOOL)" "$(InputPath)"</commands></item>
- Make sure to place it outside the <if host_os=….>…</if> statement:
- Now, quit and restart SES.
- 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”:
- Click on “CMSIS Configuration Wizard” and it will present you with the following window:
- From here, we can enable logging. Make sure you have the following options enabled (checked)
- 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
A 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.
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.
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.
If you’ve enjoyed this blog post and found it helpful, please share it with your co-workers, friends, or anyone who may find it useful.