nRF52840DK Upload Erases Bootloader

Hi there

I purchased an nRF52840dk to aid in debugging my device. I am using Arduino with the Bluefruit BLE library. PIO Core 6.1.14, VSCode on Windows.

When I use PlatformIO to upload, it erases the device and uploads the application but not the Bootloader. If I Burn the bootloader first then select Upload, same thing. If I Burn the bootloader then try Debug with upload, same thing.

I have checked the memory map layout via the nrf programmer app to confirm that the bootloader is missing.

Any suggestions?

Platform.ini

[env]
framework = arduino
; platform = https://github.com/maxgerhardt/platform-nordicnrf52
platform = nordicnrf52
monitor_speed = 115200 

lib_deps =
  # RECOMMENDED
  # Accept new functionality in a backwards compatible manner and patches
  # adafruit/Adafruit nRFCrypto
  bblanchon/ArduinoJson

[env:nrf52840_dk_adafruit]
board = nrf52840_dk_adafruit
upload_protocol = jlink
;change microcontroller
board_build.mcu = nrf52840
; change MCU frequency
board_build.f_cpu = 64000000L
; board_build.upload.offset_address = 0x00027000

; SoftDevice version
build_flags = -D NRF52_S140
build_type = debug
debug_tool = jlink
debug_build_flags =  -O1 -g3

No errors in the upload process


Processing nrf52840_dk_adafruit (board: nrf52840_dk_adafruit; framework: arduino; platform: nordicnrf52)
---------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nrf52840_dk_adafruit.html
PLATFORM: Nordic nRF52 (10.1.0+sha.cac6fcf) > Nordic nRF52840-DK (Adafruit BSP)
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) On-board (jlink) External (blackmagic, cmsis-dap, stlink)
PACKAGES:
 - framework-arduinoadafruitnrf52 @ 1.10500.0 (1.5.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-adafruit-nrfutil @ 1.503.0 (5.3)
 - tool-bossac-nordicnrf52 @ 1.10901.201022 (1.9.1)
 - tool-jlink @ 1.78811.0 (7.88.11)
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-sreccat @ 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 14 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoJson @ 7.0.4
|-- Adafruit Bluefruit nRF52 Libraries
Building in debug mode
Checking size .pio\build\nrf52840_dk_adafruit\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.0% (used 17532 bytes from 248832 bytes)
Flash: [==        ]  17.0% (used 138368 bytes from 815104 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, nrfjprog, stlink
CURRENT: upload_protocol = jlink
Uploading .pio\build\nrf52840_dk_adafruit\firmware_signature.bin
SEGGER J-Link Commander V7.88k (Compiled Jul  5 2023 15:02:18)
DLL version V7.88k, compiled Jul  5 2023 15:00:41


J-Link Command File read successfully.
Processing script file...
J-Link>h
J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-nRF5340-NordicSemi compiled Oct 30 2023 12:13:06
Hardware version: V1.00
J-Link uptime (since boot): 6d 00h 25m 05s
S/N: 1050210305
License(s): RDI, FlashBP, FlashDL, JFlash, GDB
USB speed mode: Full speed (12 MBit/s)
VTref=3.300V
Target connection not established yet but required for command.
Device "NRF52840_XXAA" selected.


Connecting to target via SWD
InitTarget() start
InitTarget() end - Took 7.40ms
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
CoreSight SoC-400 or earlier
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x02880000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
[0][0]: E000E000 CID B105E00D PID 000BB00C SCS-M7
[0][1]: E0001000 CID B105E00D PID 003BB002 DWT
[0][2]: E0002000 CID B105E00D PID 002BB003 FPB
[0][3]: E0000000 CID B105E00D PID 003BB001 ITM
[0][4]: E0040000 CID B105900D PID 000BB9A1 TPIU
[0][5]: E0041000 CID B105900D PID 000BB925 ETM
Memory zones:
  Zone: "Default" Description: Default access mode
Cortex-M4 identified.
PC = FFFFFFFE, CycleCnt = 001A620F
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= FFFFFFD8, MSP= FFFFFFD8, PSP= 00000000, R14(LR) = FFFFFFF9
XPSR = 01000003: APSR = nzcvq, EPSR = 01000000, IPSR = 003 (HardFault)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00

FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
FPSCR= 00000000
J-Link>loadbin .pio\build\nrf52840_dk_adafruit\firmware.bin,0x26000
'loadbin': Performing implicit reset & halt of MCU.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
Downloading file [.pio\build\nrf52840_dk_adafruit\firmware.bin]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (139264 bytes)
J-Link: Flash download: Total: 1.694s (Prepare: 0.091s, Compare: 0.014s, Erase: 0.000s, Program & Verify: 1.517s, Restore: 0.070s)
J-Link: Flash download: Program & Verify speed: 89 KB/s
O.K.
J-Link>loadbin .pio\build\nrf52840_dk_adafruit\firmware_signature.bin,0xFF000
'loadbin': Performing implicit reset & halt of MCU.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
Downloading file [.pio\build\nrf52840_dk_adafruit\firmware_signature.bin]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (4096 bytes)
J-Link: Flash download: Total: 0.079s (Prepare: 0.042s, Compare: 0.002s, Erase: 0.000s, Program & Verify: 0.010s, Restore: 0.023s)
J-Link: Flash download: Program & Verify speed: 399 KB/s
O.K.
J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
J-Link>q

Script processing completed.

============================================ [SUCCESS] Took 9.13 seconds ============================================

Some progress here.

deleting the PIO directory now allows me to Burn the bootloaded and run debug upload.

But if I try a normal upload, or click debug again it still uploads the application without the bootloader.