nrf5340 keeping flash sectors between flash burns

Hello!

In our application the last two sectors of the APP core flash are used to store non-volatile config information (from 0xFE000, 2x4kB). I've created the appropriate partitioning for Zephyr, can access the partitions from FW, no problem. However, these settings must be persistent, but the flash burn operation with nrfjprog destroys these areas too... naturally, "erase all" is executed.

My first idea was to dump the contents with nrfjprog, and then write it back after the FW has been burnt. Dumping is okay, but nrfjprog is unable to write many bytes, just one word, useless.

My second idea was to:

  • save the important sectors by JLinkExe to a file;
    si 1
    speed 4000
    device NRF5340_XXAA_APP
    savebin NVRAM, 0xFE000, 0x2000
    exit
  • let nrfjprog erase and reprogram the flash;
    	nrfjprog \
    		--jdll /opt/JLink_Linux/libjlinkarm.so \
    		-f NRF53 \
    		--coprocessor CP_APPLICATION \
    		--clockspeed 4000 \
    		--program FW.hex \
    		--chiperase \
    		--verify \
    		--reset >/dev/null
  • load the important sectors by JLinkExe from the file;
    si 1
    speed 4000
    device NRF5340_XXAA_APP
    loadbin NVRAM, 0xFE000
    exit

Almost success... the last step, when JLinkExe wants to write the two affected sector, fails:

SEGGER J-Link Commander V7.66a (Compiled May 19 2022 15:18:10)
DLL version V7.66a, compiled May 19 2022 15:17:54


J-Link Command File read successfully.
Processing script file...
J-Link>si 1
J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link V9 compiled May  7 2021 16:26:12
Hardware version: V9.40
S/N: 269400451
License(s): FlashBP, GDB
OEM: SEGGER-EDU
VTref=3.359V
Selecting SWD as current target interface.
J-Link>speed 4000
Selecting 4000 kHz as target interface speed
J-Link>device NRF5340_XXAA_APP
J-Link>loadbin ./build/wlttp-v1r2-ncs-obj/nvram.bin, 0xFE000
Target connection not established yet but required for command.
Device "NRF5340_XXAA_APP" selected.


Connecting to target via SWD
ConfigTargetSettings() start
ConfigTargetSettings() end
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x6BA02477
DPIDR: 0x6BA02477
CoreSight SoC-400 or earlier
AP map detection skipped. Manually configured AP map found.
AP[0]: AHB-AP (IDR: Not set)
AP[1]: AHB-AP (IDR: Not set)
AP[2]: MEM-AP (IDR: Not set)
AP[3]: MEM-AP (IDR: Not set)
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FE000
CPUID register: 0x410FD214. Implementer code: 0x41 (ARM)
Feature set: Mainline
Found Cortex-M33 r0p4, Little endian.
FPUnit: 8 code (BP) slots and 0 literal slots
Security extension: implemented
Secure debug: enabled
CoreSight components:
ROMTbl[0] @ E00FE000
[0][0]: E00FF000 CID B105100D PID 000BB4C9 ROM Table
ROMTbl[1] @ E00FF000
[1][0]: E000E000 CID B105900D PID 000BBD21 DEVARCH 47702A04 DEVTYPE 00 Cortex-M33
[1][1]: E0001000 CID B105900D PID 000BBD21 DEVARCH 47701A02 DEVTYPE 00 DWT
[1][2]: E0002000 CID B105900D PID 000BBD21 DEVARCH 47701A03 DEVTYPE 00 FPB
[1][3]: E0000000 CID B105900D PID 000BBD21 DEVARCH 47701A01 DEVTYPE 43 ITM
[1][5]: E0041000 CID B105900D PID 002BBD21 DEVARCH 47724A13 DEVTYPE 13 ETM
[1][6]: E0042000 CID B105900D PID 000BBD21 DEVARCH 47701A14 DEVTYPE 14 CSS600-CTI
[0][1]: E0040000 CID B105900D PID 000BBD21 DEVARCH 00000000 DEVTYPE 11 Cortex-M33
Cortex-M33 identified.
Halting CPU for downloading file.
Downloading file [./NVRAM]...

****** Error: Failed to prepare RAMCode using RAM
Unspecified error -1
J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: ARMv8M core with Security Extension enabled detected.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
J-Link>exit

Script processing completed.

And I had a third idea too, where everything is done by JLinkExe, but with that I couldn't even burn the new flash image itself. The error message was the same. Is it some kind of hidden write protection? Why? How to turn off?

I could make this work for nRF52 with just JLinkExe. I don't stick to nrfjprog, JLinkExe would also do for me (as it does for many other MCUs).

Any hints? How can I see what JLink commands nrfjprog is executing? Perhaps that'd help me, unless it's calling JLink tools from the shared library...

Thanks, regads,

Parents Reply Children
No Data
Related