How to Get Started With IDE for NRF51822, ARM® KEIL MDK V5 + ST-Link

by bitterbroccoli in Circuits > Microcontrollers

5113 Views, 4 Favorites, 0 Comments

How to Get Started With IDE for NRF51822, ARM® KEIL MDK V5 + ST-Link

DSC_0007.jpg
DSC_0008.jpg

Overview

When I started to develop a nRF51822 application for my hobby project, I found that there was not organised information on this topic. Here, thus, I would like to note what I have gotten through.

This describes what makes me struggle to implement a "Softdevice" example app onto the board. The programming of the ble_app_hrm application which is provided from Nordic's SDK is presented here.

And as shown in the 1st image, ST Nucleo-F401RE, Waveshare BLE400 and nRF51822 Board have been used, but BLE400 is not necessary as far as you can connect ST-Link and your nRF51822 board.

And the advantage of using ST-Link on Nucleo has been taken to supply the power of 3.3 or 5V to the nRF51822 board. So, a power supply may have to be prepared when using a ST-Link device because some of ST-Link devices seem not to have a capability of powering up a microcontroller.

I found out that my nRF51822 board is "nRF51822_xxAA" which has 256kB ROM (program memory size) and 16kB RAM (the 2nd image).

The procedure contains the following steps.

  1. Software Installation
  2. Hardware Connection
  3. Software Settings
  4. Compile and Load
  5. Run the app on a mobile phone (Android)

All the information are obtained as of September 28, 2018.

Software Installation

Image.png
Image.png

Download MDK-ARM v5.26 or later from ARM KEIL and install it in Windows 10. Once installed, Keil µVision IDE is installed with ARM CMSIS and such. But, then, the system does not have any Nordic SDKs installed.

When Keil µVision IDE first starts, Pack Installer launches. In Pack Installer, software packages necessary for the target board to be developed can be installed.

See the 1st image.

It is a good idea to click the "Check For Updates" button to update Pack Installer beforehand.

In the Devices tab, search for and select the target device, "nRF51822_xxAA" so that the related packages appear in the Examples tab.

In this instructable, I selected "ble_app_hrs_s130_pca10028 (nRF51 PCA10028)". Don't forget to uncheck "Show examples from installed Packs only" to find the project in the Example tab since any installation is not done yet at this point.

Click the "Install" button to start to unpack (and also copy) the example project. During copying the project to your arbitrary directory, you are asked a couple of times to install the other Software Packs required by the project.

See the 2nd image.

After the installation completed, µVision opens the project.

Note that the original project is located in C:\Keil_v5\ARM\PACK\NordicSemiconductor\nRF_Examples\11.0.0-2.alpha\ble_peripheral\ble_app_hrs\pca10028\s130\arm5.

Hardware Connection

connection.png

Here, the image shows the actual wiring diagram.

The image presents a way of the connection of ST-Link and BLE400 with a nRF51822 board. Only 4 cables are needed as the following table.

ST-Link (Nucleo) ---> nRF51822

-------------------------------------------------

+5V ---> USB5V

GND ---> GND

SWCLK ---> SWDCLK

SWDIO ---> SWDIO

To select ST-Link, the "CN2" jumpers must be open as shown in the diagram.

Note: Instead supplying the power of 3.3V works as well.

Software Settings

setting.JPG
Image.png
includeHeaders.png
Image.png
Image.png
Image.png
Image.png

The procedure in this part must be followed, otherwise it doesn't get anywhere.

See the 1st image.

(1) First of all, select "nrf51422_xxac_s130" from the "Select Target" drop-down menu in the toolbar of µVision. The name is different from the target device, but this will do due to their compatibility.

See the 2nd image

(2) In the Project window, left-click "main.c" in the Application folder and select "Translate main.c" in the context menu so as to include the necessary headers (the 3rd image). Note that "nrf51422_xxac_s130" has to be selected at this point or this operation does not work.

(3) Click the "Option For Target" to configure the IDE (the 1st image). As the previous operation, "Translate" has set the target microcontroller correctly, it is confirmed that IROM1:0x1B000 in Start, 0x25000 in Size and IRAM:0x20001F00 in Start, 0x6100 in Size as seen in the Target tab (the 4th image).

See the 5th image.

(4) In the Debug tab, select "ST-Link Debugger" from the "Use:" drop-down.

(5) Click the "Settings" button to open up the "Cortex-M Target Driver Setup" window. Confirm that the Debug tab indicates that the target microcontroller is connected (the 6th image). If it dose not, go back to the Hardware Connection section and check the connection again.

See the 7th image.

(6) In the Flash Download tab, click the "Add" button in the Programming Algorithm and add "nRF51xxx External Connectivity Board". In addition, "Reset and Run" can be checked to let ST-Link reset and run the program.

Click OK and close "Option For Target" window.

(7) Next, select "flash_s130_nrf51_x.x.x-x-x_softdevice" from the "Select Target" drop-down menu in the toolbar.

(8) Click the "Option For Target". In the Debug tab, select "ST-Link Debugger" from the "Use:" drop-down.

(9) Click the "Settings" button to open the "Cortex-M Target Driver Setup" window. Again make sure the Debug tab indicates that the target device is connected. If it dose not, go back to the Hardware Connection section and check the connection again.

(10) In the Flash Download tab, click the "Add" button in the "Programming Algorithm" and add "nRF51xxx External Connectivity Board". And "Erase Full Chip" in "Download Function" can be selected to let ST-Link erase the board memory at the beginning of flashing instead of manually erasing.

Click OK and close "Option For Target" window.

Now that you are ready to compile the code and flash the nRF51822.

Note that although the Device tab in "Option For Target" shows that nRF51422_xxAC has been selected, that works all right.

Compile and Load

BuildFlash.png
flash.JPG
build.JPG
flash2.JPG
MOV 0009

First of all, here, select "flash_s130_nrf51_x.x.x-x-x_softdevice" from the "Select Target" drop-down menu in the toolbar and click the Download button to flash the memory. You see "Verify OK" if the download is successful (the 1st & 2nd image).

Then, select "nrf51422_xxac_s130" from the "Select Target" drop-down menu and click the Build button to compile the code. You see the message as shown in the 3rd image.

Next, click the Download button to flash the memory. You see the same message as the 4th image.

After successfully completing the flashing, you see the LED3 is blinking (video).

Now, installing the app in your mobile phone, you see what the program does.

Run the App on a Mobile Phone

DSC_0010[1].JPG
MOV 00111

Install the "nRF Toolbox for BLE" app from Nordic Semiconductor in a mobile phone or pad (the 1st image).

Start up the HRM and connect the nRF51822 (video).

Summary

There were some points in this instructable;

  1. power the nRF51822 board in order to connect ST-Link

  2. translate the main.c file before compiling and downloading the code if an example project is copied in a directory other than the original directory

  3. set "nRF51xxx External Connectivity Board" in the Programming Algorithm section

I hope this instruction will help those hobbyists like me.