diff --git a/variants/nrf52840/diy/moonshine_NRF52/platformio.ini b/variants/nrf52840/diy/moonshine_NRF52/platformio.ini index 713a14574..119ffb8f5 100644 --- a/variants/nrf52840/diy/moonshine_NRF52/platformio.ini +++ b/variants/nrf52840/diy/moonshine_NRF52/platformio.ini @@ -2,8 +2,15 @@ [env:moonshine_NRF52_node] extends = nrf52840_base board = adafruit_feather_nrf52840 +board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld build_flags = ${nrf52840_base.build_flags} -I variants/nrf52840/diy/moonshine_NRF52 -D PRIVATE_HW + -D USE_SEGGER + -D MESHTASTIC_EXCLUDE_I2C=1 + -D MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -D MESHTASTIC_EXCLUDE_INPUTBROKER=1 + -D MESHTASTIC_EXCLUDE_ACCELEROMETER=1 + -D MESHTASTIC_EXCLUDE_MAGNETOMETER=1 build_src_filter = ${nrf52_base.build_src_filter} +<../variants/nrf52840/diy/moonshine_NRF52> debug_tool = jlink diff --git a/variants/nrf52840/diy/moonshine_NRF52/readme.md b/variants/nrf52840/diy/moonshine_NRF52/readme.md index 09b344813..d97e6dd9e 100644 --- a/variants/nrf52840/diy/moonshine_NRF52/readme.md +++ b/variants/nrf52840/diy/moonshine_NRF52/readme.md @@ -5,7 +5,9 @@ DIY Meshtastic node variant based on the RF-BM-ND05 nRF52840 module. ## Hardware - **MCU module**: RF-BM-ND05 (nRF52840, 512 KB flash / 128 KB RAM) -- **LF clock**: 32.768 kHz crystal (`USE_LFXO`) +- **LF clock**: internal RC (`USE_LFRC`) - RF-BM-ND05 has no 32.768 kHz crystal; using + `USE_LFXO` without a crystal makes SoftDevice hang in `RTC1_IRQHandler` waiting + for LFCLK, causing LED-stuck-on and silent BLE failure. - **LoRa**: multi-module compatible (SX1262 / SX1268 / RF95 / LLCC68 / LR1121 / LR2021) with TCXO - **GPS**: u-blox (no EN pin) - **Battery ADC**: 0.5 voltage divider (equal resistors) @@ -51,4 +53,57 @@ pio run -e moonshine_NRF52_node ``` Uses `PRIVATE_HW` (HardwareModel 255) - no protobuf or `architecture.h` changes -required. Flash via SWD (`debug_tool = jlink`). +required. + +The build links against `nrf52840_s140_v7.ld`, so the application is linked to +start at `0x27000` and requires the S140 SoftDevice v7.x to be present on the +chip at `0x0`-`0x26FFF`. The build output (`firmware-*.hex` / `.uf2`) contains +**only the application**, not the SoftDevice. + +## Flash (first time on a bare RF-BM-ND05) + +A factory-fresh RF-BM-ND05 module has **no SoftDevice and no bootloader**. The +SoftDevice must be flashed once via SWD before the application; otherwise +`Bluefruit.begin()` fails, `sd_flash_*` calls (LittleFS, NodeDB, config +persistence) return errors, and the node appears dead. + +The S140 v7.3.0 SoftDevice hex is shipped in this repo at +`bin/s140_nrf52_7.3.0_softdevice.hex`. Flash via SWD with OpenOCD (CMSIS-DAP / +J-Link / ST-Link). The `nrf52_recover` command does a chip-wide ERASEALL through +the nRF52 CTRL-AP and clears APPROTECT, so it is the recommended first step on a +fresh module (ebyte/Raytac modules ship with APPROTECT engaged). + +```sh +# Single-command flow: recover (erase all + unlock) -> SoftDevice -> app -> reset +C:/openocd/bin/openocd.exe -s C:/openocd/share/openocd/scripts \ + -f interface/cmsis-dap.cfg -f target/nrf52.cfg \ + -c "init; nrf52_recover; \ + program bin/s140_nrf52_7.3.0_softdevice.hex verify; \ + program .pio/build/moonshine_NRF52_node/firmware-moonshine_NRF52_node-*.hex verify; \ + reset run; exit" +``` + +If the chip is already unlocked and you only need to re-flash the application +(SoftDevice already present), skip `nrf52_recover` and the SoftDevice line: + +```sh +C:/openocd/bin/openocd.exe -s C:/openocd/share/openocd/scripts \ + -f interface/cmsis-dap.cfg -f target/nrf52.cfg \ + -c "init; \ + program .pio/build/moonshine_NRF52_node/firmware-moonshine_NRF52_node-*.hex verify; \ + reset run; exit" +``` + +Notes: +- The firmware hex filename contains a commit hash (e.g. `2.8.0.421838f`); use + the actual file produced by `pio run` or a shell glob. +- The SoftDevice hex occupies `0x0`-`0x26498` (~156 KB) and does **not** write + UICR, so `nrf52_recover` is safe (UICR resets to defaults). +- Swap `interface/cmsis-dap.cfg` for `interface/jlink.cfg` or + `interface/stlink.cfg` if using a different SWD probe. + +No UF2 bootloader is installed in this flow, so subsequent updates must go +through BLE DFU (secure DFU service) or SWD again. To enable UF2 drag-and-drop +updates, flash an Adafruit nRF52 UF2 bootloader +(https://github.com/adafruit/Adafruit_nRF52_Bootloader) at `0x0` in place of the +bare SoftDevice - the bootloader bundles its own SoftDevice. diff --git a/variants/nrf52840/diy/moonshine_NRF52/variant.h b/variants/nrf52840/diy/moonshine_NRF52/variant.h index a81d2ba23..1abb2f7b3 100644 --- a/variants/nrf52840/diy/moonshine_NRF52/variant.h +++ b/variants/nrf52840/diy/moonshine_NRF52/variant.h @@ -4,7 +4,8 @@ /** Master clock frequency */ #define VARIANT_MCK (64000000ul) -#define USE_LFXO // Board uses 32khz crystal for LF +// #define USE_LFXO // Board uses 32khz crystal for LF +#define USE_LFRC // RF-BM-ND05 has no LFXO crystal - use internal RC /*---------------------------------------------------------------------------- * Headers