How to read/write/erase on QSPI through nrfjprog

NRF52840 DK board has a QSPI flash.  It can use to run the code (SIP) or act as the external normal flash.

In this passage, I would like to share how to use the nrfjprog for accessing the QSPI flash on the NRF52840 DK Board.

if you need to use the qspi on the NRF52840 DK board, you need to include the

nrfjprog --qspicustominit 

It would call the qspidefault.ini (red color) instruction.

; Custom instructions to send to the external memory after initialization. Only used if –qspicustominit option is given in the call to nrfjprog. Format is
; instruction code plus data to send in between optional brakets. Numbers can be given in decimal, hex (starting with either 0x or 0X) and binary (starting
; with either 0b or 0B) formats. The custom instructions will be executed in the order found.
; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) enabling the Quad Operation and the High Performance
; mode for the MX25R6435F memory present in the nRF52840 DK.
InitializationCustomInstruction = 0x06
InitializationCustomInstruction = 0x01, [0x40, 0, 0x2]

Check the version of the nrfjprog [download]

cmd> nrfjprog -v

nrfjprog -v
nrfjprog version: 9.8.1
JLinkARM.dll version: 6.40

Get the help menu of the nrfjprog [online user manual]

cmd> nrfjprog -h

(https://www.nordicsemi.com/DocLib/Content/User_Guides/nrf5x_cltools/latest/UG/cltools/nrf5x_nrfjprogexe_reference)


Erase the QSPI flash content

cmd> nrfjprog --qspieraseall

Erases all the flash of the external memory device
with the help of the QSPI peripheral. Note that
depending on the external memory device’s erase
speed the operation might take minutes. Can be
combined with the –eraseall operation.
Limitations:
For nRF51 devices, the operation is not available.
For 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 option.

cmd> nrfjprog -f nrf52 --qspicustominit --qspieraseall

 


Read the content from QSPI flash

nrfjprog -f nrf52 --qspicustominit --memrd 0x12001000 --w 8 --n 0x0100
0x12001000: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001010: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001020: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001030: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001040: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001050: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001060: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001070: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001080: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x12001090: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010A0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010B0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010C0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010D0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010E0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|
0x120010F0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF |................|

Write the HEX on QSPI flash

You need to change the address on given HEX.  You can use the tool objcopy.

https://ftp.gnu.org/old-gnu/Manuals/binutils-2.12/html_node/binutils_5.html#SEC5

NRFJPROG can be used to program the DFU images to onboard SPI flash on PCA10056.

To program the QSPI flash memory by NRFJPROG, convert the binary file to HEX format plus a memory offset of 0x12000000.

For example,

Convert the DFU image files for SPI flash 1st DFU image.

  • objcopy -v -I binary -O ihex --change-addresses 0x12001000 init_pkt.bin init_pkt.hex
  • objcopy -v -I binary -O ihex --change-addresses 0x12002000 nrf52840_xxaa.bin fw_bin.hex

Convert the DFU image files for SPI flash 2nd DFU image.

  • objcopy -v -I binary -O ihex --change-addresses 0x12100000 init_pkt.bin init_pkt.hex
  • objcopy -v -I binary -O ihex --change-addresses 0x12101000 nrf52840_xxaa.bin fw_bin.hex

 

Program the HEX files by NRFJPROG. A customized INI file may be needed for tuning QSPI parameters.

nrfjprog -f nrf52 --qspicustominit --program fw_bin.hex

 

2 thoughts on “How to read/write/erase on QSPI through nrfjprog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.