Segger Embedded Studio - A Cross Platform IDE

Download and Setup

Note: It is recommended, but not necessary, to use the most recent releases of the above software.

Importing a Keil uVision project

Note: From nRF5 SDK v14.1, Segger Embedded studio projects are officially supported. If using v14.1 or newer, please use the native SES-projects instead of the "import" function.

  • Open SEGGER Embedded Studio 3.10e
  • Select Tools -> Package Manager... and install the CMSIS-CORE Support Package

image description

  • Select File -> Import IAR EWARM / Keil MDK Project...
  • Navigate to your local nRF5 SDK and in NRF5_SDK/examples/ble_peripheral/ble_app_beacon/ select pca10040/s132/arm5_no_packs/ble_app_beacon_pca10040_s132.uvprojx
  • The Import Build Configuration window will pop-up. Make sure you select to use Embedded Studio's Internal Toolchain (GCC/Clang) for now...

image description

Nuances

If you've used Keil uVision with Nordic's SDK before, you might remember that each example BLE project contains a dummy project configuration for easy flashing of the SoftDevice. We don't need this in Embedded Studio and it can cause confusion so let's delete it.

  • Select Project -> Build Configurations... and under Public Configurations select flash_s132_nrf52_3.0.0_softdevice and delete it by clicking the - symbol in the upper right-hand corner of the pop-up window.

Your build configurations should look like this now:

image description

And your project explorer:

image description

Adding nRF5 MDK Files

Keil uVision uses Device packs for Startup/System Setup. This pack contains the nRF5 startup assembly files arm_startup_nrf52.s and the system setup files system_nrf52.c along with some header files. We will need to manually add these files to our Embedded Studio project.

  • Download ses_nrf51_startup.s and ses_nrf52_startup.s and save them into NRF5_SDK/components/toolchain/embedded_studio/ (create the folder)
  • Remove Cortex_M_Startup.s from the Internal Files folder in the Project Explorer
  • Right click the Internal Files folder and select Add Existing File...
  • In NRF5_SDK/components/toolchain/ select system_nrf52.c
  • Do the same for NRF5_SDK/components/toolchain/embedded_studio/ses_nrf52_startup.s

Your project explorer should look like this now:

image description

  • Select Project -> Edit Options... and then select the Preprocessor tab
  • Add ../../../../../../components/device to the User Include Directories field to include the device header files in our Embedded Studio project

Your user include directories should look like this now:

image description

Peer Manager/Flash Data Storage

Most of the examples in the SDK use Peer Manager. Peer Manager uses Flash Data Storage and Flash Storage. To indicate where information from Peer Manager (e.g bonding information) should be store page tags in flash (section variables) is used. These page tags need to be written to flash. To do so, flash_placement.xml and thumb_crt0.s have to be added and modified. Thanks to @RK and @Håkon Alseth in this post.

Flash_placement.xml can be located in the project folder, for example: ..\nRF5_SDK_xxx\examples\ble_peripheral\ble_app_gls\pca10040\s132\arm5_no_packs

You have to generate flash_placement.xml using text editor, notepad for example. After that you can import it by right click on the project name and choose "Import Section placement"

==========

For SDK v14 please use these updated files:

flash_placement.xml

thumb_crt0.s

==========

flash_placement.xml should then look like the following (SDK 12):

