This is aimed as a very basic tutorial on using the Nordics SDK, version 15.2.0 . There are already a lot of good guides directly from Nordic so this is just a quick brief on how to get things set up and running as fast as possible.
Although I’ll be using version 15.2.0 these steps should work with other versions as well.
You will need:
- GCC compiler and tools for ARM
- MinGW compiler and tools for Windows(we need this for mingw32-make.exe, read text below if using some other OS)
- nRF5 SDK
Download and install these two compilers, and download the SDK.
If you are wondering why MinGW is needed, it is because it contains mingw32-make.exe tool. This tool is used for building the examples of the SDK. Every example contains a makefile, which is a file that describes how each example should be built. Makefile lists all the necessary source files, as well as include paths needed for successfully building the example. It also contains compiler and linker paths, precompiled libraries, project specific defines and flags, as well as list of commands that invoke compiler and linker, and other tools if necessary.
mingw32-make.exe is a windows specific make tool, and if using some other operating system it is needed to download make tool for that system.
Preparing the SDK
Go ahead and download nRF5 SDK from Nordics website. After download is complete you will have a zipped SDK files. Extract it and I would suggest renaming it to e.g. :
Now if you installed all the necessary tools go to:
Start a terminal window in this folder. This is just one of the examples that comes with SDK. All of these examples are ready to build, all you have to do is start a make tool… or at least this should be the case. Lets see what happens. Type in terminal:
Now you might have succeeded, or you might have failed. If I do this make command it fails for me because I don’t have compiler in the path where SDK expects me to have it. This is the error message:
process_begin: CreateProcess(NULL, "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/bin/arm-none-eabi-gcc" --version, ...) failed. Cannot find: 'C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/bin/arm-none-eabi-gcc'. Please set values in: "E:/nRF5_SDK_15.2.0/components/toolchain/gcc/Makefile.windows" according to the actual configuration of your system. ../../../../../../components/toolchain/gcc/Makefile.common:129: *** Cannot continue. Stop.
The great thing is that this error message provides me with a solution to the problem. We have to look in:
When we open this folder there are two files of interest:
These files define compiler path, version and name prefix for Windows and posix systems(Linux, macOS). Since I use Windows i will edit Makefile.windows . Path to compiler on my sistem is:
But this may differ for you. The important thing is to give a path that contains these files:
This is not the complete list, but it should give you an idea what files should be present. Also if on Windows make sure you use ‘/‘ instead of Windows default ‘\‘ for folder separation.
We can also set the correct version number, but it is not essential, everything will work without it. To find out compiler version we can use command:
In my case it is “7.2.1“.
Building the example
Now finally lets build the example. If on Windows type in terminal once again:
and hit ENTER. If using Linux or macOS your make tool can probably be invoked with simply typing:
and hit ENTER. Regardless of OS now compiler should start compiling all of the source files specified in the example makefile, and output should be something like this:
mkdir _build cd _build && mkdir nrf52832_xxaa Assembling file: gcc_startup_nrf52.S Compiling file: nrf_log_backend_rtt.c Compiling file: nrf_log_backend_serial.c Compiling file: nrf_log_backend_uart.c Compiling file: nrf_log_default_backends.c Compiling file: nrf_log_frontend.c Compiling file: nrf_log_str_formatter.c Compiling file: app_button.c Compiling file: app_error.c Compiling file: app_error_handler_gcc.c Compiling file: app_error_weak.c Compiling file: app_scheduler.c Compiling file: app_timer.c Compiling file: app_util_platform.c Compiling file: hardfault_implementation.c Compiling file: nrf_assert.c Compiling file: nrf_atfifo.c Compiling file: nrf_atflags.c Compiling file: nrf_atomic.c Compiling file: nrf_balloc.c Compiling file: nrf_fprintf.c Compiling file: nrf_fprintf_format.c Compiling file: nrf_memobj.c Compiling file: nrf_pwr_mgmt.c Compiling file: nrf_ringbuf.c Compiling file: nrf_section_iter.c Compiling file: nrf_strerror.c Compiling file: system_nrf52.c Compiling file: boards.c Compiling file: nrf_drv_clock.c Compiling file: nrf_drv_uart.c Compiling file: nrfx_clock.c Compiling file: nrfx_gpiote.c Compiling file: nrfx_power_clock.c Compiling file: nrfx_prs.c Compiling file: nrfx_uart.c Compiling file: nrfx_uarte.c Compiling file: main.c Compiling file: SEGGER_RTT.c Compiling file: SEGGER_RTT_Syscalls_GCC.c Compiling file: SEGGER_RTT_printf.c Compiling file: ble_advdata.c Compiling file: ble_conn_params.c Compiling file: ble_conn_state.c Compiling file: ble_srv_common.c Compiling file: nrf_ble_gatt.c Compiling file: nrf_ble_qwr.c Compiling file: utf.c Compiling file: ble_lbs.c Compiling file: nrf_sdh.c Compiling file: nrf_sdh_ble.c Compiling file: nrf_sdh_soc.c Linking target: _build/nrf52832_xxaa.out text data bss dec hex filename 26032 532 2452 29016 7158 _build/nrf52832_xxaa.out Preparing: _build/nrf52832_xxaa.hex Preparing: _build/nrf52832_xxaa.bin DONE nrf52832_xxaa
And that is it! Now we have nrf52832_xxaa.hex that can be flashed to nRF52832 chip. I’ll show how to flash it in another post.
Bonus: faster build time
The process of building this simple example on my machine took about half a minute. It is not too long, but it would be nice if it could go faster. Compiling of different sources can be easily parallelised, so if you have a multi-core processor, and you probably do, then compiling with multiple cores should speed things up. Make tool doesn’t do this by default, for some reason, so we have to explicitly enable it. It can be done by adding a -j option to make command, for example:
With including -j option my build time drops to only 8 seconds! That is more than 3x speed up! But it will depend on your hardware, so it could be less… or more!