Adafruit nRF52840 BLE probes using Black Magic Probe debugger

Asen Lekov
5 min readJun 17, 2020

--

Not so long time ago, a couple of friends and I made a prototype project with device for access control management using Adafruit Feather Express with nRF52480 BLE SoC. Previously I had some experience in writing native Android and iOS app for similar nRF52 chips but now we needed to get our hands dirty a little bit more.

Our initial prototype using Adafruit was great — we used Arduino IDE and their support for Adafruit Feather to compile and load our first program. We used slightly modified example app and initially we used nRF Connect by Nordic Android and iOS apps to evaluate our idea.

And…

We decided to try making our own project using the Nordic SDK and leverage the nRF52840 features. So we were beginners. After the research we got to a few key points:

  1. Nordic SDK is Makefile based
  2. We need some debugger for sure
  3. There’s no general way to setup working environment without using the default stack (Segger Studio, JLink, etc.)

Point 1 and 3 are somehow linked because as an Android/Java developer I’m IntelliJ focused and CLion was a good candidate for an IDE for developing. Sure but CLion uses CMake builds and is not a great friend with a Makefile based projects such as Nordic nRF5 SDK.

I found a good article about it https://blog.jetbrains.com/clion/2020/01/using-nrf52-with-clion/ or this one from the same guys https://www.nrbtech.io/blog/2020/1/4/using-clion-for-nordic-nrf52-project which should be good topic for next article once we update our setup.

Because we ordered Black Magic Probe instead of using J-LINK for debugging and we are beginners we preferred to go baby steps and get it initially done straight forward.

Getting started

I compiled some Homebrew prerequisites to prepare my MacBook for Nordic nRF52 development:

brew cask install homebrew/cask-drivers/nordic-nrf-command-line-tools
brew cask install homebrew/cask-drivers/nordic-nrf-connect
brew cask install segger-jlink
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc

For Black Magic Probe we also needed:

brew install dfu-util

Takeaway I — Update your probe

I had many issues working with the probe and the Adafruit, but after updating the probe the things began to happen.

Follow the instructions here: https://github.com/blacksphere/blackmagic/wiki/Upgrading-Firmware

Make sure you have latest version of the probe firmware.

Takeaway II — Dry run before setup your project

First download nRF52 SDK v16 and SoftDevice s140 Adafruit Feather Express uses PCA10056 board.

Unzip and go to:

examples/ble_peripheral/ble_app_uart/pca10056/s140/armgcc

Make:

$ make
make: /usr/local/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc: Command not found
Cannot find: '/usr/local/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc'.
Please set values in: "/Users/lekov/Desktop/nRF52/nRF5SDK160098a08e2 2/components/toolchain/gcc/Makefile.posix"
according to the actual configuration of your system.

../../../../../../components/toolchain/gcc/Makefile.common:129: *** Cannot continue. Stop.

We have a hint here! We need to update the toolchain configuration to match ours:

$ which arm-none-eabi-gcc
/usr/local/bin/arm-none-eabi-gcc
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Open and edit the Makefile.posix file and it should look like this:

GNU_INSTALL_ROOT ?= /usr/local/bin/
GNU_VERSION ?= 9.2.1
GNU_PREFIX ?= arm-none-eabi

Make again:

$ make
mkdir _build
cd _build && mkdir nrf52840_xxaa
Assembling file: gcc_startup_nrf52840.S
Compiling file: nrf_log_backend_rtt.c
Compiling file: nrf_log_backend_serial.c
Compiling file: nrf_log_default_backends.c
Compiling file: nrf_log_frontend.c
Compiling file: nrf_log_str_formatter.c
Compiling file: app_button.c
Compiling file: app_error.c
Compiling file: app_error_handler_gcc.c
Compiling file: app_error_weak.c
Compiling file: app_fifo.c
Compiling file: app_scheduler.c
Compiling file: app_timer2.c
Compiling file: app_uart_fifo.c
Compiling file: app_util_platform.c
Compiling file: drv_rtc.c
Compiling file: hardfault_implementation.c
Compiling file: nrf_assert.c
Compiling file: nrf_atfifo.c
Compiling file: nrf_atflags.c
Compiling file: nrf_atomic.c
Compiling file: nrf_balloc.c
Compiling file: nrf_fprintf.c
Compiling file: nrf_fprintf_format.c
Compiling file: nrf_memobj.c
Compiling file: nrf_pwr_mgmt.c
Compiling file: nrf_ringbuf.c
Compiling file: nrf_section_iter.c
Compiling file: nrf_sortlist.c
Compiling file: nrf_strerror.c
Compiling file: retarget.c
Compiling file: system_nrf52840.c
Compiling file: boards.c
Compiling file: nrf_drv_clock.c
Compiling file: nrf_drv_uart.c
Compiling file: nrfx_atomic.c
Compiling file: nrfx_clock.c
Compiling file: nrfx_gpiote.c
Compiling file: nrfx_prs.c
Compiling file: nrfx_uart.c
Compiling file: nrfx_uarte.c
Compiling file: bsp.c
Compiling file: bsp_btn_ble.c
Compiling file: main.c
Compiling file: SEGGER_RTT.c
Compiling file: SEGGER_RTT_Syscalls_GCC.c
Compiling file: SEGGER_RTT_printf.c
Compiling file: ble_advdata.c
Compiling file: ble_advertising.c
Compiling file: ble_conn_params.c
Compiling file: ble_conn_state.c
Compiling file: ble_link_ctx_manager.c
Compiling file: ble_srv_common.c
Compiling file: nrf_ble_gatt.c
Compiling file: nrf_ble_qwr.c
Compiling file: utf.c
Compiling file: ble_nus.c
Compiling file: nrf_sdh.c
Compiling file: nrf_sdh_ble.c
Compiling file: nrf_sdh_soc.c
Linking target: _build/nrf52840_xxaa.out
text data bss dec hex filename
38428 192 4988 43608 aa58 _build/nrf52840_xxaa.out
Preparing: _build/nrf52840_xxaa.hex
Preparing: _build/nrf52840_xxaa.bin
DONE nrf52840_xxaa

Cool! This means we have configured our SDK and we can build on our machine!

Test the probe with example app

Connect the devices to your computer:

$ arm-none-eabi-gdb
GNU gdb (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 8.3.0.20190709-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)

You must check the device serial interface, in my case:

$ ls /dev | grep 'modem'
/dev/cu.usbmodem79A67BCB1
/dev/cu.usbmodem79A67BCB3

Into the GDB:

(gdb) target extended-remote /dev/cu.usbmodem79A67BCB1
Remote debugging using /dev/cu.usbmodem79A67BCB1
(gdb) monitor swdp_scan
Target voltage: 3.3V
Available Targets:
No. Att Driver
1 Nordic nRF52 M3/M4
2 Nordic nRF52 Access Port
(gdb) attach 1
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x00002ff8 in ?? ()
(gdb) load ../nRF5SDK160098a08e2/examples/../_build/nrf52840_xxaa.out
Loading section .text, size 0x9510 lma 0x27000
Loading section .sdh_soc_observers, size 0x8 lma 0x30510
Loading section .sdh_ble_observers, size 0x40 lma 0x30518
Loading section .sdh_state_observers, size 0x8 lma 0x30558
Loading section .sdh_stack_observers, size 0x10 lma 0x30560
Loading section .nrf_balloc, size 0x14 lma 0x30570
Loading section .log_const_data, size 0x80 lma 0x30584
Loading section .log_backends, size 0x10 lma 0x30604
Loading section .ARM.exidx, size 0x8 lma 0x30614
Loading section .data, size 0xc0 lma 0x3061c
Start address 0x272b4, load size 38620
Transfer rate: 26 KB/sec, 788 bytes/write.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program:
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.

Now you should see your bluetooth device using nRF Connect app on your phone! Congrats! 🥳

--

--

Asen Lekov
Asen Lekov

Written by Asen Lekov

Experienced native mobile and web developer. Interested in management and education with a solid experience behind.

No responses yet