Programming the BluChip with CMSIS-DAP and Keil

The following is a step-by-step guide to programming your BluChip using the CMSIS-DAP debugger included in the Explorer Kit available in the shop. In this guide we will:

  • Find/Connect the hardware
  • Install the required software
  • Program and debug the BluChip

The Hardware

This guide is written for the BluChip Explorer kit and assumes you have a CMSIS-DAP debugger and the BluChip.  The demo software was designed for the breadboard and components in the Explorer kit but they are not necessary to properly program, debug and test your BluChip development environment.

 
 

The BluChip was designed with a flexibility in mind and as a result there are multiple ways to connect any debugger/programmer to the BluChip directly.  The programming pins (GND, PWR, SWDIO, SWCLK) are present on the .1" headers and on the .05" headers.  In this example we are going to connect the .05" headers to the CMSIS-DAP debugger using the included cable.  

Connect the grey ribbon cable to the "TGT_DBG" connector on the CMSIS-DAP Debugger.  The connection to the .05" header on the BluChip is a little trickier.  The 4 pins on the BluChip should mate with the 4 pins closest to the red line on the cable, that is the 4 "top" pins on the cable.

 
 

After connecting the boards your all set to install the software and plug the CMSIS-DAP into the computer using any standard micro-USB cable.


The Software

There is a fair amount of required software to create programs targeting the Nordic NRF51822 processor on the BluChip.  The following software needs to be downloaded and installed:


Programming the BluChip

There are several ways to program the BluChip and the correct way generally depends on the situation. With a BluChip that has previously been programmed the application can be reprogrammed through Keil (installed above) or Over-The-Air (OTA). If the BluChip has not been previously programmed or is in a bad state then it may need the soft device and bootloader reprogrammed.

Quick explanation of firmware

  • Application - This is the program running on the device - generally this is the only code that the developer will modify
  • Soft Device - This is the hardware/blutooth control software provided by Nordic.  The BluChip ships with v8.0.0 installed.
  • Bootloader - The bootloader provides the Over-The-Air (OTA) update capability

**You can learn more about the bootloader and soft device in the Nordic Forums. We chose the Nordic nrf51822 as the basis for BluChip because of the outstanding support provided by Nordic.


Creating the Hex File

In order to program the BluChip you must create a hex file containing the program.  This can be done using Keil uVision.  

  1. Open uVision and select Open Project from the Project menu
  2. Navigate to /PATH_TO_SDK/examples/ble_peripheral/ble_bluchip/bluchip/s110_with_dfu/arm4/ and open the ble_bluchip_s110_with_dfu.uvproj project file
    1. This assumes the SDK was unzipped to PATH_TO_SDK and that the ble_bluchip was placed in the examples/ble_peripheral directory as describedin "The Software" above
  3. Make a simple change to the code to demonstrate that the BluChip has been reprogrammed
    1. In Application->main.c edit the DEVICE_NAME define to be "BluLite" or something similar
  4. From the Project menu select Rebuild all Target Files

At this point your custom hex file is now available at /PATH_TO_SDK/examples/ble_peripheral/ble_bluchip/bluchip/s110_with_dfu/arm4/_build/nrf51422_xxac_s110.hex


Transferring the Hex File

As outlined above there are several ways to transfer the hex file three of which are briefly covered below

Using Keil and CMSIS/DAP

  1. Open the project in Keil
  2. Verify your CMSIS/DAP programmer is plugged in to the PC and connected to the BluChip
  3. Select Flash->Configure Flash Tools.
  4. Select the Debug tab
  5. In the upper right drop-down box select CMSIS-DAP Debugger
  6. Click on Settings
    1. In the upper left drop-down box "IBDAP-..." should be selected and there should be an ARM CoreSight SW-DP device in the SW Device box
  7. Click OK
  8. You can now flash->Download the code on your devic
    1. After loading the code a reset (power on/off) may be required of the BluChip
Example CMSIS-DAP settings dialog

Example CMSIS-DAP settings dialog

Transfer via Over-The-Air programming
With a BluChip that has already been programmed and setup this is a convenient method for programming. To do over the air programming you can install Nordic's Master Control panel on your phone or computer. To use it on your PC a Master Emulator USB stick is required.  

With a PC your hex file can be transferred directly as an Application image.  With mobile devices you may need to create a zip file that includes the init packet.  The Nordic message boards have a great example.

Programming via OpenOCD with CMSIS/DAP

To program the bootloader and softdevice, along with the application, using the CMSIS-DAP debugger it is necessary to use OpenOCD.  Downloading OpenOCD and using it is outlined in an IBDAP (CMSIS-DAP device) user guide provided by adafruit.

https://cdn-shop.adafruit.com/product-files/2764/c4119_IBDAP-User-Manual.pdf

An alternative method to this is using a J-Link device with nrfprog and/or nRFgo Studio.