Downloading softdevice to PCA10059 USB Dongle Board Using nrfutil

In the previous post I have described how to download firmware files to PCA10059 board that do not require a softdevice to run. This time I will expand on that and show how easy it is to add a softdevice to the mix.

Unfortunately it seems that you can’t merge your application .hex file and softdevice .hex file. You have to provide them separately to the nrfutil tool.

To demonstrate firmware download we will be using 
example ble_app_blinky from Nordic SDK located in SDK_root/examples/ble_peripheral/ble_app_blinky/ folder. In order to make your life easier I have bundled app .hex and softdevice together:

Unpack this file to a folder of your choice and start a terminal window in that folder. I am using PowerShell on MS Windows 10. Enter the following command into a terminal:

nrfutil pkg generate --hw-version 52 --sd-req 0x00 --sd-id 0xA9 --softdevice .\s140_nrf52_6.0.0_softdevice.hex --application-version 1 --application .\nrf52840_xxaa.hex

This will generate a package Now we have to program our board with the following command:

nrfutil dfu usb_serial -pkg -p COM6 -b 115200

And with that if you open nRF Connect on your mobile device and scan for the available devices you will see the Nordic_blinky device. You can even connect to it and turn the on-board led ON/OFF and read the button state.

Updating the application firmware without softdevice

From now on you can package only the application without packaging the softdevice along with it. The command is similar to the one used when softdevice wasn’t used, but with one simple change. First download this altered ble_app_blinky .hex file or use you own:

Unpack it and start terminal window in the same window as the unpacked .hex file. Once opened, type in the following command:

nrfutil pkg generate --hw-version 52 --sd-req 0xA9 --application-version 1 --application .\altered_nrf52840_xxaa.hex

The small modification I mentioned is the –sd-req argument. Instead of 0x00 we are now using 0xA9. This is because 0xA9 is the s140_nrf52_6.0.0 softdevice ID. Every softdevice, and every version have their ID. You can find a list of those IDs and a lot more info on nrfutil here.

From here I would recommend creating your own program script, so you don’t have to manualy put in these two commands.

Thank you for reading!

Programming the New Nordic Chip NRF52840, and USB Dongle Board PCA10059 Featuring it

PCA10059 USB dongle featuring a NRF52840 microcontroller

Recently Nordic released a new board/dongle featuring their new microcontroller NRF52840. Although this board is not feature rich, like a full development kit, it still provides enough periphery for some basics, like blinky example and button example. There is also a possibility to do USB development because the board comes with a giant USB connector which makes it very portable, very simple to get started, and the most important thing, looks really nice 🙂 .

Of course the PCA10059 board has an on-board antenna which can be used for, among other things, Bluetooth. This makes the board great for Bluetooth development, especially if you need to have multiple boards interconnect with one another. You can just plug in as many as you need to USB ports, program them, and watch what happens. This is mostly what I’ll be doing with them.

Programming the PCA10059 USB dongle board

Back side of the PCA10059 board. Few test points and a 10-pin tag connect programming interface can be seen

Programming of the board can be done through a USB interface, which is the most convenient way to program it in my opinion. Just to mention that there is also a 10-pin tag connect interface that can be used for programming, but we won’t be discussing that here.

In order to be able to program the PCA10059 board through USB, some sort of bootloader has to be used. Nordic provides such a bootloader on every PCA10059 board so we don’t have to worry about it.

General memory layout

General structure of NRF52840 flash memory

The above image shows how the flash memory will generally look like. It can be seen that softdevice(SD) occupies the bottom part of flash pool, from address 0x1000 to somewhere around 0x26000. Start address will probably always be the same, but the end address could change with new revisions of softdevice. After softdevice comes the application part of the memory. The application can potentially occupy all of the empty space all the way up to the bootloader. Bootloader starts at 0xE0000 and consumes the rest of the available flash memory above this address. Bootloader part is always in the memory, but softdevice doesn’t have to be. If application doesn’t use any of the softdevice functionality, then softdevice can be omitted. More on this later.

PC side of things

Bear in mind that all of this is tested on MS Windows 10, with powershell(PS). It should work on other OSes, but I can’t give any guarantees.

With that out of the way, there are, according to Nordic, two ways to program the PCA10059 board. GUI or CLI. GUI way is by using the nRF Connect for Desktop app. CLI way is by using the nrfutil tool. Unfortunately I wasn’t able to make nRF Connect for Desktop work, so we will be using the CLI. However Nordic states that driver for PCA1059 board comes with nRF Connect for Desktop, so you will probably have to install that anyway.

Now lets install nrfutil tool. It is a python package that works only with python 2.7. Make sure you install it for python 2.7 and not for python 3. If you don’t have python, install it. You can find it here. Now check if pip is available, and check where is it:

pip -V
or as in my case
pip2 -V

If you are on windows output should be something like:

pip 9.0.1 from d:\python27\lib\site-packages (python 2.7)

And if pip command is not from python 2 folder, it will look something like:

pip 9.0.3 from d:\python36\lib\site-packages (python 3.6)

You can see either by the folder or by text in parentheses for which python version your pip command will install packages. If you don’t know what is the command to run the correct pip, you can just cd into python 2 directory and start pip from there like this:

cd d:/python27/Scripts
./pip.exe -V

If in folder run the following command, and if not just replace ./pip.exe with your pip command:

./pip.exe install nrfutil

Check if nrfutil got installed:

nrfutil --help

Now that everything is setup we are ready to start programming our board!

Downloading a simple blinky example to PCA10059 board

We will now finally download a blinky example .hex file from SDK to our board. If you have SDK you can go and find blinky example .hex file there, or just use this one:

Unzip this file and open a terminal window in a directory where you downloaded it. Type the following in terminal:

nrfutil pkg generate --hw-version 52 --sd-req 0x00 --application-version 1 --application .\blinky_pca10059_mbr.hex

This will create file in the folder you are currently in. You will probably get a big warning in your terminal 😀 . That is because we are not using keys to encrypt this newly generated .zip , and potentially someone could tamper with our precious .hex . We are currently not worried about that, but if you are going to use this in production, you should think about using keys to encrypt this .zip . We are not going to cover that here.

We will not go into detail about the options, just in short:

  • hw-version depends on the microcontroller that is on board
  • sd-req is the code for expected softdevice on board. This information was really hard to find, you can put 0x00 to basically say that you don’t care about this parameter
  • application-version is any number you want
  • application is the .hex file containing your program, but without softdevice

Now that our package is ready the only thing left to do is to finally program the board. Go ahead and insert it into a USB port on your computer. After you insert it two things can happen. You could see the LD2 slowly pulsing red, or you could see something else. If you see LD2 pulsing red that means that the board is in bootloader mode and is ready to accept our program. If LD2 is not pulsing red, then just reset it with a reset button that is located on the left side of the board.

PCA10059 board from above. On the left side is the reset button, which is pushed on the side, as the arrow shows. LD2 is located on the right side of the board, near the USB connector

After a reset, LD2 should start pulsing red, and you should have a new device connected on your computer. If on windows you can look it up on device manager:

NRF52840 DFU visible in device manager as a COM6 port

You need to remember what COM port is assigned to the board because we will need it now. Go to the terminal and type in this command:

nrfutil dfu usb_serial -pkg -p COM6 -b 115200

Replace the COM6 with your port number, or if on Linux or Mac with a corresponding file path. When you hit enter, you should see a progress bar, and a short message “Device programmed.” after the programming is complete. All leds on board should be turning on one after another, and then turn off at the same time, and repeat indefinitely. If you see that then congratulations! The board is programmed successfully!

To find out how to flash a softdevice along with the application .hex file click here.