Thursday, 6 July 2017

nrf51 - dk with arm gcc and ubuntu

Recently i bought the nrf51-dk. it consist of nrf51422 SoC which is similar to nrf51822SoC without ANT protocol. nrf51822 is the BLE4.2 SoC. i am trying my luck with beacons.



nrf51822 is mbed enabled i.e  we can program it using mBed online compiler and nordic also provides support for following development options.

 1. Keil uVision - most of nordic official document comes with Keil example's.
 2. IAR 
 3. ARM GCC 

In this post i will cover arm gcc setup using nordic command line tools  on linux (ubuntu) to compile and flash the given examples.

watch the video of total procedure here




1.Download the required softwares from Nordic  here (look under Downloads)
          a. nRF5-SDK
          b. nRF5X-Command-Line-Tools
2. GNU ARM Embedded tool chain from  here

3. Segger JLink Software from here

 install the segger jlink software using command

sudo dpkg -i segerJlinkFile.deb

it will be installed under /opt/segger

 sdk,command line tools and gnu arm tools chain comes as .tar packages. untar them and place them in directory.

go to your arm gcc tool chain folder

 cd <ARM_GCC_FOLDER>
ls

you can find following folders

arm-none-eabi  bin  lib  share

 add the bin folder to the path

PATH=$PATH:<ARM_GCC_TOOLCHAIN>/bin



go to your SDK Folder and cd into the

cd <SDK_PATH>/components/toolchain/gcc

and change the Makefile.posix  to the following 

GNU_INSTALL_ROOT :=<ARM_GCC_FOLDER>
GNU_VERSION := 4.9.3
GNU_PREFIX := arm-none-eabi


then go to the blinky example

cd  <nRF5_SDK>/examples/peripheral/blinky
ls

 blinky.eww  hex  main.c  pca10028  pca10031  pca10040  pca10056

main.c consist of the instructions pca100xx consist of make file and link files for different versions of dk boards. i am having the pca10028.

cd pca10028
ls

blank  s130

s130 is the softdevice implementation. softdevice is the precompiled hex files which consist functions of ble and ant api's.

we are not using soft device

cd blank
ls


arm4  arm5_no_packs  armgcc  config  iar


these are different implementation options. we are using armgcc

cd armgcc
ls

blinky_gcc_nrf51.ld  Makefile
we use make file to compile the main.c and generate .hex file. use command make to do that.

make

  you will get following on terminal

 mkdir _build
Compiling file: nrf_log_backend_serial.c
Compiling file: nrf_log_frontend.c
Compiling file: app_error.c
Compiling file: app_error_weak.c
Compiling file: app_timer.c
Compiling file: app_util_platform.c
Compiling file: hardfault_implementation.c
Compiling file: nrf_assert.c
Compiling file: sdk_errors.c
Compiling file: boards.c
Compiling file: nrf_drv_clock.c
Compiling file: nrf_drv_common.c
Compiling file: nrf_drv_uart.c
Compiling file: nrf_nvic.c
Compiling file: nrf_soc.c
Compiling file: main.c
Compiling file: RTT_Syscalls_GCC.c
Compiling file: SEGGER_RTT.c
Compiling file: SEGGER_RTT_printf.c
Assembling file: gcc_startup_nrf51.S
Compiling file: system_nrf51.c
Linking target: _build/nrf51422_xxac.out

   text       data        bss        dec        hex    filename
   3120        112        112       3344        d10    _build/nrf51422_xxac.out

Preparing: _build/nrf51422_xxac.hex

Preparing: _build/nrf51422_xxac.bin
 

_build/nrf51422_xxac.hex file will flashed to the board. to flash the board nrfcommand line tools are used. go to the command line tools directory

cd  <NRF_COMMAND_LINE_TOOLS>
ls
 nrfjprog mergehex

add the nrfjprog to the path

PATH=$PATH:<NRFJPROG_DIRECTORY> 

and use the following command to flash the device

nrfjprog --family nrf51 --program _build/nrf51422_xxac.hex

after flashing you need to reset the board. use the following command to reset board

 

nrfjprog --family nrf51 -r

makr some changes in the main.c file and you can reflash the dk. 

to erase the pre flashed code  we command

nrfjprog --family nrf51 -e

clean the build and build again

make clean
make 

then flash and reset again

 nrfjprog --family nrf51 --program _build/nrf51422_xxac.hex


nrfjprog --family nrf51 -r