Custom Projects in nRF5-SDK : Segger Embedded Studio (Arch linux)
07 Sep 2019, 12:26am TZ +05:30
Developing custom projects with nRF5-SDK for nRF52 devices from Nordic Semiconductors.
Keeping the mess of files away !
Fig: Segger Embedded Studio
Source: Segger Embedded Studio
Its been some time since I worked on BLE. So pulled out my nRF52-DK to try to start again.
Fig: nRF52-DK Board
Source: Nordic Semiconductors
My BLE
was really rusted. Looked at my past projects like ble-jugaad
etc. They were already covered in layer of dust growing on them.
And so was the firmware. Nothing seams to work with Keil.
Hence I started on another adventure. Finding out how to do development on nRF52 the new way.
This time working under Manjaro Linux my choice of distro,
based on Arch Linux under the hood 😎.
Segger Embedded Studio #
To my surprise, Nordic Semiconductors had Segger Embedded Studio as default development environment.
I would walk you through the steps I took. Understanding the new way of developing with nRF5-SDK.
The focus on Segger Embedded Studio as default development environment. Due to availability of tooling and debugging support in Out-of-The-Box fashion.
IMPORTANT! its free for Commercial use by Nordic Semiconductors nRF52 and nRF51 products.
This is great no more struggling with makefiles
and Keil.
nRF5-SDK #
Well we first need to download the SDK.
https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK
Here we would be looking at nRF5_SDK_15.3.0_59ac345
.
That was the latest one at Sept,2019.
References #
There were a few video series that helped me out:
Playlist from Nordic Semiconductors on how to get started on Segger Embedded Studio
https://www.youtube.com/watch?v=YZouRE_Ol8g&list=PLx_tBuQ_KSqGHmzdEL2GWEOeix-S5rgTV
Tutorial on how to make your own nRF5-SDK sample projects:
I followed some work published by the same author. The second video in the above list.
After a few trials and error I found the right way to do this.
Setting up your Workspace #
Let’s walk through the steps. It might seem long but you would like in and remember it well.
I do at least, since its more copy paste than hack this - hack that stuff.
Step 1 : Directory Setup #
Note that both the SDK and Project are in the same Directory.
Though we would not touch the SDK we still need it for actual code compile and to extract from the examples.
First Create the Directory Listing & extract the SDK as follows:
|
|
Where the environment variables are as follows:
export NRF_SDK_VERSION="nRF5_SDK_15.3.0_59ac345"
is version of SDKexport PROJECT_NAME="MyBlinky"
is the Name of your desired projectexport BRD="nRF52DK"
This is the Board being used possible values include- “nRF52DK”
- “nRF52840-DK”
- etc from the nRF52xxx family or may be a custom board
- Note In case of custom Board One needs to add a Compiler Define to the common configuration in Segger Embedded Studio
CUSTOM_BOARD_INC=my_custom_board
The actual file would be
my_custom_board.h
in thesrc
directoryexport CONFIG="blank"
This is the memory and soft-device configuration- “mbr” with Master Boot Record
- “s132” with S132 Soft-Device configuration
The Last line would create an empty file tagging the SDK version in which the given project was created.
The
config
directory would store the respective configuration for SDK filesNote: We can create multiple of
$BRD-$CONFIG
combos as needed. Thesrc
folder would remain the same.
Step 2 : Get the Files in Order #
Next, we would need to copy the specific files.
2.1 Source Files #
First among them would be source code placed in the src
folder.
E.g. main.c
2.2 SDK Configuration #
The Configuration for SDK stored in sdk_config.h
file.
This needs to be copied to the
$PROJECT_NAME/project-$BRD-$CONFIG/config
directory
2.3 Segger Embedded Studio project files #
Next the Project Files
This would need the respective project files for Segger Embedded Studio
Having extension .emProject
, e.g. blinky_pca10040.emProject
Typically this is located at ses
directory in each of the example’s
corresponding configuration folder.
E.g. nRF5_SDK_15.3.0_59ac345/examples/peripheral/blinky/pca10040/blank/ses
directory contains the files:
blinky_pca10040.emProject
blinky_pca10040.emSession
flash_placement.xml
We need to copy all these 3 to the $PROJECT_NAME/project-$BRD-$CONFIG
directory.
Note that in this case we are specifically talking about the blinky
project
under the peripheral
examples. We can also the the similar job in case
of a BLE example also.
Step 3: Modifying the Project Configuration #
The .emProject
file is a XML file storing the project config.
There are specific sections of this file that need to be modified:
3.1 Project Name #
|
|
The part of "blinky_pca10040"
would change the executable name.
3.2 Include Directories #
|
|
This might look as a mangled thing but its essentially path.
Hence we need to modify the configuration accordingly:
../../../config
This is for OS Configuration in case of FreeRTOSNeed to Change this to
../src/config
where we might have theFreeRTOSConfig.h
file.../../../../../../components
and many more are actually the Path to SDK Components.Hence this also needs to be changed.
We would transform
../../../../../../components
to../../nRF5_SDK_15.3.0_59ac345/components
And similarly we can transform all other Directory Paths as well.
../config
This is the Last one it points tosdk_config.h
locationIn Our present configuration we have this at
$PROJECT_NAME/project-$BRD-$CONFIG\config
Hence
../config
becomesconfig
Note All paths are separated by
;
and this needs to remain correct.In the End add
../src
to include all header files insrc
directory also.The transformed Block would look like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
c_user_include_directories="../src/config; ../../nRF5_SDK_15.3.0_59ac345/components; ../../nRF5_SDK_15.3.0_59ac345/components/boards; ../../nRF5_SDK_15.3.0_59ac345/components/drivers_nrf/nrf_soc_nosd; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/atomic; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/balloc; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/bsp; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/delay; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/experimental_section_vars; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/log; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/log/src; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/memobj; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/ringbuf; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/strerror; ../../nRF5_SDK_15.3.0_59ac345/components/libraries/util; ../../nRF5_SDK_15.3.0_59ac345/components/toolchain/cmsis/include; ../../..; ../../nRF5_SDK_15.3.0_59ac345/external/fprintf; ../../nRF5_SDK_15.3.0_59ac345/integration/nrfx; ../../nRF5_SDK_15.3.0_59ac345/modules/nrfx; ../../nRF5_SDK_15.3.0_59ac345/modules/nrfx/hal; ../../nRF5_SDK_15.3.0_59ac345/modules/nrfx/mdk;config;../src;"
3.3 Preprocessor Definition #
|
|
These are the Preprocessor Directives separated by ;
For Custom Board We would need to change BOARD_PCA10040
That would transform to CUSTOM_BOARD_INC=my_custom_board
Final Block would become Only in case of Custom Board:
|
|
3.4 Other Paths #
Replace anywhere the ../../../../../../components
pattern occurs
with the as explained ../../nRF5_SDK_15.3.0_59ac345/components
pattern
for all files and tools as well.
3.5 Source File Section #
Finally the Source file section
|
|
This would transform to :
|
|
Based on the Project configuration.
Ready #
Now this modified .emProject
can be used in Segger Embedded Studio.
That’s all you begin your adventure with derived projects.