nrfjproj

erase, write and read from Nordic nRF5 System On Chip

nrfjprog Nordic command invokes Segger j-link embedded debugger
jLinkARM is expected to be installed at /Applications/SEGGER/JLink There is actually no such file as jLinkARM.

Nordic/nRF5x-CL-Tools_ /nrfjprog/nrfjprog

/usr/local/bin/nrfjprog

See iPhone nRFConnect

See nrfutil which documents how flashable components are created. PC nRFutil

Requires:ERROR: JLinkARM DLL not found. Please reinstall latest JLinkARM.

-f
--family family
NRF51, NRF52 and UNKNOWN.
If UNKNOWN is given, an automatic family detection of the device is performed. providing the actual family is faster . If --family option is not given, the default is taken from nrfjprog.ini.
--program hex_file Fails If the target area is not erased, unless an erase option is given rc=58.

--verify

For internal flash memory

--sectorerase targeted pages
--sectoranduicrerase targeted pages and UICR
Not available for nRF51 devices.
--chiperase all the available user memory, including UICR.

With a QSPI peripheral and an external memory device present, data targeting the XIP region will be written to the external memory device.
The first address of the XIP region is considered as address 0 of the external memory device.
To determine if an external memory device is present, nrfjprog> checks MemSize from QspiDefault.ini or from the QSPI configuration ini file given with the --qspiini option.

    For external memory device :
  • --qspichiperase the external memory device will be erased.
  • --qspisectorerase only 4kB pages pages

--verify [hex_file]
         [--fast]
compare with the code flash, RAM, UICR and XIP regions (for devices equipped with a QSPI peripheral connected to an external memory device).
Fails with return code 55 if there is a mismatch.

With --fast calculate a hash of the flash target area and compare it to the expected hash instead of reading back the actual contents of the device's flash in order to speed the operation. For example a softdevice verify is reduced from 2.3 to 1.0 seconds.
Can be combined with --program, --memwr and --ramwr without hex_file .

nRF51 devices: --fast is not available.
--eraseuicr Erases the UICR page.
For nRF51 devices, the operation is available only if the device came with a pre-programmed SoftDevice.
--erasepage start[-end]Erases the flash pages (end is not included in the erase).
If end is not given, only one flash page will be erased.

If device is equipped with a QSPI peripheral the pages to erase belong to the XIP region and an external memory device is present, this command erases 4 kB pages from the external memory device.
The first address of the region is considered as address 0 of the external memory device.
To determine if an external memory device is present, nrfjprog checks the MemSize parameter from QspiDefault.ini or from the QSPI configuration ini file given with --qspiinii

nRF51 devices: the page will not be erased if it belongs to region 0.

--reset or --debugreset after the flash operation to start the execution.

If the hex_file provided contains sectors belonging to region 0, --program will fail.
--qspisectorerase and --qspichiperase are not available.

Must be combined with --memrd, --memwr, --program, --verify, --erasepage or --qspieraseall .

Not for nRF51, nRF52 or devices without a QSPI peripheral.

-e
--eraseall
Erases user available program flash memory and the UICR page.
Can be combined with --qspieraseall .

For nRF51 devices: if the device came with a pre-programmed SoftDevice, only the user available code flash and UICR will be erased.

--qspieraseall Erases all the flash of the external memory device using the QSPI peripheral.
Depending on the external memory device's erase speed the operation might take minutes.
Can be combined with --eraseall

Limitations: For nRF51 nRF52 devices, the operation is not available
for devices without a QSPI peripheral. For nRF52 devices, the operation is only available for devices connected to an external memory device.
To determine if an external memory device is connected, nrfjprog checks MemSize parameter from the QspiDefault.ini file or the QSPI configuration ini file that is given with the --qspiini

--rbp CR0 | ALL Enables the Readback Protection Mechanism.
This is designed to prevent reverse engineering the device by reading the code.
CR0 is invalid for nRF52 devices.
For nRF52 devices: only --pinreset, --debugreset or --recover operations are available after --rbp.

For nRF51 devices and ALL is used --pinreset will not work on older devices.
Specifically memrd, readUICR, readcode, readram, readqspi, program, … are not available!

--recover Erases all user available non-volatile memory and disables the read back protection mechanism, i.e. returns the device to the programable state.
--pinresetenable For nRF52 devices, pin reset will be enabled.(Invalid for nRF51 devices).
-p
--pinreset
Performs a pin reset. Core will run after the operation.
-r
--reset
Performs a soft reset by setting the SysResetReq bit of the AIRCR register of the core.
core will run after the operation.
Can be combined with --program .
Reset will occur after flashing
-d
--debugreset
Performs a soft reset by the use of the CTRL-AP.
core will run afterwards .
Can be combined with --program .
With the --program , the debug reset will occur after the flashing has occurred to start execution.

Limitations: For nRF51 devices, FnRF52832_xxAA_ENGA devices not available.

--memwr 0xaddr --val 0xval Writes 1 word only using the NVM Controller.
If not erased(i.e. FFFFFFFF ), the operation will fail. (even attempting to write same contents.)
ERROR: The area to write is not erased.
If device is equipped with a QSPI peripheral and the address to write belongs to the XIP region, uses the QSPI.
The first address of the region is considered as address 0 of the external memory device.

Can be combined with --verify .

 nrfjprog --memwr 0x10001080 --val 0x89010203 # write to first word of UICR
Parsing parameters.
Writing.

     
--memrd 0xaddr
      [--w 8|16|32]
      [--n [0x]n]
outputs n values from 0xaddr.
If width is not given, 32-bit values will be displayed, if addr is 16bit aligned, 16-bit values if addr is half word aligned, and 8-bit values otherwise.
The address and n must be aligned to the width parameter.
Default: n is 1.
The maximum number of bytes is 1 MB.