<!DOCTYPE Linker_Placement_File>
<Root name="Flash Section Placement">
  <MemorySegment name="$(FLASH_NAME:FLASH)">
    <ProgramSection alignment="0x100" load="Yes" name=".vectors" start="$(FLASH_START:)" />
    <ProgramSection alignment="4" load="Yes" name=".init" />
    <ProgramSection alignment="4" load="Yes" name=".init_rodata" />
    <ProgramSection alignment="4" load="Yes" name=".text" />
    <ProgramSection alignment="4" load="Yes" name=".dtors" />
    <ProgramSection alignment="4" load="Yes" name=".ctors" />
    <ProgramSection alignment="4" load="Yes" name=".rodata" />
    <ProgramSection alignment="4" load="Yes" name=".ARM.exidx" address_symbol="__exidx_start" end_symbol="__exidx_end" />
    <ProgramSection alignment="4" load="Yes" runin=".fast_run" name=".fast" />
    <ProgramSection alignment="4" load="Yes" runin=".data_run" name=".data" />
    <ProgramSection alignment="4" load="Yes" runin=".tdata_run" name=".tdata" />
    <ProgramSection alignment="4" keep="Yes" load="Yes" runin=".fs_data_run" name=".fs_data" />
  </MemorySegment>
  <MemorySegment name="$(RAM_NAME:RAM);SRAM">
    <ProgramSection alignment="0x100" load="No" name=".vectors_ram" start="$(RAM_START:$(SRAM_START:))" />
    <ProgramSection alignment="4" load="No" name=".fast_run" />
    <ProgramSection alignment="4" load="No" name=".data_run" />
    <ProgramSection alignment="4" load="No" name=".tdata_run" />
    <ProgramSection alignment="4" load="No" keep="Yes" name=".fs_data_run" address_symbol="__start_fs_data" end_symbol="__stop_fs_data" />
    <ProgramSection alignment="4" load="No" name=".bss" />
    <ProgramSection alignment="4" load="No" name=".tbss" />
    <ProgramSection alignment="4" load="No" name=".non_init" />
    <ProgramSection alignment="4" size="__HEAPSIZE__" load="No" name=".heap" />
    <ProgramSection alignment="8" size="__STACKSIZE__" load="No" place_from_segment_end="Yes" name=".stack" />
    <ProgramSection alignment="8" size="__STACKSIZE_PROCESS__" load="No" name=".stack_process" />
  </MemorySegment>
  <MemorySegment name="$(FLASH2_NAME:FLASH2)">
    <ProgramSection alignment="4" load="Yes" name=".text2" />
    <ProgramSection alignment="4" load="Yes" name=".rodata2" />
    <ProgramSection alignment="4" load="Yes" runin=".data2_run" name=".data2" />
  </MemorySegment>
  <MemorySegment name="$(RAM2_NAME:RAM2)">
    <ProgramSection alignment="4" load="No" name=".data2_run" />
    <ProgramSection alignment="4" load="No" name=".bss2" />
  </MemorySegment>
</Root>

Thumb_crt0.s is located in the Segger Embedded studio install folder: ..\SEGGER\SEGGER Embedded Studio <v. xx>\source

In thumb_crt0.s, fs_data should be added, it can be added after tdata (thanks to @RK):

ldr r2, =__tdata_end__
bl memory_copy
# ADD HERE ... 
ldr r0, =__fs_data_load_start__
ldr r1, =__fs_data_start__
ldr r2, =__fs_data_end__
bl memory_copy
# TO HERE ...

Building

Our project should build successfully now:

  • Build the project by selecting Build -> Build ble_app_beacon_pca10040_s132 or by simply hitting F7

image description

Notice that the compiled binary is placed at the beginning of FLASH and SRAM. This project requires a SoftDevice so let's reserve the correct amount of room for it.

  • Select Project -> Edit Options... and then select the Linker tab
  • Paste the following into the Section Placement Macros field (SDKv12):

FLASH_START=0x1F000
SRAM_START=0x20002000

Your Project Options should look like this now:

image description

  • Re-build the project by selecting Build -> Rebuild ble_app_beacon_pca10040_s132 or by simply hitting Alt + F7

Now you should see that space has been reserved in FLASH and SRAM for the SoftDevice:

image description

Fine-Tuning

  • Select Project -> Edit Options... and then select the Preprocessor tab
  • Add the definition NO_VTOR_CONFIG to the Preprocessor Definitions field (this tells Embedded Studio to expect a SoftDevice to be present and that it will forward exceptions/interrupts to the application)

Your Preprocessor Definitions should look like this now:

image description

Flashing the SoftDevice with our application

  • Select Project -> Edit Options... and then select the Loader tab
  • Add the absolute path to the SoftDevice NRF5_SDK/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex to the Additional Load File[0] field

Your Loader options should look like this now:

image description

Running

  • Connect your nRF5 Development Kit to your computer and turn it on
  • Run the application by selecting Debug -> Build and Run or hitting Ctrl + F5

