Stack overflow caused by BLE.connect

Hi all,

I was attempting to use my Boron to connect to an nRF52840 board using Bluetooth LE. The nRF board is running the Secure bootloader with the DFU service, enabling firmware flashing over Bluetooth.

The issue I'm encountering is that my Boron starts blinking red as soon as the connection initiates, blinking 13 times, indicating a stack overflow. This consistently happens, regardless of how much I simplify my code.

Here is my source code for the Boron (running on device OS 5.6.0):

Source code
static uint8_t dfuAddress[6] = {0x05, 0x8F, 0x54, 0xD2, 0x8B, 0xEE};

static volatile bool connectNeeded;
static BleAddress connectAddress;

static BlePeerDevice peer;


SerialLogHandler logHandler(LOG_LEVEL_ALL);

static void scanResultCallback(const BleScanResult* scanResult, void* context) {
    uint8_t address[BLE_SIG_ADDR_LEN];
    if (memcmp(dfuAddress, address, 6) != 0) {
    connectNeeded = true;
    connectAddress = scanResult->address();

void setup() {

void loop() {
    connectNeeded = false;"Starting scan");
    BLE.scan(scanResultCallback, NULL);"Scan ended");
    if (connectNeeded) {"Connecting");
        peer = BLE.connect(connectAddress);
        if (peer.connected()) {

And here are the logs I've obtained:

0000002290 [app] INFO: Scan ended
0000002291 [app] INFO: Starting scan
0000002844 [app] INFO: Scan ended
0000002845 [app] INFO: Connecting
0000002960 [wiring.ble] TRACE: New peripheral is connected.
0000002961 [wiring.ble] TRACE: Start discovering services.
0000003187 [wiring.ble] TRACE: Disconnected
0000003187 [app] INFO: Starting scan
0000005309 [app] INFO: Scan ended
0000005309 [app] INFO: Starting scan
0000008426 [app] INFO: Scan ended
0000008426 [app] INFO: Starting scan
0000010448 [app] INFO: Scan ended
0000010448 [app] INFO: Starting scan
0000010682 [app] INFO: Scan ended
0000010682 [app] INFO: Connecting
0000010715 [wiring.ble] TRACE: New peripheral is connected.
0000010715 [wiring.ble] TRACE: Start discovering services.
0000010762 [wiring.ble] TRACE: Start discovering characteristics of service: 1800.
0000011121 [wiring.ble] TRACE: Characteristic discovered.
0000011122 [wiring.ble] TRACE: Start discovering characteristics of service: 1801.
0000011181 [wiring.ble] TRACE: Characteristic discovered.
0000011182 [wiring.ble] TRACE: Start discovering characteristics of service: FE59.
0000011524 [hal

Unfortunately, I don't have access to the last line starting with "hal" because the Boron doesn't print logs while blinking red. I managed to get it once, and it's truncated.

Is there anything I'm doing wrong here? What would be a good way to investigate this stack overflow further?

Thanks for your help.