flash and debug custom nRF5340 fails

Hello,
I'using nRF Connect SDK 1.9.1 on linux mint PC.
nrfjprog version : 10.15.3 external
Jlink version :JLink_V758b
nRF chip : nRF5340
I'm able to flash, debug the nRF5340 DK without any problem with west, nrfjprog, JLinkExe, SEGGER Embedded Studio,...
I have a custom board runs nRF5340 and I use my nRF5340 DK as axternal JLink prob.

I couldn't flash the custom board with hello_world program because the readback protection

nrfjprog -f nRF53 --coprocessor CP_APPLICATION -r --verify --program build/zephyr/zephyr.hex  --sectorerase                                            62 ↵

ERROR: The operation attempted is unavailable due to readback protection in
ERROR: your device. Please use --recover to unlock the device.

I tried to use recover but no luck.


nrfjprog -f nRF53 --coprocessor CP_APPLICATION --recover                                                                                               16 ↵

Recovering device. This operation might take 30s.
ERROR: Recover failed. Please make sure that the correct device family is given
ERROR: and try again

so , I used the method from this blog to unsecure the nRF5340 
Allowing debugger access to nRF5340 - Blogs - Nordic Blog - Nordic DevZone (nordicsemi.com)

This the log I got after runnig JLinkExe   -CommandFile   nrf_flash.jlink  

nrf_flash.jlink

JLinkExe   -CommandFile   nrf_debug.jlink
SEGGER J-Link Commander V7.58b (Compiled Nov 16 2021 15:04:43)
DLL version V7.58b, compiled Nov 16 2021 15:04:27


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 OB-nRF5340-NordicSemi compiled Dec  3 2021 15:46:49
Hardware version: V1.00
S/N: 1050063546
VTref=3.300V
Selecting SWD as current target interface.

Selecting 4000 kHz as target interface speed


Device "NRF5340_XXAA_APP" selected.


Connecting to target via SWD
ConfigTargetSettings() start
ConfigTargetSettings() end
InitTarget() start
AHB-AP CSW register indicates that the device is secured.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash, SRAM and UICR of both the application and the network core.

Executing default behavior previously saved in the registry.
Device will be unsecured now.
InitTarget() end
ConfigTargetSettings() start
ConfigTargetSettings() end
InitTarget() start
AHB-AP CSW register indicates that the device is secured.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash, SRAM and UICR of both the application and the network core.

Executing default behavior previously saved in the registry.
Device will be unsecured now.
InitTarget() end
Found SW-DP with ID 0x6BA02477
DPIDR: 0x6B802467
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: 0x410FD014. Implementer code: 0x41 (ARM)
Unknown core, assuming Cortex-M0
Found Cortex-M0 r0p4, Little endian.
Identified core does not match configuration. (Found: Cortex-M0, Configured: Cortex-M33)
FPUnit: 8 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl[0] @ E00FE000
[0][0]: E00FE000 CID A105100D PID 006C4007 ???
[0][1]: E003E000 CID 00000000 PID 00000000 ???
Cortex-M0 identified.

Select SWD by sending SWD switching sequence.

Write DP register 1 = 0x50000000

Sleep(100)

Write DP register 2 = 0x020000F0

Sleep(100)

Read AP register 3 = 0x00000000

Sleep(100)

Read AP register 3 = 0x00000000

Sleep(100)

Write DP register 2 = 0x02000000

Sleep(100)

Read AP register 2 = 0x12880000

Sleep(200)

Read AP register 2 = 0x00000000

Sleep(200)

Read AP register 2 = 0x00000000

Sleep(200)

Read AP register 2 = 0x00000000

Sleep(200)

Disconnecting from J-Link...O.K.
Device "NRF5340_XXAA_APP" selected.


Connecting to target via SWD
ConfigTargetSettings() start
ConfigTargetSettings() end
InitTarget() start
AHB-AP CSW register indicates that the device is secured.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash, SRAM and UICR of both the application and the network core.

Executing default behavior previously saved in the registry.
Device will be unsecured now.
InitTarget() end
ConfigTargetSettings() start
ConfigTargetSettings() end
InitTarget() start
AHB-AP CSW register indicates that the device is secured.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash, SRAM and UICR of both the application and the network core.

Executing default behavior previously saved in the registry.
Device will be unsecured now.
InitTarget() end
Found SW-DP with ID 0x6BA02477
DPIDR: 0x6BA02077
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: 0x410FD210. Implementer code: 0x41 (ARM)
Feature set: Mainline
Found Cortex-M33 r0p0, 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]: DFF0D000 CID 00000000 PID 00000000 ???
[1][1]: E0001000 CID B105900D PID 000B3D21 DEVARCH 47701A02 DEVTYPE 00 DWT
[1][2]: E0002000 CID B105900D PID 000ABD21 DEVARCH 47701203 DEVTYPE 00 Cortex-M33 (?)
[1][3]: E0000000 CID B105900D PID 000BBD21 DEVARCH 47701000 DEVTYPE 43 Cortex-M33 (?)
[1][5]: E0041000 CID B105900D PID 002BBD21 DEVARCH 47724A13 DEVTYPE 13 ETM
[1][6]: E0042000 CID 3105900D PID 000BBD21 DEVARCH 47701A14 DEVTYPE 14 ???
[0][1]: E0040000 CID B105900D PID 000BBD21 DEVARCH 00000000 DEVTYPE 11 Cortex-M33
Cortex-M33 identified.

Sleep(500)

Downloading file [build/zephyr/zephyr.hex]...

****** Error: Verification of RAMCode failed @ address 0x20000008.
Write: 0xE7F9F99D 11223344
Read: 0xE7F1F11D 01222344
Failed to prepare for programming.
Failed to download RAMCode!
Unspecified error -1


Script processing completed.


Q1: Did I miss something in order to flash and debug the new board?
Q2: It there a way to disable permanently the security feature and restore it later ?

Thank you

Related