Your Output log should look like this now:

image description

The application should be running on your nRF5 DK and LED1 should be blinking. You should be able to scan for and find the beacon using nRF Connect.

Debugging

  • Select Debug -> Go or simply hit F5

You should see that you have entered the debugging interface now:

image description

Notice that our application has ran until the first line in main() and is halted. You should experiment with debugging in Embedded Studio. It has all the debugging features you would expect from a professional IDE and more (makes sense as SEGGER makes the debuggers as well).

Peer manager

To make peer manager (SDK 10(?), SDK 11, SDK 12) work with Segger Embedded Studio the modifications in this post are needed.

Troubleshooting

If you are stuck, previous blog posts (although deprecated) may help you fix your problem (also see the questions section):

  • Hi, again! Happy to report that all is working now.

    I'm not 100% sure of this, but I believe that it may have been the flash_placement.xml file. The original instructions in the tutorial stated:

    Flash_placement.xml is located in the project folder, for example: ..\nRF5_SDK_xxx\examples\ble_peripheral\ble_app_gls\pca10040\s132\arm5_no_packs

    There was none in SDK 13, so I may have copied over the file from the Segger installation directory (thanks to jcormier) into the project folder... and modified it.

    To matters more confusing to me, I noticed that there are two flash_placement.xml files, one in:

    /usr/share/segger_embedded_studio_3.12/targets/

    and one in:

    /usr/share/segger_embedded_studio_3.12/targets/Cortex_M/

    I think I used the wrong one to copy over (the one in .../targets).

    In summary... I followed the excellent instructions in this tutorial and the only deviation I made to get it all working was to modify the flash_placement.xml file that resides in the following directory:

    /usr/share/segger_embedded_studio_3.12/targets/Cortex_M/

    Just sharing my experience with those using SDK 13.0. Have a good day!

  • Hey, guys... I'm stuck at the "Peer Manager/Flash Data Storage" with a compile error. I'm running SES V3.12 on Linux with SDK 13, and have modified both the flash_placement.xml and thumb_crt0.s files (hopefully correctly).

    I get this error:

    image description

    This is what I added to the thumb_crt0.s file:

    image description

    I'm attaching my flash_placement.xml file that resides in the project directory, to see if you can see a problem. By the way, I also tried modifying the one that resides in the SES installation directory, but got a similar compilation error.

    Finally... this is how my project structure looks like:

    image description

    Can anyone help me out, please? Thanks in advance!

  • For people who are trying to setup the Segger Embedded Studio on mac\windows. This post is for nRF52-DK board. If you are using the nRF-51 board, check the PCA100xx number that you have on your nrf51-DK board.

    Use the ses_nrf51_startup.s, system_nrf51.c files to add them to internal files.

    FLASH_START=0x1F000 SRAM_START=0x20002000 The above values are for the nRF52-DK board. For nRF51-DK you need to retrieve these values from the loader file located in the SDK directory that you download: nRF5_SDK_12-2/examples/ble_peripheral/ble_app_beacon/pca10028/s130/armgcc/ble_app_beacon_gcc_nrf51.ld USE THE VALUE FOR FLASH_START and SRAM_START from this file.

    Lastly the .hex softdevice file that you use in the loader, make sure that you select the on from 'S130' directory. I had struggled for a day because of these stupid mistakes that I made.

    Thank you Nordic so much for putting together this wonderful post! Happy tinkering :)

  • @jcormier I had the same problem but using SDK13, I initially got "nrf.h: No such file or director". I found that my problem was in the second part of "Adding nRF5 MDK Files" section. It asks you to "Select Project -> Edit Options...", but first make sure you have clicked on you active project from project explorer before doing this step. This solved my missing file issue.

  • @svenkbach: You have to add the register definition file to your project, this is done by navigating to

    Project -> Edit Options -> Debugger -> Register Definition File
    

    and then selecting the register definition file for your device.

    You'll find the register definition files(.svd) in the svd folder in the nRF5_SDK folder, e.g. for SKD v12.0.0 you'll find it in nRF5_SDK_12.2.0_f012efa\svd