nRF51/nRF52

Developing nRF51 & nRF52 series software using Eclipse

Bluetooth® Low Energy SoC





I have been building BLE applications using Nordic’s popular nRF51822, nRF51422 & nRF52832 series ultra low power System on Chip (SoC).   It integrates the nRF51 series 2.4GHz transceiver, a 32 bits ARM® Cortex-M0 MCU, Flash memory, analog and digital I/O, supporting both Bluetooth Low Energy, ANT and proprietary protocols.  The nRF52 series sports a Cortex-M4 MCU.  It took me longer than I would have liked to get the development, debug, and build environment up and running on my Mac.  I hope this post gives you insight into the lessons I learned along the way - saving you precious time along the way.

Things I have built are the modules and CMSIS-DAP Debug JTAG programmer that I am selling.  The one in the picture bellow integrates an nRF51822 with all available I/O are routed out to the pads.  The pads are both through hole and SMT so that it can be easily prototype any application and SMD in for production.  There are 3 modules IMM-NRF51822, IMM-NRF51422 and IMM-NRF52832.  They are all pin compatible, though you can use any module interchangeably on your PCB.  The IMM-NRF52832 is going to be available around June time frame.


IMM-NRF51422 micromodule 23x17mm with all I/O routed out.
IMM-NRF52832 available now

Available on Tindie


The software development environment with Eclipse & GCC


While there are several IDE options, I chose the Eclipse IDE because it fully free and available cross platforms Windows, OS X & Linux.


  • Follow the Eclipse page on this blog to setup the Eclipse development environment for ARM.   
  • Clone the EHAL source tree.   This can be done using git command line tools or use SourceTree from this site http://www.sourcetreeapp.com.  github : https://github.com/I-SYST/EHAL
  • Download the Nordic Bluetooth SDK from Nordic Semiconductor.  
  • Put the SDK in the nrf51_sdk folder in the nRF51 Eclipse workspace. 
  • Download the CMSIS SDK, follow the EHAL page to download and setup the environment.


The  development source tree should look like bellow :

