Introduction
Getting started to work with the NRF52840 this semester has been more challenging than expected. This post should clear up the most commonly encountered pitfalls when setting up a development environment. This will hopefully also help others facing similar issues.
Setup
Hardware setup:
- Mac
- Micro-USB 2.0 cable
Software setup:
- MacOS
- SEGGER J-Link Software
You can download the SEGGER J-Link Software utile on the official website and follow the setup instructions of the wizard.
For this post a Mac with macOS Catalina v. 10.15.1. was used.
Getting Started
For getting started, the NRF52840 Devkit User Guide was used to take the first steps.
First, some required applications should be downloaded and set up.
- For this purpose, we are using Visual Studio Code. You can obtain this software on the website and download it.
- Used compiler: GNU/GCC. Follow this instruction to set it up.
- Download the file:
gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2
- Unzip file
tar -tf gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2
- Make a directory to install it:
mkdir /usr/local/gcc_arm
- Move the unzipped file
sudo mv ~/Downloads/gcc-arm-none eabi-9-2019-q4-major/ /opt/local/gcc_arm
- Check the directory
ls /opt/local/gcc_arm/arm-none-eabi/
- echo current path variable
echo $PATH
- Add this path also to
./profile
so that you don’t have to add this line to the path every time:vi ~/.profile
export PATH="$PATH:/usr/local/gcc_arm/bin/"
- Check if everything was successful
arm-none-eabi-gcc --version
- Download the file:
- The next step is to download the Software Development Kit (SDK). For this semester project version 16.0.0 has been used (take a look here).
Simply download the zip file and extract it where you want to set up your workspace.
Now that we have everything we need, we can actually start testing the development kit. Let’s start with the precompiled Blinky example. Therefore, follow these steps.
- Connect the boards to the computer with a USB cable.
- Make sure that the power switch is set to “on”.
- In the SDK directory open the Blinky example
examples\peripheral\blinky
- In the hex folder, you find all the precompiled hex files. For the NRF52840 you choose
blinky_pca10056.hex
- Now you can copy the hex file to the board.
- Therefore, open the finder.
- Now go to the
_build
folder and copy the hex file. - As you can see in the picture below, you will find the “JLINK” driver under “Locations”. Open that folder and insert the hex file.
- The board will now restart and run the application.
- Finally, you should be seeing the blinking leds.
Of course, instead of just flashing binaries onto the target board it is essential to understand how to compile the source code. In order to compile a project, follow these steps for the blinky example.
- First, open the Makefile which is in the folder
\blank\armgcc
- On the row
129
changeMakefile.common
toMakefile.posix
- Open the
Makefile.posix
file and change the path and version - Now open the terminal in the
…\armgcc
folder and run the command make - Now you got a
_build
folder and you will find the right hex file in there. According to point 5 from the precompiled blinky example you can copy this file to your board.
The benefit of using the blinky example for this guide is that you do not have to deal with the softdevice. The softdevice contains functionality for the BLE stack (and other functionality) and is proprietary and thus only exists in binary form.
Some examples require the softdevice. For those examples you find the softdevice numbered folder in the pca10056
folder. In most cases where you need the BLE Stack, you will need to flash softdevice s140
. In order to do so, open the terminal in the folder containing the makefile and run the command make flash_softdevice
.
Hopefully, this post has helped you getting started on your own project. Let me know in the comments if it was helpful to you.