Close

nRF51822 development on the Mac

Erland LewinErland Lewin wrote 03/11/2016 at 14:28 • 3 min read • Like

March 11, 2016

It took a full day, but I now believe I have the the latest version (10) of Nordic's SDK working on my Mac.

I mainly followed instructions here. Do read that page also, it has some tips, like running gdb, that I won't cover here.

Some of the difficulties came from the fact that there are different versions of the ARM toolchain, SDK, SoftDevice and IC:s.

I'm now using SDK 10 downloaded from here.

I'm using the latest ARM toolchain, version 5.2.1, downloaded from here. Unpacked in /usr/local

My IC is an nRF51822QFAAH0 (this is printed on the IC). H0 means it is a revision three chip. You might be interested in Nordic's Compatibility Matrix.

I also installed the latest drivers from Segger for my J-Link programmer I originally got with a development kit from Nordic.

In the SDK, I modified components/toolchain/gcc/Makefile.posix to be:

GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-5_2-2015q4

GNU_VERSION := 5.1.2

GNU_PREFIX := arm-none-eabi

I did my testing with the HRS (Heart Rate Service) example code.

Do:

cd examples/ble_peripheral/ble_app_hrs/pca10028/s110/armgcc

The problem here was all examples are preconfigured for the nRF51422 chip, whereas I have the 51822.

Copy the right linker script to this directory (I had a lot of grief before I figured this one out), in my case:

cp <sdk root>/components/softdevice/s110/toolchain/armgcc/armgcc_s110_nrf51822_xxaa.ld .

I then added the nrf51822_xxaa as a target in the Makefile. Around line 168 of the makefile, I duplicated the lines for the nrf51422_xxac_s110 target, renamed them to nrf51822_xxaa_s110, changed the output filename and linker script thusly:

OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)

nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110

nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld

nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)

@echo Linking target: $(OUTPUT_FILENAME).out

        $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out

        $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize

nrf51822_xxaa_s110: OUTPUT_FILENAME := nrf51822_xxaa_s110

nrf51822_xxaa_s110: LINKER_SCRIPT= armgcc_s110_nrf51822_xxaa.ld

nrf51822_xxaa_s110: $(BUILD_DIRECTORIES) $(OBJECTS)

@echo Linking target: $(OUTPUT_FILENAME).out

        $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out

        $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize

I could then build the code with:

$ make nrf51822_xxaa_s110
To program the chip, use JLinkExe to erase the flash (the magic w4 commands they have turned out to be neccessary when changing softDevice), flash the SoftDevice and the application, then reset the device. Once you have the SoftDevice in place, you only need to flash the application.

$ JLinkExe -device nrf51822_xxaa -if swd -speed 4000
SEGGER J-Link Commander V5.10s (Compiled Mar  9 2016 18:54:51)

DLL version V5.10s, compiled Mar  9 2016 18:54:45

Connecting to J-Link via USB...O.K.

Firmware: J-Link Lite-Cortex-M V8 compiled Aug 20 2015 17:57:19

Hardware version: V8.00

S/N: 518002428

License(s): GDB

Emulator has Trace capability

VTref = 3.287V

Type "connect" to establish a target connection, '?' for help

J-Link>connect

Device "NRF51822_XXAA" selected.

Found SWD-DP with ID 0x0BB11477

Found Cortex-M0 r0p0, Little endian.

FPUnit: 4 code (BP) slots and 0 literal slots

CoreSight components:

ROMTbl 0 @ F0000000

ROMTbl 0 [0]: F00FF000, CID: B105100D, PID: 000BB471 ROM Table

ROMTbl 1 @ E00FF000

ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS

ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT

ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB

ROMTbl 0 [1]: 00002000, CID: B105900D, PID: 000BB9A3 ???

Cortex-M0 identified.

J-Link>w4 4001e504 2

Writing 00000002 -> 4001E504

J-Link>w4 4001e50c 1

Writing 00000001 -> 4001E50C

J-Link>loadbin ../../../../../../components/softdevice/s110/hex/s110_nrf51_8.0.0_softdevice.hex 0

Downloading file [../../../../../../components/softdevice/s110/hex/s110_nrf51_8.0.0_softdevice.hex]...Comparing flash   [100%] Done.

Erasing flash     [100%] Done.

Programming flash [100%] Done.

Verifying flash   [100%] Done.

J-Link: Flash download: Flash programming performed for 2 ranges (91136 bytes)

J-Link: Flash download: Total time needed: 1.313s (Prepare: 0.085s, Compare: 0.030s, Erase: 0.000s, Program: 1.180s, Verify: 0.008s, Restore: 0.008s)

O.K.

J-Link>loadbin _build/nrf51822_xxaa_s110.hex 0x16000

Downloading file [_build/nrf51822_xxaa_s110.hex]...Comparing flash   [100%] Done.

Erasing flash     [100%] Done.

Programming flash [100%] Done.

Verifying flash   [100%] Done.

J-Link: Flash download: Flash programming performed for 1 range (28672 bytes)

J-Link: Flash download: Total time needed: 0.584s (Prepare: 0.116s, Compare: 0.010s, Erase: 0.000s, Program: 0.408s, Verify: 0.002s, Restore: 0.046s)

O.K.

J-Link>r

Reset delay: 0 ms

Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.

J-Link>g

J-Link>exit

After this, the application runs, an LED flashes on my board, and I can see the HRS using the nRF MCP app on my iPhone.

I have not done any more testing yet.

Like

Discussions