/your_root     - Development root directory
 |-- external    - Contains downloaded SDKs from silicon vendors
 |   |-- CMSIS            - ARM CMSIS SDK for all ARM platform (download from ARM)
 |   |   |--CMSIS
 |   |   |...
 |   |-- nRF5_SDK_12    - Nordic SDK 12, nRF51 & nRF52 (download from nordicsemi.com)
 |   |   |   |-- components
 |   |   |   |-- examples
 |   |   |   |-- external
 |   |   |   |   |--- micro-ecc
 |   |   |   |   |   |--- micro-ecc - Micro-ECC (download from https://github.com/kmackay/micro-ecc)
 |   |   |   |...
 |   |.... 
 |   |-- nRF5_SDK    - Latest Nordic SDK 13+, nRF52 only (download from nordicsemi.com)
 |   |   |   |-- components
 |   |   |   |-- examples
 |   |   |   |-- external
 |   |   |   |   |--- micro-ecc
 |   |   |   |   |   |--- micro-ecc - Micro-ECC (download from https://github.com/kmackay/micro-ecc)
 |   |   |   |...
 |   |....
 |-- EHAL      - Put the EHAL here
 |   |-- include     - Generic include common to all platform
 |   |-- src            - Generic source common to all platform
 |   |-- ARM
 |   |   |-- include    - Common include for all ARM platform
 |   |   |-- src           - Common source for all ARM platform
 |   |   |-- Nordic
 |   |   |   |--include - Common include for all nRF5x 
 |   |   |   |--src        - Common source for all nRF5x
 |   |   |   |-- nRF51
 |   |   |   |   |-- CMSIS   - static library of CMSIS system functions for nRF51
 |   |   |   |   |-- EHAL    - Embedded Hardware Abstraction Library project for Nordic nRF51 (static lib)
 |   |   |   |   |   |-- include
 |   |   |   |   |   |-- src
 |   |   |   |   |-- exemples - exemple projects
 |   |   |   |   |   |--dfu      - SDK12 Secure DFU 
 |   |   |   |   |...
 |   |   |   |-- nRF52
 |   |   |   |   |-- CMSIS   - static library of CMSIS system functions for nRF51
 |   |   |   |   |-- EHAL    - Embedded Hardware Abstraction Library project for Nordic nRF51 (static lib)
 |   |   |   |   |   |-- include
 |   |   |   |   |   |-- src
 |   |   |   |   |-- exemples - example projects are in here
 |   |   |   |   |   |--dfu      - SDK13 Secure DFU 
 |   |   |   |   |...
 |--- private   - your own private working folder
   
Start Eclipse and set the Workspace to the nRF51 folder.  Select the 'import'  to import CMSIS and EHAL projects into the workspace if it does not show up.  Do the import project without copying files since it is already located inside the workspace.

Require change to compile the SDK with GCC in the file nrf_svc.h.  This file is located in headers folder of each Softdevice.  Nordic default cast was uint8_t.  This is wrong it needs to be casted cot uint16_t

        "bx r14" : : "I" ((uint16_t)number) : "r0" \

Cast (uint16_t) is needed if you compile C++ code.  The default startup code from the SDK does not work with C++.  Use the one from EHAL.  See example code for details.

Now you can start creating projects.  To create Eclipse projects for nRF51, follow the steps further down this page.

Migrating to SDK 12  

The new nRF5 SDK12 has changed a lot. There are many compile error for GCC with C++.  The extern "C" { was added to most .h files now but you may find compile error du to the fact that the opening was placed within a conditional define and the ending was outsite or vice versa.   The SDK also contains ridiculous conditional compilation in every source files.  By adding the source file to your project is not sufficient.  You need a also add those defines for each source.  So depending on how many sources you are using from the SDK.  You may ended up with hundreds of conditional compilation defines.  The EHAL lib is already updated to SDK12.  I am updating gradually the examples to SDK.  It will take some times to get all updated.


CMSIS library


The CMSIS library project now includes build for RTX kernel in the build configurations.  Precompiled libs are available in github.  The default initialization of RTX version was modified to use RC oscillator so it can start on any nRF5x without the 32KHz Crystal.  The default RTX build from Nordic requires the 32KHz crystal to run.
  

Examples code :


Most of the examples code on this site are not Nordic examples.  They are written from scratch targeted to use with the IMM-NRF51822 module (see Hardware section bellow) and generic board.  To compile the examples, you need first compile the CMSIS library, few examples may need the EHAL library.  All BLE examples have accompanying iOS code as well.  iOS code is here : https://github.com/I-SYST/iOS

The Blinky_ble exemples is not actually to make the LED blink.  It is a custom service example that uses the iPad to configure the Gpio as input or output, turn it on/off, read it state. All 30 i/o can be controlled at once or individually.  Now SDK 8.

dfu_nrf51 is now the Eclipse project for SDK 8 DFU.  It contains only project file.  Source code are not in github.  Project has virtual link to source files in nrf51_sdk folder except for main.c and incude folder which need to be copy from the sdk sample over to DFU project folder.

dfu_sdk7 is the DFU Eclipse project for SDK 7.2.  Dfu BLE is now functional with iOS nRFToolbox 1.5.  Dfu Serial does not seems to work with nRFGo.  Currently I am too busy to debug it.  Let me know if you can get it to work in serial mode.

The LMXDisplay_ble is an example demonstrate the use of long write characteristic.  It gets a text message from a mobile device and  displays it on LED matrix multi-displays.  The LedMx library is used to control display on multiple IDM-LMX3208 series LED matrix display (See my Arduino page for more details).  The display controller is the IBB-LMXBLUE, which can dive up to 16 displays boards.

Different UART over BLE example than the one from Nordic.  This example uses only one characteristic for both TX and RX.  Uses app_uart API rather than simple_uart.

To create an Eclipse based project for nRF5x, see instruction at the end of this page.


Flashing the nRF51 & nRF52 


Nordic provides utilities to flash the nRF5x but those utilities only work with the JLink.   The Nordic development kit has an on board JLink that can be used to flash other board.  It can not be used to flash commercial products due to its usage license.  For commercial use, you need to buy the full JLink which is very expensive.   This section presents several methods to flash using the much cheaper alternative without a limited usage license.

Parallel gang Flashing nRF51 & nRF52 with IDAP-Link using IDAPnRFProg on OS X and Windows


IDAPnRFProg now allows flashing just Softdevice or combines with either app firmware and/or DFU.

IDAP-Link/M Software Download now support readback protection.  Available for OS X and Windows XP and above.

PM me if you need Linux version


Flashing Softdevice + Firmware + DFU

IDAPnRFProg s110_nrf51822_7.1.0_softdevice.hex Blinky_ble.hex dfu_sdk7.hex


$ ./IDAPnRFProg s110_nrf51_8.0.0_softdevice.hex Blinky_ble.hex dfu_nrf51.hex
IDAPnRFProg version 0.2
Copyright 2015, I-SYST inc. All rights reserved

Found IDAP-Link - S/N : 0000000000001
Found IDAP-Link - S/N : 0000000000002
IDAP-Link-0030415000005 : nRF51822-QFAA R2, Rev.2, HWID = 0x003C, DEVID = 0x299C1D17BD361134
IDAP-Link-0030415000005 : Flash size = 262144, Ram size = 16384
IDAP-Link-0030415000017 : nRF51822-QFAA R1, Rev.1, HWID = 0x001D, DEVID = 0x32B4DDFECEE22394
IDAP-Link-0030415000017 : Flash size = 262144, Ram size = 16384

IDAP-Link found : 2

IDAP-Link-0030415000005 : Erase Flash
IDAP-Link-0030415000017 : Erase Flash
IDAP-Link-0030415000005 : Blank checking...
IDAP-Link-0030415000017 : Blank checking...
IDAP-Link-0030415000005 : Programming...
IDAP-Link-0030415000017 : Programming...
IDAP-Link-0030415000005 : Firmware start address 0x18000
IDAP-Link-0030415000005 : DFU start address 0x3c000
IDAP-Link-0030415000017 : Firmware start address 0x18000
IDAP-Link-0030415000017 : DFU start address 0x3c000
IDAP-Link-0030415000005 : Programmed 256 KB in 21.524 sec at rate 11.894 KB/s
IDAP-Link-0030415000005 : Verifying...
IDAP-Link-0030415000017 : Programmed 256 KB in 21.524 sec at rate 11.894 KB/s
IDAP-Link-0030415000017 : Verifying...
IDAP-Link-0030415000005 : Flashing succeeded.
IDAP-Link-0030415000017 : Flashing succeeded.

Total Flashed 2 nRF51 devices in 51.112 sec, 1024 KB R/W transfered, rate = 20.035 KB/s



Flashing nRF5x using microSD card with IDAP-Link

Prerequisite :

Prio to use this Flashing method.  The IDAP-Link must set to nRF51 target.  Use the IDAPSetTarget command line program to set it.  Executing IDAPSetTarget without any argument will show a list of available target core.  Then execute IDAPSetTarget again with the nRF51 target index number to set it.  This is needed to be done only once.  IDAPSetTarget is needed again only when target change is needed.  The IDAP firmware can only recognized predefined file name when Flashing with this method.  File naming is preset by the target definition.  For nRF51 file name must be as follow:

Softdevice.hex - for softdevice
firmware.hex - Application firmware
DFU.hex - OTA Bootloader

It is not require to have all 3 files to flash.  Copy the require files onto a microSD card.  Insert it in the IDAP-Link.  Power the IDAP-Link.  Press ISP/Program button.  The green LED will light up.  When Flashing is done, all LED are off if successful.  Blink red LED if failed.  If the IDAP-Link is still connected to PC, make sure to eject USB MSC from the PC for better Flashing performance.  Normally it should take about 26s to flash all 3 hex files.  If the USB MSC is not ejected from the PC, it may take a lot longer depending how much access the PC is performing on the microSD.  It is due to PC access has priority over the internal access.

Flashing softdevice with OpenOCD.


Using low cost alternative IDAP-Link.  You can flash the softdevice using OpenOCD command.  Version 0.9 is require.  To install latest OpenOCD on OS X using the command

brew install --HEAD openocd

Then flash Softdevice with

openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg -c "program s110.hex verify"

Unlock nRF52 protection using OpenOCD

openocd -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "program dap apreg 1 0x04 0x01"

Eclipse debugging using IDAP-Link with OpenOCD

Create an OpenOCD debug configuration.  Set the OpneOCD config option in the Debuger tab with :

-f interface/cmsis-dap.cfg
-f target/nrf51.cfg
-c "cms-dap-serial ###"

where ### is the serial # of IDAP-Link to use when multiple IDAP-Link are connected to the same PC (see IDAP-Link page for more details)









The Hardware


IMM-NRF51822, IMM-NRF51422 & IMM-NRF52832 


The IMM-NRF5x series are 23 x 17 mm micro-module with embedded PCB antenna.  It allows developers to take full advantage of the nRF5x series by making all its I/O available via 35 SMD/Through hole 1.27mm pitch pads.   The module can be mounted with header pins in order to re-use during development and prototyping phase and SMD it for production to be the most cost effective.  IMM-NRF51822 ModuleModule user man




IMM-NRF51822 and IMM-NRF51422 micromodule 23x17mm with all I/O routed out.

Also available on Tindie and SemiconductorStore


IBK-BLUEIO
Breakout PCB for the IMM-NRF5x modules available on
Tindie

I/O layout of the IMM-NRF51822 module.  All 30 I/O pins are routed to the pads.

Debug JTag connection


The IMM-NRF51822 micro-module has exposed the SWD (Serial Wire Debug) pins SWDIO & SWCLK, see I/O layout picture above. The module can be directly connected to a Jtag tool for development by wiring the 2 SWD pins to the appropriate pins on the Jtag connector. The VIN must be wire to the VCC pin on the Jtag. GND pad is also require to be connected to GND on Jtag.  The default JTAG supported by Nordic is the Segger.  Other low cost option is using CMSIS-DAP JTAG such as the IDAP-Link.  The IDAP-Link can also be used for production flashing multi-boards in parallel.  See IDAP-Link page for details.



IMM-NRF51822 mounted on breakout board connected to the IDAP-Link.
3.3v power is provided by the IDAP-Link.



Other accessories





UART to RS-232 Breakout board
Available on Tindie






Creating Eclipse project


To create a new nRF51 project with Eclipse, select New from the File menu then select either you want C or C++ project.  In the dialog, select the project type 'Hello World ARM ..." with toolchains 'Cross ARM GCC'.  Do not use any other templates.

Once the new project is created, open project settings dialog.  Change the target processor to Cortex-M0 for nRF51 and Cortex-M4 for nRF52

Set target processor to cortex-m0

There are a few preprocessor definitions require by the SDK.  If BLE stack not needed, only NRF51 or NRF52 is required.  If BLE stack is needed, the following are required

BLE_STACK_SUPPORT_REQD
NRF51

Preprocessor settings


In case of a C++ project, those preprocessor settings are also needed to be set in C++ preprocessor section.  Next are the include path settings.  Assuming the SDK is located in nrf51_sdk as described previously.  These are the minimum require include paths for BLE project.



For SDK 6 :

"${ProjDirPath}/src"
"${ProjDirPath}/../../EHAL/include"
"${ProjDirPath}/../../CMSIS/include"
"${ProjDirPath}/../../../../../include"
"${ProjDirPath}/../../../../CMSIS/CMSIS/include"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/sdk"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble/device_manager"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble/ble_services"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/sd_common"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/s110"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/app_common"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/gcc"
"${ProjDirPath}/../../nrf51_sdk/nrf51822/Include"

For SDK 8, the way the folders are organized is the worst.

"${ProjDirPath}/src"
"${ProjDirPath}/../../EHAL/include"
"${ProjDirPath}/../../CMSIS/include"
"${ProjDirPath}/../../../../../include"
"${ProjDirPath}/../../../../CMSIS/CMSIS/include"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_hids"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu/experimental"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/gpiote"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_debug_assert_handler"
"${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/ble_flash"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_error_log"
"${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/pstorage"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/trace"
"${ProjDirPath}/../../nrf51_sdk/components/softdevice/common/softdevice_handler"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/timer"
"${ProjDirPath}/../../nrf51_sdk/components/softdevice/s110/headers"
"${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/nrf_soc_nosd"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/util"
"${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/hal"
"${ProjDirPath}/../../nrf51_sdk/components/device"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/scheduler"
"${ProjDirPath}/../../nrf51_sdk/components/ble/common"
"${ProjDirPath}/../../nrf51_sdk/components/ble/device_manager"
"${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu/ble_transport"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_bas"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_dfu"
"${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_dis"

For SDK11

"${ProjDirPath}/src"
"${ProjDirPath}/../../EHAL/include"
"${ProjDirPath}/../../CMSIS/include"
"${ProjDirPath}/../../../../include"
"${ProjDirPath}/../../../../../include"
"${ProjDirPath}/../../../../CMSIS/CMSIS/include"
"${ProjDirPath}/../../../nrf5_sdk/components/device"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/bootloader_dfu"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/fstorage"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/gpiote"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/timer"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/scheduler"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/trace"
"${ProjDirPath}/../../../nrf5_sdk/components/libraries/util"
"${ProjDirPath}/../../../nrf5_sdk/components/drivers_nrf/hal"
"${ProjDirPath}/../../../nrf5_sdk/components/drivers_nrf/delay"
"${ProjDirPath}/../../../nrf5_sdk/components/drivers_nrf/ble_flash"
"${ProjDirPath}/../../../nrf5_sdk/components/drivers_nrf/pstorage"
"${ProjDirPath}/../../../nrf5_sdk/components/drivers_nrf/common"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/common"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/device_manager"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/advertising"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/ble_debug_assert_handler"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/ble_error_log"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/ble_services/ble_bas"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/ble_services/ble_dfu"
"${ProjDirPath}/../../../nrf5_sdk/components/ble/ble_services/ble_dis"
"${ProjDirPath}/../../../nrf5_sdk/components/softdevice/common/softdevice_handler"
"${ProjDirPath}/../../../nrf5_sdk/components/softdevice/s130/headers"

There are a few to set in the linker settings as well.  First thing is the linker script.

for BLE project

"${ProjDirPath}/../../src/gcc_nrf51_s110_xxaa.ld"

Non BLE project

"${ProjDirPath}/../../src/gcc_nrf51_blank_xxaa.ld"

Linker settings
Require libraries and path in linker setting.  Minimum require is the CMSIS lib.  Set the library path to

"${ProjDirPath}/../../CMSIS/Debug"  - Debug build
"${ProjDirPath}/../../CMSIS/Release" - Release build

Optionally if EHAL is used, add EHAL to the lib and path

"${ProjDirPath}/../../EHAL/Debug"
"${ProjDirPath}/../../EHAL/Release"


Library & path for the linker


That's about it for project settings.  What's left to do is to add source code in the project.

Add source files


There are many files to be added to the project depending on what is require for the application.  One file must always be added to all projects is the Vector_nRF51.c.  It is located in scr folder in the nRF51 workspace.  It is the interrupt vector and the reset function.  It can be added by doing import then chose filesystem.




142 comments:

  1. I'm working on setting up eclipse to build for the NRF51822. While building CMSIS it had a file it couldn't find. ResetEntry.c I deleted the references and then CMSIS built fine but when i went to build Blinky_ble im getting a "undefined reference to "ResetEntry" Is there a file missing?
    Thanks for the help
    Nate

    ReplyDelete
    Replies
    1. The ResetEntry.c is generic to all ARM based. It is located in ARM/src. See the folder structure. In CMSIS project should it is relatively linked to that file. If you have a different folder structure, then you should update the links accordingly. The hierarchical folder structure is described in EHAL page.

      Delete
  2. I tried to setup my folder structure to follow what you said here. But can't find that file either in the SDK or the files from you GIT. Where can I get that file?
    Thanks

    ReplyDelete
    Replies
    1. For some unknown reason, the file disappeared from the git repo. I just put it back. Please try again. Should be in ARM/src

      Delete
    2. Just saw it, thank you for your help

      Delete
    3. Actually thank you for reporting the problem. If you find any thing wrong or have suggestion for improvement, please let me know. Thanks

      Delete
  3. Great tutorial !
    i am struggling with 1 problem building the Blinky_ble project...
    I got this error:

    23:42:35 **** Incremental Build of configuration Debug for project Blinky_ble ****
    make all
    Building target: Blinky_ble.elf
    Invoking: Cross ARM C Linker
    arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g3 -T "/Development/EHAL-master/ARM/Nordic/nRF51/src/gcc_nrf51_s110_xxaa.ld" -nodefaultlibs -Xlinker --gc-sections -L/Development/EHAL-master/ARM/Nordic/nRF51/CMSIS/Debug -L/Development/EHAL-master/ARM/Nordic/nRF51/CMSIS/Release -Wl,-Map,"Blinky_ble.map" -o "Blinky_ble.elf" ./src/BlinkyBleMain.o ./src/BlinkyBleService.o -lCMSIS
    /usr/local/gcc-arm-none-eabi-4_8-2014q3/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: cannot find -lCMSIS
    /usr/local/gcc-arm-none-eabi-4_8-2014q3/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: cannot find -lCMSIS
    collect2: error: ld returned 1 exit status
    make: *** [Blinky_ble.elf] Error 1

    But I have CMSIS linked to the project in the Cross ARM C Linker:
    /Development/EHAL-master/ARM/Nordic/nRF51/CMSIS/Debug
    /Development/EHAL-master/ARM/Nordic/nRF51/CMSIS/Release

    and I successfully build the CMSIS project before the Blinky_ble, with some files generated in the /Development/EHAL-master/ARM/Nordic/nRF51/CMSIS/Debug folder, not in the Release one.

    Thanks.

    ReplyDelete
    Replies
    1. each project has 2 build target Debug and Release. You can set the default build target via the build icon on the tool bar. In other word, you need to build the CMSIS library for Debug and Release to have both libraries available for other projects.

      Delete
    2. ok, Thanks ! It works ... I am totally a beginner to all of this ;-)

      Delete
    3. You're welcome! Just post a message or PM me if you need help.

      Delete
  4. Building the Debug target project would generate an .out file for debug purposes ?
    I see the .bin, .elf, .hex, .map, but not the .out
    Best Regards

    ReplyDelete
    Replies
    1. In embedded usually .elf is the one to use. The .out is usually for desktop computer system. When creating a new Debug Configuration for a project, click on 'Search Project' button. It will find the the correct file for you.

      Delete
  5. hi!!
    great tutorial!
    but what should I do to compile CMSIS for the first time?
    thank you very much

    ReplyDelete
    Replies
    1. Thanks. When you open Eclipse, set the Workspace to the nRF51 folder of the source tree. The CMSIS project is already created. If you don't see it, just do an import project.

      Delete
  6. The SDK structure has changed in version 7 and the prior versions of the SDK appear to no longer be available. Can you address this problem? Using the instructions above but the nRF51_SDK_7.1.0_372d17a SDK results in odd build problems such as:


    make: *** target pattern contains no '%'. Stop. subdir.mk /CMSIS/Debug/src line 20 C/C++ Problem


    ReplyDelete
    Replies
    1. The CMSIS library has been updated. It now uses the ARM CMSIS SDK 4.2 and nRF51 SDK 7. Follow the Eclipse page to download and setup the ARM CMSIS SDK.

      Delete
    2. All projects are now updated with ARM CMSIS SDK 4.2 and nRF51 SDK 7.1 except for DFU project.

      Delete
  7. Hi,
    is the file BlinkyBle-Prefix.pch needed to build the IOS project ???
    I got this error trying to build it:

    clang: error: no such file or directory: '/Users/joan/Downloads/iOS-master 2/BlinkyBle/BlinkyBle/BlinkyBle-Prefix.pch'
    clang: error: no input files
    Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

    Thanks

    ReplyDelete
    Replies
    1. The .pch file is the precompiled header generated by the compiler when you compile. Try do a clean then build see if you still get the error.

      Delete
  8. (sorry, not sure if my post got lost or is pending mod)

    Thanks very much for doing this, I have a nearly working Eclipse (Mars) system.

    I have a few things:


    1)
    I've had to make a changes in the C/C++ build settings -> tools settings -> [asm | c | c++] -> includes
    of the form:

    from: "${workspace_loc:/nrf51_sdk/components/drivers_nrf/hal}"
    to: "${workspace_loc}/nrf51_sdk/components/drivers_nrf/hal"

    I tried a few things like moving brf51_sdk and trying to create a project, but resorted to just modifying the include settings in the end.

    2)
    I can compile EHAL.a (and example) but the IDE editor still can't resolve some symbols.

    for example: NRF_GPIO or PIN_CNF on line 70 of iopincfg_nrf51.c:

    NRF_GPIO->PIN_CNF[PinNo] = cnf;

    even though it can include the nrf51.h header where they are defined.
    I've probably missed a config #define somewhere?


    on another topic: The pch file is only generated once at project creation, @QWERTY just 'touch' the missing file.

    ReplyDelete
    Replies
    1. Is there a missing ":" in the new include path you ? It should be "${workspace_loc:}/nrf51_sdk/components/drivers_nrf/hal". The NRF_GPIO should be defined in nrf51.h at line 1300. I think the missing semi-column that is causing the problem.

      Delete
  9. hi,

    it wouldn't work when using: "${workspace_loc:}/nrf51_sdk/components/drivers_nrf/hal"

    the library compiles ok, so the path set in the compiler settings seems ok, it's just the IDE doest like it. I'll try adding both.

    ReplyDelete
  10. they both resolve to the same location, but the IDE is still unhappy.

    -I"C:\nRF51822\EHAL\ARM\Nordic\nRF51/nrf51_sdk/components/drivers_nrf/hal" -I"C:\nRF51822\EHAL\ARM\Nordic\nRF51/nrf51_sdk/components/drivers_nrf/hal"

    ReplyDelete
  11. so apologies and for clarity these work:
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/hal"
    "${workspace_loc:}/nrf51_sdk/components/drivers_nrf/hal"

    it's just the default project path "${workspace_loc:/nrf51_sdk/components/drivers_nrf/hal}" doesn't work for compilation on Eclipse Mars for me on Windows.

    ReplyDelete
    Replies
    1. Yeah, that issue is Eclipse. Not only on Windows. I work on MAC same problem. When you add a new relative path, Eclipse generate with the '}' put at the end. That works fine until you import the project or change it. I had to edit and change all to move the '}' right after the ':'. I may have missed some.
      As for Eclipse not resolving all the defines. I got that too but I didn't bother with it as long as everything compiles. It's just a little annoying. Let me know if you find a cure to that. I think it got something to do with the parser.

      Delete
  12. thanks for getting back so quick. will take a look at the IDE issue.
    Your on a mac, that's awesome to know, I'm running this in a WinVM on a Mac. Have you ever used j-segger with Mac?

    ReplyDelete
    Replies
    1. Yes, all the time. You need the segger software version 4.94 or above. Since that version, they have resolved the CDC issue. I develop mainly using MAC and JLink. I one day I'll hope to use IDAP-Link as main tool when I resolve all the software issues.
      Look for RKNRFGO. It's the nRFGo for mac. I rarely need to go back to Windows. Using Windows heats up my system so I try to avoid that as much as I can.

      Delete
  13. Hi,
    Thanks for the guide. I had to change some entries for the include for me to work, though. It was a similar problem as mentioned above.
    I'm using Luna in windows 7.

    My include lines that worked:

    "${workspace_loc}/${ProjName}/src"
    "${workspace_loc}/EHAL/include"
    "${workspace_loc}/CMSIS/include"
    "${workspace_loc}/../../../include"
    "${workspace_loc}/../../CMSIS/include"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_services/ble_hids"
    "${workspace_loc}/nrf51_sdk/components/libraries/bootloader_dfu/experimental"
    "${workspace_loc}/nrf51_sdk/components/libraries/gpiote"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_debug_assert_handler"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/ble_flash"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_error_log"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/pstorage"
    "${workspace_loc}/nrf51_sdk/components/libraries/trace"
    "${workspace_loc}/nrf51_sdk/components/softdevice/common/softdevice_handler"
    "${workspace_loc}/nrf51_sdk/components/libraries/timer"
    "${workspace_loc}/nrf51_sdk/components/softdevice/s110/headers"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/nrf_soc_nosd"
    "${workspace_loc}/nrf51_sdk/components/libraries/bootloader_dfu"
    "${workspace_loc}/nrf51_sdk/components/libraries/util"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/hal"
    "${workspace_loc}/nrf51_sdk/components/libraries/scheduler"
    "${workspace_loc}/nrf51_sdk/components/ble/common"
    "${workspace_loc}/nrf51_sdk/components/ble/device_manager"
    "${workspace_loc}/nrf51_sdk/components/libraries/bootloader_dfu/ble_transport"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_services/ble_bas"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_services/ble_dfu"
    "${workspace_loc}/nrf51_sdk/components/ble/ble_services/ble_dis"

    and for the EHAL project:
    "${workspace_loc}/nrf51_sdk/components/softdevice/s110/headers"
    "${workspace_loc}/nrf51_sdk/components/libraries/util"
    "${workspace_loc}/nrf51_sdk/components/libraries/scheduler"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/nrf_soc_nosd"
    "${workspace_loc}/nrf51_sdk/components/drivers_nrf/hal"
    "${workspace_loc}/CMSIS/include"
    "${workspace_loc}/../../CMSIS/include"
    "${workspace_loc}/../../../include"
    "${workspace_loc}/${ProjName}/include"

    ReplyDelete
    Replies
    1. Thanks very much for the update. I updated the blog with your paths

      Delete
  14. hi,
    i use eclipse for blink LED on nrf kit . i successfully compile code and it generate hex file , but when i load that hex in kit it not work same code when i compile in keil and generate hex and load it work nice, so what is my fault i have made? i made Cross ARM GNU hello word project and edit that.
    if you have sample LED blink code in eclipse than please give me.
    Thank you

    ReplyDelete
    Replies
    1. Have you change the setting of the target processor to Cortex m0 ? By default it is set to the m3. There are a few require files that need to be added. The easiest is to import the Blinky project that I already created and modify it for your board.

      Delete
    2. yes i change m3 to m0 and added file also..with no error ... can you please give link i can't found example code in blog...
      Thnak You

      Delete
    3. The link is in the second paragraph the EHAL.

      Delete
    4. i found the example and using your example i build it and change only led pin number and compile. it generate hex file Debug folder not generate .elf and hex file in release folder other file .map and .mk and.o etc are generate...when i load hex file from debug folder LED not blink and yes i set device cortex-m0 and give linker file as you suggest in this blog... so is there any mistake that i have made.?

      Delete
    5. You said there is no .elf file ? Something is wrong then. Can you tell what files you have in your project. Can you import my blinky project into your workspace and compile.

      Delete
    6. Thank for Reply
      yes project.elf in release folder not generate .i have import your project and no other file....and can you please explain how i debug my code in eclipse?
      Thank you

      Delete
    7. When you compile, you can choose whether compile in debug mode or release mode. It is debug by default. To debug your program, select the menu 'Run/Debug Configuration...". A popup will show up. There 2 options on the left hand list 'OpenOCD' or 'JLink'. Create a new debug session with the one you are using as jtag. Default setting for Jlink works fine. OpenOCD require some setting based on your jtag device.

      Delete
  15. Hi,

    I tried out your UART example with the NRF51-DK (PCA10028) and the Android App (nrf toolbox). The sending from the Android App to the device works, but the other direction doesn't. Any idea what it could be? I double and triple checked the pin number assignment. I flashed the s110 softdevice. Thanks!

    ReplyDelete
    Replies
    1. Hi,
      My UART example is different from the Nordic. I send & receive on the same characteristic and use of app_uart instead of simple_uart. You can use modify the nRFToolbox to have it receive on the same charac. I don't have Android example code yet but you can use my iOS code that goes with it.

      Delete
  16. Hi,

    I have been trying to setup the work environment for the nRF51 DK on my mac, but no avail. I am hoping you can me finding the missing link to the setup. Thanks.

    Environment: Mac OS X 10.10 with eclipse IDE for C 4.4.2
    Steps that I did:
    1) I cloned the workspace from Github.
    2) Put CMSIS that downloaded from ARM under ARM folder
    3) Put the Nordic SDK under the nRF51 folder
    4) Import CMSIS and EHAL project into eclipse
    5) Lots of warnings saying "Invalid project path: Include path not found ...) Total of 11 warnings after imports

    Best,
    Steven

    ReplyDelete
    Replies
    1. You Are you able to compile ? Which version of the SDK are you using ? Can you list some of the path ?
      Eclipse 4.4 (Luna) is not recommended. You need to install 4.5 (Mars).

      Delete
    2. Thanks for the reply. I am not able to compile those two projects even though I installed eclipse Mars, and pulled the changes from your the git server today. I pasted the warning below.

      Description Resource Path Location Type
      Invalid project path: Include path not found (CMSIS/CMSIS/include). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (include). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/drivers_nrf/hal). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/drivers_nrf/nrf_soc_nosd). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/libraries/scheduler). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/libraries/util). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/softdevice/s110/headers). EHAL pathentry Path Entry Problem
      Invalid project path: Include path not found (CMSIS/CMSIS/include). CMSIS pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/device). CMSIS pathentry Path Entry Problem
      Invalid project path: Include path not found (nrf51_sdk/components/drivers_nrf/hal). CMSIS pathentry Path Entry Problem

      Delete
    3. These are the error I got when I compile, of course with those warning as well.
      Description Resource Path Location Type
      fatal error: nrf51.h: No such file or directory iopincfg_nrf51.c /EHAL/src line 36 C/C++ Problem
      Field 'PIN_CNF' could not be resolved iopincfg_nrf51.c /EHAL/src line 70 Semantic Error
      Symbol 'NRF_GPIO' could not be resolved iopincfg_nrf51.c /EHAL/src line 70 Semantic Error
      make: *** [src/iopincfg_nrf51.o] Error 1 EHAL C/C++ Problem

      Delete
    4. When you open Eclipse, where do you set the workspace to ? You need to use the nRF51 folder location a your workspace. All the include path are relative to the workspace being in that folder. If your workspace is at a different location, you need to readjust all the path according.

      Delete
    5. Yes. I realized something wired is that when I use absolute path everything works, and if I use the relative path. It seems eclipse don't recognize any path except for this "${workspace_loc:/${ProjName}/include}".

      Delete
    6. I think I found my problem. I solved it by adding ${workspace_loc} in font of some of the non-accessible paths in the Include directories under "Paths and Symbols" in "C/C++ General" in the Properties of the project.
      For example:
      Change /../../CMSIS/CMSIS/include to ${workspace_loc}/../../CMSIS/CMSIS/include

      Delete
    7. Sorry for spamming on the replies. Another thing I have to do is change all the Includes in Settings in C/C++ Build.
      For exmaple: "${workspace_loc:}/../../CMSIS/CMSIS/include" to "${workspace_loc}/../../CMSIS/CMSIS/include".
      Basically remove the colon in the workspace_loc

      Delete
    8. Thanks for the update. All most all of my path setting has that workspace_loc. Some how it seem have been removed when you do the import or I must have forgotten some. My Eclipse didn't complain about the ':'. In fact on the older Eclipse, the ':' was required. Look like Eclipse has some inconsistency from one system to the other. Few people reported that some of the path had to be absolute on their system. Atleast there is a solution that works for everyone :)

      Delete
  17. Hello Nguyen, I'm trying to build a prototype using nRF51822. Do you know any way to load the .hex file to NRF51822 chips? The only way I found was to buy a BeeProg2C programmer which is very expensive for me. I was thinking about a using a QFN48 TO DIP48 adapter+Waveshare BLE 400 board, but I don't know if it's really possible.
    Thanks for your help Nguyen.

    ReplyDelete
    Replies
    1. I just check the Waveshare board you talked about. They said the CP2102 is used for debugging. I seriously doubt that. The CP2102 is a UART to USB bridge. Has nothing to do with debug. I also see a SWD connector on that board. Which means you still need a JTAG, The nRF51 series require ARM SWD debugger does not support flashing through UART unless you already flash in a UART bootloader. The official debugger supported by Nordic is Segger. However you can use cheaper alternative such as the IDAP-Link (see the IDAP-Link page) which is a CMSIS-DAP debug jtag. You can use a QFN48 to DIP48 adapter and connect vcc, gnd, SWCLK and SWDIO pin to a debug jtag to program the chip. You need also connect the vcc to 3.3V supply. The IDAP-Link can provide the 3.3V power. I have not try connecting the chip that way yet. You may need to jump wire some other pins for power requirements of the chip. See the data sheet for more details.

      Delete
    2. Hello Nguyen, I have Waveshare BLE 400 board. I program it using a J-Link. So the idea is to use: Waveshare board + protoboard + QFN48 TO DIP48 adaptater + J-Link. Why do you think it wouldn't work ?

      Delete
    3. Are you the one who asked the question about Waveshare. If I am not mistaken the question was use the Waveshare to program the nRF51822 without a JTAG. There were no mention of using the JLink with it. If you read my answer fully, I did mention that a JTAG is required and that the official supported jtag by Nordic was Segger, hence JLink.

      Delete
  18. Hi, I just update to Migrating to SDK 8, but I am stuck at this point. Any idea ? Thanks

    20:05:59 **** Incremental Build of configuration Release for project EHAL ****
    make all
    make: *** No rule to make target `/Users/joanet/Development/Embedded/eclipseWS/EHAL-master/src/fatfs.cpp', needed by `src/fatfs.o'. Stop.

    ReplyDelete
    Replies
    1. You can remove that file from the EHAL project. It's the FAT filesystem I am implementing. It is not ready to commit yet. When you see an error like that, it means the source file is missing.

      Delete
  19. Hello

    i like to use EHAL for nrf51 but with a different WORKSPACE Path.

    In EHAL Eclipse Project there are some Files referenced by PROJECT_PATH but others are referenced by WORKSPACE_PATH.
    uart.h ---> WORKSPACE_LOC\..\..\..\include\uart.h
    usb_cdcdef.h --> PROJECT_LOC\..\..\..\..\include\usb_cdcdef.h

    Thanks,
    Lukas


    ReplyDelete
    Replies
    1. Hi,
      You can remove the usb_cdcdef.h. USB is not available on nRF51. The relative reference can be either one of your choice. I usually prefer WORKSPACE_LOC. I must have forgot to remove when I did a quick compile check. Often I do quick compile check when adding new stuff to other platform to make sure it doesn't break the compilation.

      Delete
  20. I cant compile the EHAL Project because HWND in usbhiddev.h is missing and some things in sdcard.c like SDDEV.
    Where can i find the missing header file?

    Thanks,
    Lukas

    ReplyDelete
    Replies
    1. sdcard.c was excluded from the build at the moment. You can remove it. It is replaced by C++ version sdcard_impl.cpp. I am phasing out support for the C version of high level library.

      Delete
  21. Any hints on how to get your UART_Example working with KEIL? I tried to add all missing .headers via the Package Installer (SDK8 installed). Because I've got an revision 1 based module I can't get to work :(

    ReplyDelete
    Replies
    1. There is an UART example project for Keil in the SDK under examples/ble_peripheral. You'll need to change Board definitions for your own. To change header path, you need to go into project settings of Keil.

      Delete
    2. Dear Bác,

      I am Nguyen Van Trung, come from Vietnam. I want to build a medical device. I want to use nRF51 to transmit data to computer and smartphone. How to transmit speed up to 2MB/s and interface USB?

      Thanks

      Delete
    3. The nRF5x is a Bluetooth LE chip. BLE cannot transmit at that rate. It can do about 250Kb/s. Send me a private message via Goole+ with some more details so I can understand what you need. Viết bằng tiếng việt cũng được.

      Delete
  22. Hi Nguyen,

    Thanks for your effort on the tutorial. Greatly appreciated.

    I had a few fun examples in Keil but I like to use Eclipse and GCC for being free. Now, it seems my Keil projects ported to Eclipse wont work, given me alot of weird errors, debugged, but when eventually compiled, it didnt work. :-(

    I am using Luna, Win7, SDK9.0 with bug fixes.

    I got lost much earlier than expected following through your tutorial.
    Importing the EHAL and CMSIS projects, I suppose to import 2 separate projects available in the workspace? is this expected? then if I am to use Blinky_ble, it will be the third?

    Project Explorer
    \
    |---CMSIS
    |---EHAL
    |---Blinky_ble

    Can you be able to share the screenshot of your project explorer tree of your Eclipse?please.

    I am Hardware Engineer by trade and relatively new to Eclipse, so I am not so familiar with jargons and work arounds.

    Thanks,
    Arthur

    ReplyDelete
    Replies
    1. Your imports look fine. Have you downloaded CMSIS library from ARM with the links I provided ? You should try Blinky first. Get it compile and download to the board using the debugger. Once you get that working, you can move up to Blnky_ble which will require Softdevice. Most of the errors are caused by wrong Path. Can you show me the errors ? I can't show the screenshot because my workspace have a lot of project. It will confuse you.

      Delete
    2. Thanks for the quick reply.
      I successfully built and tested the Blinky project.
      Now, stepping up to Blinky_ble, I had errors as below;
      .........pstorage.c:224:44: error: 'PSTORAGE_NUM_OF_PAGES' undeclared here (not in a function)

      In Keil, it is on "pstorage_platform.h", and the value is different depending on the project.
      The "pstorage_platform.h", in the EHAL "..../Blinky_ble/src" dont have the 'PSTORAGE_NUM_OF_PAGES' defined.

      So what I did add a line in pstorage.c, #define PSTORAGE_NUM_OF_PAGES 1.
      Now, I just randomly pick value of "1". How would I know?
      It did build successfully, and flashed the S110, and Application.

      Using nRF Master Control Panel, I did successfully connected, and the Pin 30 toggled to HI (always ON except disconnected).
      Now, should it suppose to blink? Should I send a value on a service?

      Thanks,
      Arthur

      Delete
    3. Replace the storage_platform.h from the Blinky_ble with the new file from the SDK9. The new is located in in the SDK9 under drivers_nrf/pstorage/config. Copy it over the Blinky_ble.

      Delete
    4. The GPIO 30 is used in to indicate connected state in the Blinky_ble project and most of my exemples code.

      Delete
    5. Thanks again.
      With Blinky_ble, my understanding in the gpiote_event_handler(), tries to read the GPIO level and pin location, then pass it to ble_blinkys_on_data_change(), but what is next after that?
      Then, what is the function of blinkys_write_handler()?

      Delete
    6. The ble_blinky_on_data_change() sends the data to the Central.
      The bliny_write_handler() is called when receiving data from the Central.
      See the accompanying iOS example code.

      Delete
    7. Thanks. Unfortunately I havent had iOS device. I used Android nRF Master control Panel.
      I tried to add IAS service and had no luck triggering to the on_ias_evt(). I'm not sure what I missed.

      Delete
    8. I haven't try Android yet. There are many Android applications on GooglePlay that allows you to scan for BLE device.

      Delete
  23. I am using nRF52 from nordic semiconductor. I have some problems popping up like:- make No rule to make target 'all'. Gcc not found and g++ not found. Eclipse and GCC is being used to run blinky program. I would be helpful If you could give me some suggestions on that.

    ReplyDelete
    Replies
    1. It looks like your Eclipse couldn't find the GCC compiler. Look in the Eclipse preference. There is a place where you can set the Path for the GCC compiler and toolset.

      Delete
  24. Now path is set. It overcome that problem. Now only left with the:- make No rule to make target 'all'. I am following this link too:-https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/ . Still Make error is there.

    ReplyDelete
    Replies
    1. Nordic uses makefies for their project. You should check the path in the makfile. I can try the nRF52 Blinky pure Eclipse project I posted here.

      Delete
  25. Nguyen,
    Thanks for posting this very enlightening article. I have been looking at the CC2541, but it requires a $3K development ide to just get started!
    Am I understanding you correctly that all the software that you used in your example was downloaded AT NO COST? If so, this is quite compelling, and may convince me to switch to the nRF51 device. Also, just to be clear, the IDAP-Link J-Tag probe and nRF51 module are the only hardware (besides a PC/mac) required?
    Thanks in advance.

    ReplyDelete
    Replies
    1. Hi,
      The SDK is provided by Nordic free of charge with full source code. But it's main support was Keil and J-Link. This blog is about alternative way to use free Eclipse & Gcc as environment to develop with nRF5x series. The IDAP-Link is a low cost alternative to the J-Link. The minimum requirements for development are the module, the breakout board and the J-Tag (IDAP-Link or J-Link).

      Delete
  26. Cám ơn bài hướng dẫn tuyệt vời của anh.

    Anh cho em hỏi. Em có thể dùng làm theo hướng dẫn của anh Flash cho board Nrf81822 này được không, Có cũng có các Pin SWD, SCLK ? Link board: http://world.taobao.com/item/523149247914.htm

    Cám ơn anh, Chúc anh sức khỏe

    ReplyDelete
    Replies
    1. Hello Mai,

      Em cần có một cái JTAG để flash. Dùng cái IDAP-Link để flash cũng được. Em xem trang IDAP-Link sẽ rõ hơn. Có thể mua nó ở semiconductorstore.com. Nếu cần hướng dẫn nhiều hơn thì mail cho anh biết.

      Delete
  27. Nguyen, thank you for the post!

    "The default startup code from the SDK does not work with C++. Use the one from EHAL. See example code for details."

    I couldn't find the c++ startup code. Where in EHAL can I find it? What steps do I need to take if I want to run c++ code on the nRF51?

    Thanks!

    ReplyDelete
    Replies
    1. Hi,

      The startup code is split in 2 section. The generic portion to all ARM cortex M is located in ARM/src. The file ResetEntry.c. It contains the reset initialization code. It is compiled in CMSIS library in each MCU. The specific protion per MCU is located in src of each. The file name starts with Vectors_xxx.c. It contains the interrupt vector mapping. This file is to be included in each executable project. You are also require the LD files for to use with the EHAL startup code

      Delete
    2. Thanks! For context: I am trying to compile the https://github.com/FastLED/FastLED cpp project with one of the nRF51 samples that are all written in c and have makefiles and startup code that is for c only.

      I'll try to work with the files you suggested

      Delete
    3. Were you successful in integrating the FastLED code?
      That would interest me...

      Delete
    4. I don't know about FastLED and haven't tried it.

      Delete
  28. Hi,
    Thank you for this wonderful tutorial. I was able to complete the setup and build your sample Blinky and UART BLE examples. However, these are all C projects and I could not find any C++ demo project in it. I tried creating a new C++ project but could not build it successfully. Could you please share any sample C++ project with BLE soft device enabled? Thanks so much

    ReplyDelete
    Replies
    1. Have you read my blog post about changes you need to do in the SDK code? The LMXDeisplayDemo is an Eclipse C++ project. It does not use BLE but you can easily add it.

      Delete
    2. Thank you directing me to this CPP project. However, I hit the below error when I build the project

      arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -T C:\NordicProject\ARM\Nordic\nRF51\src\gcc_nrf51_blank_xxaa.ld -Xlinker --gc-sections -L"C:\NordicProject\ARM\Nordic\nRF51\CMSIS\Release" -L"C:\NordicProject\ARM\Nordic\nRF51\CMSIS\Debug" -Wl,-Map,"LMXDisplayDemo.map" --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group -o "LMXDisplayDemo.elf" ./src/LMXDisplayDemo.o ./src/Vectors_nRF51.o -lEHAL
      c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: cannot find -lEHAL
      collect2.exe: error: ld returned 1 exit status
      make: *** [LMXDisplayDemo.elf] Error 1

      I have changed for all includes and linker directories from relative project path to absolute project path. Could you please help me resolve this error. Thanks

      Delete
    3. You need to compile the EHAL library.

      Delete
    4. Thank you so much. It worked! However, do you add C++ wrapper to all the nordic SDK files to get in compiled. Is there a quick workaround for this?

      Delete
    5. Wrap all Nordic include files within extern "C" { #include ... }

      Delete
  29. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  30. Hi Hoang,
    I'm having issues getting things working in Eclipse. I have downloaded the CMSIS and EHAL as well as the Nordic SDK v.11. But I don't know where to begin as far as getting an example project working. I have the IDAP-link for programming the module, and two nrf51422 modules that I have soldered to the breakout board.

    I would like to implement a program to detect the proximity of two connected IMM-NRF51422 modules to each other. One module will be connected to a vibration motor, and if the two get too far apart, it will turn the motor on. I saw an example Proximity program in the BLE examples in the sdk under the BLE peripheral folder. I plan on starting there once I am able to figure out how to use Eclipse.

    For now, I could use your help with understanding how to start with the basics of how to get a simple program set up in eclipse and programmed onto the board. I hope you see this soon, I'm under a bit of a time crunch.

    Thanks, Taylor

    ReplyDelete
    Replies
    1. I have updated some of the examples to the new SDK11. You can import them to try.

      Delete
  31. What is a good low cost ARM SWD programmer to use with these? Will Nucleo board from ST work as a SWD programmer -- one of those is coming in the mail already.

    Thanks,

    John in Texas

    ReplyDelete
    Replies
    1. You can use the IDAP-Link. See the IDAP-Link page. It is a full CMSIS-DAP Debug J-Tag. Compatible with all major IDE such as KEIL, CrossWorks, IAR, Eclipse & OpenOCD, etc... The ST may work too. Some people use it but I haven't tried it myself.

      Delete
  32. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  33. Hi!

    Can you comment about the tools paths when using SDK11? Thanks for the awesome post

    ReplyDelete
    Replies
    1. The location of the SDK11 is shown in the folder tree at the top of this blog page. Some of the examples (Blinky, Bliky_ble,...) have been ipdated to SDK11. You'll find all the path in the project settings.

      Delete
    2. Sorry, I wasn't clear enough.

      I was talking about the include paths for SDK11. You have already mention this for SDK6 And SDK8. i wonder if those are the same for SDK11. Thanks again

      For SDK 6 :

      "${ProjDirPath}/src"
      "${ProjDirPath}/../../EHAL/include"
      "${ProjDirPath}/../../CMSIS/include"
      "${ProjDirPath}/../../../../../include"
      "${ProjDirPath}/../../../../CMSIS/CMSIS/include"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/sdk"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble/device_manager"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble/ble_services"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/sd_common"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/ble"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/s110"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/app_common"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include/gcc"
      "${ProjDirPath}/../../nrf51_sdk/nrf51822/Include"

      For SDK 8, the way the folders are organized is the worst.

      "${ProjDirPath}/src"
      "${ProjDirPath}/../../EHAL/include"
      "${ProjDirPath}/../../CMSIS/include"
      "${ProjDirPath}/../../../../../include"
      "${ProjDirPath}/../../../../CMSIS/CMSIS/include"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_hids"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu/experimental"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/gpiote"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_debug_assert_handler"
      "${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/ble_flash"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_error_log"
      "${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/pstorage"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/trace"
      "${ProjDirPath}/../../nrf51_sdk/components/softdevice/common/softdevice_handler"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/timer"
      "${ProjDirPath}/../../nrf51_sdk/components/softdevice/s110/headers"
      "${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/nrf_soc_nosd"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/util"
      "${ProjDirPath}/../../nrf51_sdk/components/drivers_nrf/hal"
      "${ProjDirPath}/../../nrf51_sdk/components/device"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/scheduler"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/common"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/device_manager"
      "${ProjDirPath}/../../nrf51_sdk/components/libraries/bootloader_dfu/ble_transport"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_bas"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_dfu"
      "${ProjDirPath}/../../nrf51_sdk/components/ble/ble_services/ble_dis"



      There are a few to set in the linker settings as well. First thing is the linker script.

      for BLE project

      "${ProjDirPath}/../../src/gcc_nrf51_s110_xxaa.ld"

      Non BLE project

      "${ProjDirPath}/../../src/gcc_nrf51_blank_xxaa.ld"

      Delete
    3. One more time, THANK YOU. I'll try to set up all .

      Delete
    4. One more time, THANK YOU. I'll try to set up all .

      Delete
  34. How can I buy the IMM-NRF52832?.
    Is there any example to send like 10 or 100KB of data with at baud rate of 115200 or 9600 over BLE between two nrf52 dk (central and peripheral)? because the example in Nordic "ble_app_uart_c" when I program the one as central and the other as peripheral, I just get 260 bites received.

    ReplyDelete
    Replies
    1. Unfortunately Central mode is very slow. Only optimization you can do is to reduce the connection interval. Use only notification to send 20 bytes at time. Long write is very slow. You can never achieve 100KB for sure.

      Delete
  35. thanks for the answer!! is there any documentation of the practical maximum data rate and the acceptable amount of data that can be sent over BLE in Nordic nrf52 dk (is it using a GATT BLE profile ? ) ?

    ReplyDelete
    Replies
    1. All docs are avail on Nordic Devzone and on bluetooth.org

      Delete
  36. Hi Nguyen Hoan Hoang

    Thanks for pointing out your site to me.

    I am interersted in doing some BLE Beacon type work with IOS Apps.

    Any guidance you can give would be appreciated.

    Iain

    ReplyDelete
    Replies
    1. You'll need to get a hardware kit. You buy the IMM-NRF5x module showed in this blog along with a breakout board and the IDAP-Link (see IDAP-Link page) or the Nordic DK. Then download Nordic SDK and follow my guide on this page to setup your eclipse development environment. There are example code here to get you going with Eclipse and iOS. The Nordic SDK has a lot more example code which also include a Beacon example. There are quite some learning you need to go through.

      Delete
  37. We want to use the IMM-NRF52832, the question is when we are currently using the nrf52 dk development board we program is with keil micro vision / J-tag (via USB).
    When the size is then so small like in the future with the IMM-NRF52832, how can we program it (are there pins to connect)?.

    ReplyDelete
    Replies
    1. The SWD and all I/O pins are routed out on the edge of the module.

      Delete
  38. thanks a lot Nguyen Hoan Hoang :) !! when is the IMM-NRF52832 available for ordering ?

    ReplyDelete
    Replies
    1. It is being produced. We'll have some available in about a week or so.

      Delete
  39. great !! please keep us updated when and how to order as soon as they're available

    ReplyDelete
    Replies
    1. I received the IMM-NRF52832 from production.

      Delete
    2. Great !! can you send the link to order the IMM-NRF52832 ?

      Delete
    3. Now available on Tindie https://www.tindie.com/stores/hnhoan/

      Delete
  40. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  41. hi,
    i am working on Eclipse IDE for ble_hrs example from the nRF_SDK.
    i have created work space on desktop and created one source file.
    in which i placed all files which i have needed from nRF_SDK. and include all the file paths(bcoz getting errors like .h file not found) by c/c++ Build->paths and symbols.
    then it worked fine all files are building (with out including main.c of example ble_hrs).
    but while calling functions(which are present in nRF_SDK source files) from my main.cpp like SOFTDEVICE_HANDLER_INIT(CLK_SRC, NULL) and time_init i am getting bugs which i am unable to solve.
    please help me to solve this.
    and how to initialise softdevice (priority of calling softdevice functions ormacros).

    ReplyDelete
    Replies
    1. Have you tried to encapsulate the __cplusplus, extern thing I told you about ?

      Delete
    2. hi, thank you its working fine. but while calling softdevice_enable() i am getting. undefined reference to `__data_start__' y i am getting these errors continuously.

      Delete
    3. i mean how the code can recognise symbols present in the linkerScript. and memory restriction like this.
      MEMORY
      {
      FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000
      RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x6000
      }

      Delete
    4. You are missing main linker script.

      Delete
  42. hi i am using nRF51 development kit. i have gone through your blog build was successful it is creating release folder in which i am getting .elf file. but if i want to flash to file by using debug configuration option i am getting fallowing message.

    Error in services launch sequence Launching command [/JLinkGDBServerCL.exe -if jtag -device nRF51822_xxAA -endian little -speed 1000 -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0 -nogui] failed. Launching command [/JLinkGDBServerCL.exe -if jtag -device nRF51822_xxAA -endian little -speed 1000 -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0 -nogui] failed. Cannot run program "/JLinkGDBServerCL.exe": Launching failed

    please help me from this..

    ReplyDelete
    Replies
    1. Is the path to your JLinkGDBServerCL.exe good ? Check the path make sure that you have installed Segger driver software

      Delete
    2. Target halted (DBGRQ, PC = 0xFFFFFFFE)
      Reading all registers
      Read 4 bytes @ address 0xFFFFFFFE (Data = 0x049182A0)
      Read 2 bytes @ address 0xFFFFFFFE (Data = 0x0000)
      Read 4 bytes @ address 0xFFFFFFF4 (Data = 0x00000000)
      Read 4 bytes @ address 0xFFFFFFF0 (Data = 0x00000000)
      Read 4 bytes @ address 0x00000000 (Data = 0xFFFFFFFF)
      Read 4 bytes @ address 0xFFFFFFF4 (Data = 0x00000000)
      Read 4 bytes @ address 0xFFFFFFF4 (Data = 0x00000000)
      Read 4 bytes @ address 0xFFFFFFFF (Data = 0x00FFFFFF)


      unable to flash code to nrf51

      Delete
    3. Are you using softdevice ? if you do, then first you need to flash the softdevice in using nrfjprog from Nordic. There are instructions on the devzone. You need only do this once. Second make sure you use the right linker script for the softdevice version you are using s110 or s120 or s130.

      Delete
    4. i am using s130 .ld file is

      MEMORY { FLASH (rx) : ORIGIN = 0x00020000, LENGTH = 0x20000
      RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x6000 }

      all ready added soft device to nrf51 kit using nRFGO studio. but unable to flash blinky through eclipse. getting some register information and stopping procedure.

      Delete
    5. your memory map is wrong. For S130 of SDK11.

      FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
      RAM (rwx) : ORIGIN = 0x20002100, LENGTH = 0x5F00

      Delete
    6. even i updated the .ld file no progress getting same issue.

      Delete
    7. Which blink example are you using ? You may have bad firmware

      Delete
  43. hi,
    i have created new project(in eclipse IDE) like blinky in which i added main.c from (sdk blinky example) and added required files from nrf SDK10 (added s130 nrf51_xxaa.ld as linker script). and compiled it (which is creating debug folder in my project including .elf and .hex files) i am trying to flash generated .elf file using eclipse IDE on PC10028. using run configuration. (is my procedure is ok).

    ReplyDelete
    Replies
    1. here the my project source tree https://www.dropbox.com/sh/01jssfvr7c5rlhp/AAAPEOsJGnsw2YmzJ6XVLKpBa?dl=0

      Delete
    2. SDK10 memory map is different. The one I gave you was for SDK11.
      SDK10 I believe FLASH should be 0x1c000. Check the HRS example to be sure. You will also need to re-flash the softdevice. It might be corrupted be previous flashing off your app at wrong location.

      Delete
  44. hi,
    i am working on accelerometer adxl335 with nrf51 development kit. i want to get readings of accelerometer by connecting to nrf51 development kit. the code is available in this link https://github.com/NordicSemiconductor/nrf51-ADC-examples.(ble_app_uart_adc_simple).

    i am connecting x out put of adxl335 to p0.01(analog input of nrf51 kit). so i am getting strange values on uart(in windows termite). which is increasing by one every time even i am changing the direction of the accelerometer. please help me from this.

    ReplyDelete
    Replies
    1. I think by default the example is sample the internal vcc. You need to configure the adc to sample from external pin.

      Delete
  45. Hi Nguyen,

    Thanks for this great tutorial. I was slightly confused in the beginning with the tree structure and getting the EHAL and CMSIS projects compiled without errors, but going through the comments helped and I got it right.

    I have two problems though.

    1. I don't know why I have the two projects, CMSIS and EHAL?
    2. I have the DK for nRF52 with PCA10040 and I can't seem to get your blinky program working. It compiles and debugs without errors and I start it in debug perspective, but not getting any leds to blink. Any advice?

    Thanks again for great write up.

    ReplyDelete
    Replies
    1. The default pin map is for the blueio breakout board. To use with the Nordic DK, you need to change the pin defines to match it.

      Delete
  46. Hi,

    I have set up the Eclipse and GCC according to Nordic blog, and using the nRF_SDK_12.2.0_ble_app_hrs_pca10040.zip as the project file. It compiles, loads and debugs as expected with the nRF52DK. When I switch to Segger Jlink and IMM-NRF52832, it programs without problem, and almost work. I use the iOS app from Nordic, I can see the device boardcast, get connected, but no Heartrate received. I also enabled the serial log, it works fine as well. I also used the prebuilt hex file, ble_app_hrs_pca10040_s132.hex, same behaviour. BLE discovered, connected, but no data. Can you think of anything?

    ReplyDelete
    Replies
    1. Hi,

      I don't know for sure but I think it needs the buttons on the DK. What happen if you modify the code to use the button on the IBK-BLUEIO breakout board ? Or wire up a button to the same pin as on the DK.

      Delete
  47. Hi,

    do you have an estimate when IDAP-Link will be again in stock at Tindie?

    I apologise if this is not the right place to ask this question, please direct me if this is the case.

    BR,
    Borut

    ReplyDelete
    Replies
    1. If you are not in a hurry, the new batch would come in about 4-6 weeks. If you are in a hurry then contact me via email.

      Thanks,
      Hoan

      Delete