If device is equipped with a QSPI peripheral, and 0xaddr belongs to the XIP region, the QSPI peripheral is used to read from the external memory device. The first address of the region is considered as address 0 of the external memory device. A single --memrd cannot read addresses from both the external memory and the nRF device.

nrfjprog --memrd 0x10001080   --n 128  #  implied --w 32   read fICR
0x10001080: 00001083 00001083 D6010203 FFFFFFFF   |...o.............| 
0x10001090: D6010203 FFFFFFFE FFFFFFFF 30313233   |............3210| 
                                        0 1 2 3  ~~~~~~~~~~~~~~'
…
0x100010F0: FFFFFFFF FFFFFFFF FFFFFFFF FCFDFEFF   |................|

nrfjprog --memrd 0x10001080  --w 8 --n 0x20
0x10001080: 83 10 00 00 83 10 00 00 03 02 01 D6 FF FF FF FF   |................|
0x10001090: 03 02 01 D6 FE FF FF FF FF FF FF FF 33 32 31 30   |............3210|
                                                 3  2  1  0 !
 nrfjprog --memrd 0x10001080  --w 16  --n 0x20
0x10001080: 1083 0000 1083 0000 0203 D601 FFFF FFFF   |................|
0x10001090: 0203 D601 FFFE FFFF FFFF FFFF 3233 3031   |............3210|
                                           2 3  0 1  ~~~~~~~~~~~~~~'

'/Applications/Nordic Semiconductor/nrfjprog/nrfjprog'  --memrd 0x10000100 --w 32 --n 4   # part#
0x10000100: 00052832                              |2(..|


Omitting the 0x will most likely NOT display what you expect!

Omitting the 0x and including a hex digit causes the error:

ERROR: Argument provided has a wrong value. Memory access not aligned, value
ERROR: outside of range or similar  RC=54.
Specifying only 1 '-' instead of '--'
ERROR: An invalid argument was provided. Use --help for a list of valid
ERROR: arguments.
--ramwr 0xaddr --val valWrites without using the NVM Controller.
If the target address is in non-volatile memory, has no effect unless the non-volatile memory controller (NVMC) has been previously configured by the user for a write operation.
Can be combined with --verify .
--halt Halts the CPU core.
--run [--pc 0xpc_addr
       --sp 0xsp_addr]
Starts the CPU.
pc_addr last bit must be one.
sp_addr must be word aligned.
--readuicr fileu.hex Reads the device UICR and stores it in file .
Creates Intel Hex format file (incorrectly starts at 10000000 for 11,550 characters, S.B. only 10001080 - 100010FF
:020000041000EA
:10100000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
:10101000FFFFFFFF0050070000E00700FFFFFFFF9A
…
:10107000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80
:101080000302010083100000030201D6FFFFFFFFEF  [ 0- 3] NRF_UICR->CUSTOMER[0]
:10109000030201D6FEFFFFFFFFFFFFFF33323130B7  [ 4- 7]
:1010A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF50  [ 8-11]
:1010B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40  [12-15]
:1010C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF30  [16-19]
:1010D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20  [20-23]
:1010E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF10  [24-27]
:1010F000FFFFFFFFFFFFFFFFFFFFFFFFFFFEFDFC06  [28-31] NRF_UICR->CUSTOMER[31]
:10110000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF
…
:101FF000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1
:00000001FF
Can be combined with --readram, --readcode and --readqspi.
--readcode filef.hex Reads the device flash … 1,474,709 characters including record size,type, addres and checksum.
--readram filer.hex Reads the device ram … 184,350 characters
--readqspi file Reads the QSPI-connected external memory …
Available inactively using /Applications/SEGGER/JLink_V633a/JLinkExe
--jdll file Use Segger's JLinkARM dll specified in the given file path (yes Mac OS too)
-i
--ids
Displays serial numbers debuggers connected to the PC.
682930364
-s
--snr serial_number
Selects the debugger with the given serial number
-c
--clockspeed khz
debugger SWD clock speed in kHz 125 kHz to 50000 kHz. If clockspeed is above the maxiumum clockspeed supported by the emulator, its maximum will be used . Default from nrfjprog.ini.
--qspiini file Uses the QSPI settings file specified in the given
--readregs Reads the cpu registers.
--licenses Displays the licenses of the open source modules used in nrfjprog.exe.
-q --quiet Reduces the stdout info. Must be combined with another command.
-h --help
-v --version Displays the nrfjprog and dll versions.

Example

nrfjprog --family nrf52 --sectorerase --program  $zipname.hex --verify --log |\
                     grep -v 'Erasing page at address 0x'

nrfjprog --family nrf52 --sectorerase --program  $zipname.settings.hex --verify --reset 

Nordic/nRF5x-Command-Line-Tools_9_4_0_OSX/nrfjprog

Errors

May return 0 even though there was an error.
ERROR: There is no debugger connected to the PC.  return code:41 Is Nordic dev board switched on?

ERROR: The file specified could not be found. return code:51 

ERROR: Write verify failed.  return code:55 

ERROR: JLinkARM DLL not found. Please reinstall latest JLinkARM. return code:30

Parsing image file.
 was not recognized as supported.
ERROR: Command executed requires write permission in the current directory.
Expected .hex extension.

Parsing image file.
Found end of content before end of file in x.hex.
ERROR: The file specified is not a valid hex file, has data outside valid areas
ERROR: or does not have data in valid areas.  
 Check that the file is complete using tail -n 1 and observe end-of-file record: :00000001FF.

jLinkARM is expected to be installed at /Applications/SEGGER/JLink
There is actually no such file as jLinkARM. @ symbolic link

See j-link and nRFutil