
Hello.
For a while I had the idea to write an article about this stack, its features and applications using the nRF51822 chip. And the recent publication "
BLE stack from TI " made me sit down and try to turn the idea into something tangible.
Nordic Semiconductor provides a very interesting, in my opinion, solution. On the one hand, there is a powerful chip on the ARM Cortex-M0 core, on the other hand, the constantly evolving stack software and a set of libraries included in the SDK.
')
Unfortunately, on Habré there are no articles on the subject of BLE on NORDIC, as in other matters, there are practically no articles in runet, so I hope that the article will be useful to those who are beginning to use the products of this company in the part concerning BLE, Those who are interested in Bluetooth technology and BLE in particular.
1. Iron
The nRF51822 chip considered by us from the side of the memory size is presented in 3 variants:
- 256KB flash and 16KB of RAM;
- 128KB flash and 16KB RAM;
- 256KB flash and 32KB of RAM.
In this case, the RAM is divided into blocks and each block has its own power management. I focus on this attention, because when programming a chip you need to know that the application uses the upper half of the RAM, while the younger half is always used by the stack.
Depending on the stack version, the client software loading address may also change. It is also necessary to pay attention. If you incorrectly specify the address of the software download, the programmer will give an error, according to which you can never understand why it was not possible to flash the chip. The software download address is indicated in the specification for each version of the stack.
So, if you decide to work with BLE from NORDIC, then first of all you need to purchase one of the debugging kits. Here are some of them:
-
nRF51822 Evaluation Kit (EK) is an independent platform for evaluation and prototyping, based on the nRF51822 chip.

The kit includes:
- A board with a chip, with a pair of buttons and a pair of LEDs. On the board is the Segger programmer, which has its own unique number, which allows us to program our chip, make debugging and, not least, allow us to use the UART to communicate with the computer nRF51822 via USB;
- USB dongle, also with the nRF51822 chip and the Segger programmer, which has a special NORDIC firmware and is used to communicate with the board.
-
nRF51822 Development Kit (DK) - platform dependent on the “Starter Kit”, makes it possible to create full-fledged applications using not only BLE, but also all the resources of the nRF51822 chip, like a microcontroller.

The kit includes:
- board with nRF51822 and PCB antenna;
- board with nRF51822 and with antenna connector;
- USB dongle is the same as in EK;
- 5 chips nRF51822;
- programmer
By the way, “dependence” on the “Starter Kit” is not critical, if you know how to use a soldering iron or you have a prototype board and wiring.
-
nRF51822 Starter Kit (SK) is a kind of “motherboard” to which you can connect the EK and DK to use all the features of the nRF51822 chip.

The kit includes 2 motherboards with cable sets.

Recently, the company does not recommend using EK and DK, since new debug kits have appeared: "
nRF51 DK " and "
nRF51 Dongle ", but I believe that EK and DK are still a very good tool for learning and prototyping.
Currently, my task uses nRF51822 DK without SK. Thanks to the connectors on the DK cards, you can connect any peripherals, such as LEDs, to indicate the presence of a connection or some kind of error, using connecting wires and a breadboard model. A feature of using DK without SK is that the DK board needs to be powered, and for this you need to know the pinout of the card's connectors.

