Can't jlink upload to nrf52 unless I erase the nrf52. Why and what to do?

My development environment consists of an nrf52832 board, Segger Mini Edu Jlink and platformio/zephyr framework and everything worked just well.

Recently I enabled continuous ADC/DMA sampling with dual buffering and now I am getting an error when I try to upload a new program (see log below). To recover I erase the nrf52 with jFlashLite and then I can upload again. If I erase the nrf52 and then upload a program with DMA disabled, I can upload many times with no problem.

Any suggestion what to do? For example, can I tell the jlink uploader to erase the nrf52 before it uploads? Or, can I disable the RAM verification since the upload is just to the Flash anyway?

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = zephyr
debug_tool = jlink
monitor_speed = 230400
debug_build_flags = -O0 -g -ggdb
platform_packages = 
   framework-zephyr@~2.20701.220216

Upload log:

> Executing task: C:\Users\user\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing nrf52_dk (platform: nordicnrf52; board: nrf52_dk; framework: zephyr)
----------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nrf52_dk.html
PLATFORM: Nordic nRF52 (9.3.0) > Nordic nRF52-DK
HARDWARE: NRF52832 64MHz, 64KB RAM, 512KB Flash
DEBUG: Current (jlink) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES:
 - framework-zephyr 2.20701.220216 (2.7.1)
 - tool-bossac-nordicnrf52 1.10901.201022 (1.9.1)
 - tool-cmake 3.21.3
 - tool-dtc 1.4.7
 - tool-jlink 1.75001.0 (7.50.1)
 - tool-ninja 1.9.0
 - tool-openocd 2.1100.211028 (11.0)
 - tool-sreccat 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi 1.80201.190214 (8.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\nrf52_dk\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   9.6% (used 6304 bytes from 65536 bytes)
Flash: [          ]   3.2% (used 16892 bytes from 524288 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, nrfjprog, stlink
CURRENT: upload_protocol = jlink
Uploading .pio\build\nrf52_dk\firmware.hex
SEGGER J-Link Commander V7.50a (Compiled Jul  8 2021 18:18:11)
DLL version V7.50a, compiled Jul  8 2021 18:16:52


J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link EDU Mini V1 compiled Nov  2 2021 11:12:01
Hardware version: V1.00
S/N: 801041412
License(s): FlashBP, GDB
VTref=3.299V
Target connection not established yet but required for command.
Device "NRF52832_XXAA" selected.


Connecting to target via SWD
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
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
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
PC = 00000D5E, CycleCnt = 009E670B
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000020
R4 = 2000036C, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= 20001050, MSP= 20001880, PSP= 20001050, R14(LR) = 00002A27
XPSR = 61000000: APSR = nZCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 02000001, CONTROL = 02, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 01

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

Downloading file [.pio\build\nrf52_dk\firmware.hex]...

****** Error: Failed to prepare RAMCode using RAM
Unspecified error -1

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.


Script processing completed.

===================================================== [SUCCESS] Took 6.12 seconds =====================================================

Terminal will be reused by tasks, press any key to close it.

… BTW, when I try to erase with the platformio erase function I get this error and as far as I can tell the JLinkARM DLL does exist:

~/.platformio/packages/tool-jlink$ ls -l JLinkARM.dll
-rwxr-xr-x 1 user 197121 17842976 Jul  8  2021 JLinkARM.dll

Erase command log:

> Executing task: C:\Users\user\.platformio\penv\Scripts\platformio.exe run --target erase --environment nrf52_dk <

Processing nrf52_dk (platform: nordicnrf52; board: nrf52_dk; framework: zephyr)
----------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nrf52_dk.html
PLATFORM: Nordic nRF52 (9.3.0) > Nordic nRF52-DK
HARDWARE: NRF52832 64MHz, 64KB RAM, 512KB Flash
DEBUG: Current (jlink) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES:
 - framework-zephyr 2.20701.220216 (2.7.1)
 - tool-cmake 3.21.3
 - tool-dtc 1.4.7
 - tool-ninja 1.9.0
 - tool-nrfjprog 1.90702.0 (9.7.2)
 - tool-sreccat 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi 1.80201.190214 (8.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Erasing...
ERROR: JLinkARM DLL not found. Please reinstall latest JLinkARM.
*** [erase] Error 30
====================================================== [FAILED] Took 3.00 seconds ======================================================The terminal process "C:\Users\user\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'erase', '--environment', 'nrf52_dk'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

If pio run -t erase fails like this, please open an issue in Issues · platformio/platform-nordicnrf52 · GitHub

Same for this, hope the devs know more.

Thanks @maxgerhardt. I submitted a bug for the Erase Flash error. Once this will be resolved I will try to do auto erase on upload and go from there.

Installing the Segger’s JLink software on Windows seems to make this to work. It still seems like a bug since the platformio jlink documentation says that all files will be provided by platformio.

1 Like