Posted 2016-02-22 15:56:11 +0200

blogs->nordicers

# Keil + nrfjprog = true

In this blogpost we will demonstrate the usage of Keils integrated command line functionality. We will start nrfjprog through Keil bindings in order to erase our chip and program SoftDevices.

nrfjprog is a command line tool that Nordic provides, which allows for easy flashing and erasing of firmware onto our chips. This command line tool is automatically installed as part of installing the MDK for each version of the SoftDevice.

## Installing the command line tools

Start off by downloading and installing the command line tools executable. I will base this blogpost on SDK 11, if you are using a different SDK version, the file structure might be different.

Open the command line and type:

• nrfjprog --help

This will list the different input parameters and other help documentation. If the command line reports that it cannot find the program follow the instructions below in Adding PATH Variables.

Sometimes nrfjprog.exe will not be added to PATH by default, this is how to do it manually. If you are looking for more information on what the PATH variable is, please consult this answer at Superuser.

Navigate to environment variables by:

• Pressing: Win+Break or

• Opening Control Panel >> System >> Advanced >> Environment Variables or

• Right-clicking My Computer and click on properties

• Then click on Advanced system setting

• Click on Environment Variables...

Add the variable to path by clicking the Edit... button

Then add nrfjprog by adding ´;C:\Program Files (x86)\Nordic Semiconductor\nrf5x\bin´ to the end of the variable value for PATH. Make sure that you add a ; between entries in PATH values, i.e. path1;path2.

Then press OK. Now you will be able to see the help dialog when you type nrfjprog --help in a new command line.

## Adding command line instructions to Keil

Keil lets you add command line tools directly into the IDE, this makes flashing and erasing a lot quicker, since you only need to use one program.

Start off by opening the Customize tools menu by:

• Pressing Tools >> Customize Tools Menu...

Next we will create a new tool. Press the new button highlighted below.

Our first tool will be called eraseall. It will run the command nrfjprog with the arguments --eraseall.

After clicking OK, our new command will show up in the Tools drop down menu. When you press Tools >> eraseall, you get the following build output on a successfull erase:

If you are using nRF52 you will have to specify --family nrf52 as an additional argument, like this:

## Programming SoftDevices

It is also easy to program SoftDevices this way, start by opening the customize tools menu and creating a new tool, like we did for eraseall.

The parameters are:

• Command: nrfjprog
• Initial Folder: [YOUR_SDK_LOCATION]\SDK11\components\softdevice\s130\hex
• Arguments: --program s130_nrf51_2.0.0-7.alpha_softdevice.hex

I chose to call my tool program_sd130, however you can call this anything you like.

After pressing OK and starting my tool via Tools >> program_sd130 I see the following build output on successful programming:

## Final words

This is just a small example of what you could use command line integration in Keil for. If you encounter any difficulties or have some feedback, please leave a comment below.

Posted Feb. 23, 2016, 1:45 p.m.

Nice, I think a really useful command here could be for applications with a bootloader. You can use 'nrfjprog -f NRF52 --memwr 0x7F000 --val 0x01' so you can flash the application instead of having to upload it via bootloader.

Also 'nrfjprog -f NRF52 --recover' if your application protects the device or something like that.

Thanks for sharing this.

Posted March 21, 2017, 2:28 p.m.

Posted June 6, 2017, 11:59 a.m.

Hello

When i try to flash it on to the board, I am getting the following error. Could anyone please help me out.

ERROR: The --family option given with the command (or the default from ERROR: nrfjprog.ini) does not match the device connected.

Best Regards

Arun

Posted June 28, 2017, 2:14 p.m.

Hello Arun,

The arguments for the program_sd tool should be

--family nrf52 --program s130_nrf51_2.0.0-7.alpha_softdevice.hex


## Recent blog posts

• ### 6 Things to Know about Bluetooth Beacons

Posted 2017-09-19 12:04:14 by Rose Martin
• ### Creating a Keil project for a Bluetooth Mesh example

Posted 2017-09-19 12:08:11 by Kristian Skordal
• ### Using millis() like in Arduino.

Posted 2017-09-18 11:58:04 by schef
• ### Flashing nRF5x firmware using any dumb terminal program via standard serial COM port

Posted 2017-09-18 03:53:40 by Nguyen Hoan Hoang
• ### How to Debug the nRF52 Interrupts — Useful Tips

Posted 2017-09-13 15:15:22 by Yaniv Nis

## Recent questions

• ### why can't i program nrf51 device using the example for nrf52 series?

Posted 2017-09-21 13:48:29 by Anonymous
• ### Park mode in nRF51822

Posted 2017-09-21 13:02:15 by milav
• ### How to connect spectrum analyzer with NRF52840-DK?

Posted 2017-09-21 12:55:23 by soumil
• ### light control mesh example not working

Posted 2017-09-21 12:50:38 by rahul
• ### nRF52 PCA10040 Bossa Program Port

Posted 2017-09-21 12:41:33 by Sugitani