diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index deecf65ec..dd0230100 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -4,6 +4,7 @@ #include "HardwareRNG.h" #include "PowerFSM.h" #include "configuration.h" +#include "error.h" #include "main.h" #include "mesh/PhoneAPI.h" #include "mesh/mesh-pb-constants.h" @@ -275,7 +276,16 @@ void NRF52Bluetooth::setup() LOG_INFO("Init the Bluefruit nRF52 module"); Bluefruit.autoConnLed(false); Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.begin(); + if (!Bluefruit.begin()) { + // sd_ble_enable() rejected our RAM base: the linker RAM ORIGIN + // (src/platform/nrf52/nrf52840_s140_v*.ld) is below what the SoftDevice needs for the + // current Bluefruit config. Without this check the node would silently run without BLE. + // Rebuild with -DCFG_DEBUG=1 to get "SoftDevice's RAM requires: 0x..." in the log, then + // raise the ORIGIN accordingly. + LOG_ERROR("Bluefruit.begin failed - SoftDevice RAM reservation too small for this config"); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_UNSPECIFIED); + return; + } // Clear existing data. Bluefruit.Advertising.stop(); Bluefruit.Advertising.clearData(); diff --git a/src/platform/nrf52/nrf52840_s140_v6.ld b/src/platform/nrf52/nrf52840_s140_v6.ld index c8dac4e55..a956c6583 100644 --- a/src/platform/nrf52/nrf52840_s140_v6.ld +++ b/src/platform/nrf52/nrf52840_s140_v6.ld @@ -21,8 +21,17 @@ MEMORY * - Max ATT MTU * - Concurrent connection peripheral + central + secure links * - Event Len, HVN queue, Write CMD queue + * + * With our fixed Bluefruit config (1 peripheral link, BANDWIDTH_MAX / MTU 247, + * 0x1000 attr table) sd_ble_enable() reports a requirement well below the old + * 0x20006000 ORIGIN; every byte of gap is unusable RAM. 0x20004000 keeps a + * ~2+ KB margin over the reported base. NRF52Bluetooth::setup() now checks + * Bluefruit.begin() and records a critical error if the SoftDevice ever + * rejects this base (e.g. after an SD/Bluefruit config change) - re-measure + * with CFG_DEBUG=1 (Bluefruit logs "SoftDevice's RAM requires: 0x...") + * before raising bandwidth/MTU/link settings. */ - RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x20040000 - 0x20006000 + RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000 } SECTIONS diff --git a/src/platform/nrf52/nrf52840_s140_v7.ld b/src/platform/nrf52/nrf52840_s140_v7.ld index 4546b4a7a..dbaf7dfb7 100644 --- a/src/platform/nrf52/nrf52840_s140_v7.ld +++ b/src/platform/nrf52/nrf52840_s140_v7.ld @@ -18,8 +18,17 @@ MEMORY * - Max ATT MTU * - Concurrent connection peripheral + central + secure links * - Event Len, HVN queue, Write CMD queue - */ - RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x20040000 - 0x20006000 + * + * With our fixed Bluefruit config (1 peripheral link, BANDWIDTH_MAX / MTU 247, + * 0x1000 attr table) sd_ble_enable() reports a requirement well below the old + * 0x20006000 ORIGIN; every byte of gap is unusable RAM. 0x20004000 keeps a + * ~2+ KB margin over the reported base. NRF52Bluetooth::setup() now checks + * Bluefruit.begin() and records a critical error if the SoftDevice ever + * rejects this base (e.g. after an SD/Bluefruit config change) - re-measure + * with CFG_DEBUG=1 (Bluefruit logs "SoftDevice's RAM requires: 0x...") + * before raising bandwidth/MTU/link settings. + */ + RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000 } SECTIONS