Issues with hackaBLE and Bumpy

Greetings!

I’m trying to use PlatformIO with Electronut’s hackaBLE + Bumpy combo. I’m trying to upload a minimal code:

#include <Arduino.h>

#include <SPI.h>
#include <BLEPeripheral.h>

void setup() {
  Serial.begin(9600);

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(PIN_LEDG, OUTPUT);
  pinMode(PIN_LEDR, OUTPUT);

}

void loop() {
  digitalWrite(PIN_LEDR, HIGH);
  Serial.println(F("RED LED on"));
  delay(1000);

  digitalWrite(PIN_LEDR, LOW);
  Serial.println(F("RED LED off"));
  delay(1000);
}

Here is mine platformio.ini:

[env:hackaBLE]
platform = nordicnrf52
board = hackaBLE
framework = arduino

lib_deps = BLEPeripheral

; SoftDevice version
build_flags = -DNRF52_S132

upload_protocol = blackmagic
upload_port = /dev/ttyACM0

debug_tool = blackmagic
debug_port = /dev/ttyACM0

It builds successfully, with only bothering issue being those warnings:

...
Linking .pio/build/hackaBLE/firmware.elf

{...}arm-none-eabi/bin/ld: warning: changing start of section .heap by 4 bytes
{...}arm-none-eabi/bin/ld: warning: changing start of section .stack_dummy by 4 bytes

{...}arm-none-eabi/bin/ld: warning: changing start of section .heap by 4 bytes
{...}arm-none-eabi/bin/ld: warning: changing start of section .stack_dummy by 4 bytes

{...}arm-none-eabi/bin/ld: warning: changing start of section .heap by 4 bytes
{...}arm-none-eabi/bin/ld: warning: changing start of section .stack_dummy by 4 bytes

Building .pio/build/hackaBLE/userfirmware.hex

{...}arm-none-eabi/bin/ld: warning: changing start of section .heap by 4 bytes
{...}arm-none-eabi/bin/ld: warning: changing start of section .stack_dummy by 4 bytes

{...}arm-none-eabi/bin/ld: warning: changing start of section .heap by 4 bytes
{...}arm-none-eabi/bin/ld: warning: changing start of section .stack_dummy by 4 bytes
...

But when I try to debug code, I get a segfault:

Reading symbols from /media/data/projects/BLE/BlinkyAdvert/.pio/build/hackaBLE/firmware.elf... done.

PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = blackmagic
PlatformIO: Initializing remote target...

Target voltage: unknown
Available Targets:
No. Att Driver
1 Nordic nRF52
2 Nordic nRF52 Access Port

0x0000bbbe in ?? ()

Temporary breakpoint 1 at 0x1cc86: file /home/superprower/.platformio/packages/framework-arduinonordicnrf5/cores/nRF5/main.cpp, line 29.

Loading section .text, size 0xfe4 lma 0x1c000
Loading section .ARM.exidx, size 0x8 lma 0x1cfe4
Loading section .data, size 0x70 lma 0x1cfec

Start address 0x1c598, load size 4188
Transfer rate: 24 KB/sec, 598 bytes/write.

Warning: the current language does not match this frame.

PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug

Note: automatically using hardware breakpoints for read-only addresses.

Program received signal SIGSEGV, Segmentation fault.
0x00020b90 in ?? ()

Please share any ideas on how to fix this issues. If any additional information is required, I’ll provide more. Thanks in advance.

I have a suspicion that this is related to the SoftDevice. I tried flashing example from the nrf52 SDK, and I got the same segfault address. Debugging a bit showed me that this occurs during BLE Stack (SoftDevice) initialization.

After I merged .hex file produced by ‘make’ command with SoftDevice .hex file from SDK, and flashed it, example started working. Maybe I need to write some kind of custom build command?

On the other hand, once I run load for merged .hex file, I could also load just make-produced .hex file (example code only) and it seems to work fine. Maybe I need to point platformIO to my softdevice hex, since it uses malformed or incompatible one?

Softdevice definition seems to be in

and then handled in

Which softdevice are you using?

Thanks for reply.

I’m already using build_flags = -DNRF52_S132 in my platformio.ini - hackaBLE is based on nrf52832, which is s132 SoftDevice. SoftDevice that worked for me is from nRF52 SDK v15.3, s132_nrf52_6.1.1_softdevice.hex.

Does platformio produce code that isn’t yet merged with SoftDevice (or however it does that?), so I could try to merge it myself and upload it manually?

If it is a corrupted softdevice file, can you navigate to the path indicated by the code

So <home dir>/.platformio/packages/framework-arduinonrf52/cores/nRF5/SDK/components/softdevice/<softdevice>/hex/<hexfile> and then replace the hex file.

I tried putting in newer version of SoftDevice, but got the same issue as this guy:

It’s also seems like a relatively new issue? But also something is already in the package as a result of it. I tried changing URL to development version (platform = https://github.com/platformio/platform-nordicnrf52.git) in platformio.ini, but to no avail - I still get a segfault, although at a different address:

received signal SIGSEGV, Segmentation fault.
0x0001d27c in ?? ()

I also thought it may be a conflict between softdevices. So I went to gdb and ran

(gdb) target extended-remote /dev/ttyACM0
Remote debugging using /dev/ttyACM0
(gdb) monitor erase_mass
Target does not support this command.
(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.
0x0002b4a8 in ?? ()
(gdb) monitor erase_mass
erase..
(gdb) kill
Kill the program being debugged? (y or n) y
[Inferior 1 (Remote target) killed]
(gdb) run
Starting program:
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()

Which makes sense, I guess. But after I tried to upload code from platformio…
I still got a segfault at 0x00. So maybe issue is with flashing, somehow? What really bothered me is that gdb command for uploading is
arm-none-eabi-gdb -nx --batch -ex "target extended-remote /dev/ttyACM0" -ex "monitor swdp_scan" -ex "attach 1" -ex load -ex compare-sections -ex kill /media/data/projects/BLE/BlinkyAdvert/.pio/build/hackaBLE/firmware.elf

I’m not sure how gdb processes this command line, but will this empy load command work? I’m not sure. At this point I’m honestly just saying ideas.

Hi
Can you verify if the Platformio.io is not merging the Softdevice ?
; PlatformIO Project Configuration File

;

; Build options: build flags, source filter

; Upload options: custom upload port, speed and extra flags

; Library options: dependencies, extra library storages

; Advanced options: extra scripting

;

; Please visit documentation for the other options and examples

; Redirecting...

[env:adafruit_feather_nrf52832]

platform = nordicnrf52

board = adafruit_feather_nrf52832

framework = arduino

debug_tool = jlink

;nrfutil

upload_protocol = jlink

; SoftDevice version

build_flags = -DNRF52_S132

; change MCU frequency

board_build.f_cpu = 64000000L

I had to include it using a out the box software.