Tuesday, November 26, 2019

Building Bluetooth Mesh example for nRF52840 Dongle on a Mac

Continuing my story of getting started developing for the nRF52840 on my Mac.

I'm trying to follow instructions here, but they don't cover the Mac specifically, just Linux and Windows and say "The steps should be similar for other platforms". Disappointing.

First attempt at generating build files with cmake used (in the newly manually created build directory under the mesh SDK):

cmake -DTOOLCHAIN=gccarmemb -DPLATFORM=nrf52840_xxAA -DSDK_ROOT= ..

It worked, but generated files for the 10056 board instead of the 10059 board which is the dongle. Unfortunately there doesn't seem to be a board file for the 10059 board in the mesh SDK directory CMake/board

I copied the pca10056.board file there to pca10059.board, replacing the strings 10056 to 10059 in it. I also edited the nrf52840 section of the CMake/Board.cmake file to be:

elseif (PLATFORM STREQUAL "nrf52840_xxAA")
    set(BOARD "pca10056" CACHE STRING "Board to build examples for.")
    set_property(CACHE BOARD PROPERTY STRINGS "pca10056" "pca10059")

and then reran cmake thus (in the newly created build directory):

cmake -DTOOLCHAIN=gccarmemb -DPLATFORM=nrf52840_xxAA -DSDK_ROOT=/SDK16 -DBOARD=pca10059 ..

Looks good. It says it's using SDK15 even though I gave it the path to SDK16, but I'll try it this way.

I then run make in the build directory.

I get errors related to LED_START and LED_STOP.  Seems board related.

See my posting on the Nordic forum about this with a fix.

I got further in the compilation, now got an issue about missing symbols.
I added the path to nrfjprog and mergehex to my path, and reran cmake. Note that you need to add the subdirectories for nrfjprog and mergehex separately.

I still get a warning during build:

warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: librtt_nrf52840_xxAA.a the table of contents is empty (no object file members in the library define global symbols)

and then later errors starting with:
/usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/beaconing_nrf52840_xxAA_s140_6.1.1.dir/__/__/mesh/prov/src/prov_utils.c.obj: in function `prov_utils_keys_generate':/<...>/mesh_3.2.0/mesh/prov/src/prov_utils.c:230: undefined reference to `uECC_secp256r1'
and later also complaining about missing
/<...>/mesh_3.2.0/mesh/core/src/log.c:63: undefined reference to `SEGGER_RTT_printf'
I believe I need to link with $(SDK_ROOT)/external/nrf_cc310_bl/lib/cortex-m4/hard-float/libnrf_cc310_bl_0.9.12.a
(found this out from examples/crypto/nrf_cc310_bl/pca10056/blank/armgcc/Makefile)

The mesh SDK also built build/external/micro-ecc/libuECC_nrf52840_xxAA.a
...and it's on the build line. Don't know why it isn't working. Ask Nordic?

The trick was to surround the linked archives for uECC and RTT with 
-Wl,--whole-archive and -Wl,--no-whole-archive

Friday, November 22, 2019

Nordic SDK16, nrRF52840 Dongle and gcc on a Mac

I just got some nRF52840 dongles that I ordered (for about €9 each).

This is a log of my first step of building and programming the 'Blinky' app to it on a Mac, using gcc rather than the Segger Embedded Studio.

I downloaded Nordic's latest nRF5 SDK (version 16) from here.

Downloaded the latest gcc toolchain from ARM from ARM.

Uncompressed the archive.

Copied resulting directory to /usr/local:

cp -a gcc-arm-none-eabi-9-2019-q4-major /usr/local
In the SDK (SDK16) directory, under components/toolchain/gcc: Backed up Makefile.posix, edited it to read:
GNU_INSTALL_ROOT ?= /usr/local/gcc-arm-none-eabi-9-2019-q4-major/bin/GNU_VERSION ?= 9.2.1GNU_PREFIX ?= arm-none-eabi
Go to the SDK, directory examples/peripheral/blinky/pca10059/mbr/armgcc

The makefile is already adapted to the board, so we don't need to follow the instructions here regarding setting flash start etc.

Run make. It worked! To upload the files to the board:
  • Start the nRF for Desktop app, 
  • Start the programming mode within it, 
  • select the device in the drop down, 
  • drag the .hex file from the _build directory that make generated to the nRF Connect app
  • Click 'write'
I think it works! 

The on board LED changes color red / green / white blue-green / blue / black. 

Next step: get a Bluetooth Mesh example app running.