It is in the document "nRF51822_Development_Kit_User_Guide". Due to the fact that I use the STM32L152-DISCOVERY debugging module as the “super-host” for the nRF51822, the 3.3V power supply is supplied from there.
Nuance: until you purchase one of the sets, you cannot download from the site neither the specification, nor the stack, nor the software, except for the software “nRFgo Studio” and documentation on the chips.Each debugging kit has its own unique number (key) pasted on the box with the kit. After buying a set, you need to register on the site and in the user profile enter the key indicated on the box. After that, you will be available:
- product specifications;
- user manuals;
- specification, firmware and stack API;
- software;
- "Reference layout";
2. Software offered by NORDIC
- SoftDevice S110 stack (S120, S130) - contains API header files and a binary (HEX) file which contains the stack firmware (for each type of stack, its own HEX). There is no source code for the stack itself.
- nRF51 SDK - contains the header files of the API to the stack, as well as the source codes of the libraries in the C language to simplify working with the stack and peripherals of the nRF51422 and nRF51822 chips;
- Master Control Panel (MCP) - 32 and 64 bit software designed to work with USB dongle and allows you to search for devices, discover services, read the attributes of services, establish a Bluetooth connection, receive and transmit data. In server mode, it is possible to create any services, with characteristics defined both in the Bluetooth SIG, and with its own. In general, this is the main program for debugging your software on the other side of a wireless connection. Installing the Master Control Panel also installs software called the “Master Emulator”. About him in few places written, but it may appeal to many developers. The fact is that this is an API that allows you to create a .NET PC application with the role of master device.
- nRFgo Studio - 32 and 64 bit software designed for stack firmware and client software. Also, it can be used to change the firmware of motherboards included in the SK package; create your services, including on your own UUIDs; configure connection security settings, configure GAP and advertising, configure chip periphery, calculate chip energy consumption and much more.
- nRF Sniffer - software for viewing packets transmitted from one device to another;
- The nRF51-BLE-Driver is actually not a driver in the usual sense of the word. This is a DLL that provides an API to the stack in the C language. Thanks to it, you can write a PC application that will communicate with the stack, which can be embedded into a USB dongle, which is part of a DK or EK. The API provides an implementation of the peripheral role only.
- You can also download the source code of Android and iOS applications that allow you to work with debugging kits. The applications themselves can be found in the respective app store platforms. Applications allow you to test for example, the work of updating the firmware over the air (DFU - Device Firmware Update Service) or UART via Bluetooth.
3. Development Tools
For programming, you can use both paid and free development tools. NORDIC suggests using Keil MDK-ARM, IAR, as well as any IDE that allows you to work with GCC ARM. To work with GCC, a document called “nAN-29 nRF51 Development with GCC and Eclipse Application Note” is proposed, which describes suggestions for developers who want to use Eclipse, GCC and GDB.
NORDIC thinks Keil is preferable to use, and even the “nRF51 SDK” installer integrates the SDK into Keil, making it easier to create an application project. All examples in the SDK have Keil format project files.

4. SoftDevice stack
The stack is offered in 3 versions.
- S110 SoftDevice –is intended for use in case your device should have the role of a peripheral device (Peripheral / Broadcaster).
- S120 SoftDevice - designed for use in case your device should be a central device (Central / Observer). This stack can support up to 8 simultaneous connections to peripheral devices.
- S120 SoftDevice - designed for use in case your device should be both peripheral and central (Central / Peripheral / Broadcaster / Observer).
The API of any of the stack options allows you to control both the BLE controller and the host, i.e. and other peripherals included in the chip. It is more correct to say this: if you use the SoftDevice stack, then the rest of the periphery is managed through the stack API and it controls what and when to use it. Naturally, the chip can be used without any stack at all, just like a regular microcontroller.
The release information for the next version of the SDK always indicates the supported stack version. This is very important, because the first thing a programmer encounters is the impossibility to flash his program due to the inconsistency between the SDK version and SoftDevice. For example, the SDK version 6.1.0 works with the following stack versions: S110 - 7.0.0, 7.1.0; S120 - 1.0.0.
5. Firmware stack and client application.
Due to the fact that the stack is offered only as a binary firmware file, the question arises: how to work with the chip if you need to sew both the stack and your program?


As can be seen from these two figures, the stack is sewn to the bottom of the flash memory and uses the lower half of the RAM, starting at 0x2000000. The application is sewn into flash memory, starting from the address CODE_R1_BASE uses RAM from the address RAM_R1_BASE.
The variables CODE_R1_BASE and RAM_R1_BASE differ depending on the stack version.
The stack is sewn using the “nRFgo Studio” program once, after which you can write your application and sew it with either “nRFgo Studio” or, more conveniently, using Keil.


The stack HEX file is sewn once, after which you can write your application and sew it or “nRFgo Studio” or, more conveniently, using Keil.
Here is an example of setting up memory in Keil for S110 v.6.0.0 stack:

The CODE_R1_BASE is 0x16000, and the RAM_R1_BASE is 0x20002000.
And here is an example of setting memory in Keil for the S120 v.1.0.0 stack:

The CODE_R1_BASE is 0x18000, and the RAM_R1_BASE is 0x20002800
6. Conclusion
The SDK offers a large number of examples of using the nRF51822 chip both as a simple microcontroller and as a stack. Thanks to the examples, you can quickly master the programming of the chip in parallel by studying all the subtleties of the SDK, and there are not enough of them.
NORDIC has created a good forum where you can get an answer to almost any question. Employees of the company often answer questions themselves and rather quickly.
Thank you for reading my article to the end. If you are interested and I pass the sandbox, then in the next article I will talk about the features of implementing client software using the SDK stack.
I would like to wish you good luck and success in mastering and using Nordic Semiconductor products, I personally like their solutions.
Thanks for attention.