Bluetooth Low Energy (a.k.a Bluetooth LE, BTLE, Bluetooth Smart)

Nordic S110 and S130 SoftDevices

27 Aug 2015

As you might have noticed, we have been working on integrating S110/S130 compatibility into BLE API for nRF51 targets. A final tweak is pending in the Nordic stack driver's develop branch, so this support may be available in next version of the API. (However, you can already try it with the temporary "MCU_NORDIC_16K_S110" flag, cf. step 3 below)

nRF51 SoftDevice differences

As a reminder, the SoftDevice is the firmware shipped with each application. It provides a low-level API over Bluetooth and other capabilities of the chip. Those are the major differences between the S110 version 8.0.0 and S130 version 1.0.0, for a 128k flash/16k RAM chip:

S110S130
Available memory for application:
Flash start0x180000x1c000
Flash size32k16k
RAM start0x200020000x20002800
RAM size8k6k
Supported features:
Peripheral (server)yesyes
Central (client)noyes

As you can see, S130 provides the ability to act both as a central and peripheral simultaneously. It will be able to advertise and scan for other devices. But this comes with a great price, since applications will have 2k less RAM to play with.

Switching to S110

Currently, the live IDE is only able to build S130 applications. Using S110 is possible, but will require to get your hands dirty and do a local build. I'm using HeartRate with GCC as an example. To do this, you'll need a GCC toolchain, and srecord.

First, export your program to "GCC (ARM Embedded)". Then, to check you have all the required tools, type make, followed by make merge. This should end with something like:

arm-none-eabi-size BLE_HeartRate.elf
   text	   data	    bss	    dec	    hex	filename
  24004	    128	   1640	  25772	   64ac	BLE_HeartRate.elf
srec_cat mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s130_nrf51822_1_0_0/s130_nrf51_1.0.0_softdevice.hex -intel BLE_HeartRate.hex -intel -o combined.hex -intel --line-length=44

Beware, Windows users!

If you're using a case-insensitive file system (e.g. FAT), you might encounter obscure errors, because of a conflict between ./nRF51822/source/nordic-sdk/components/softdevice/s130/include/ble.h and ./BLE_API/ble/BLE.h. This will also be fixed when moving to yotta. The simplest solution I can see now, is removing -I./BLE_API/ble from INCLUDE_PATHS line in the Makefile. With this, BLE.h will only be accessible with #include "ble/BLE.h", which is already the conventional way to include it.

1. Change the linker script

The linker script specifies the layout of the final image. It is located in mbed/TARGET_NRF51822/TOOLCHAIN_GCC_ARM/NRF51822.ld What we're interested in is the memory section. This is the one for a 128K/16K chip:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x0001C000, LENGTH = 0x24000
  RAM (rwx) :  ORIGIN = 0x20002800, LENGTH = 0x1800
}

You will want the following layout (see the above table for explanations):

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00018000, LENGTH = 0x28000
  RAM (rwx) :  ORIGIN = 0x20002000, LENGTH = 0x2000
}

With armcc, this file is called "nRF51822.sct" for "scatter file" and has a different format, but serves the same purpose.

2. Change the SoftDevice

Change this line:

SOFTDEVICE = mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s130_nrf51822_1_0_0/s130_nrf51_1.0.0_softdevice.hex

with that one:

SOFTDEVICE = mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_8_0_0/s110_nrf51822_8.0.0_softdevice.hex

3. Disable GattClient

That's the simplest part! Just add the following symbol to your build (CC_SYMBOLS): -DMCU_NRF51_16K_S110.

After a make clean all merge, you should see something like this:

arm-none-eabi-size BLE_HeartRate.elf
   text	   data	    bss	    dec	    hex	filename
  21500	    128	   1296	  22924	   598c	BLE_HeartRate.elf

srec_cat mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_8_0_0/s110_nrf51822_8.0.0_softdevice.hex -intel BLE_HeartRate.hex -intel -o combined.hex -intel --line-length=44
                                                                      ^
Now using S110 SD ----------------------------------------------------'

Also notice that we now have 16 + 2k more flash, and 2000 + 344 more bytes of RAM :)

27 Aug 2015

Hi Jean-Philippe

Thank you very much for bringing back s110 support!! As I use a 16K Ram chip that makes my life much easier (no forking or fiddling with Nordic SDK to get the s110 hex etc.)