NordicSemiconductor / pynrfjprog

Python wrapper around the nrfjprog dynamic link library (DLL)
Other
74 stars 26 forks source link

HighLevel interface cannot erase multiple QSPI sectors #31

Open bradjc opened 1 year ago

bradjc commented 1 year ago

I'm trying to use the DebugProbe.erase() function to erase multiple QSPI sectors. What I'm seeing is only the first sector is erased.

Here is my example code:

#!/usr/bin/env python3

import logging

import pynrfjprog
from pynrfjprog import HighLevel, Parameters

api = pynrfjprog.HighLevel.API()
api.open()

serial_numbers = api.get_connected_probes()

nrfjprog = pynrfjprog.HighLevel.DebugProbe(api, serial_numbers[0], log=True)
nrfjprog.setup_qspi(64 * 1024 * 1024)

address1 = 0x12009000

print("Erasing sector at address {:#x}".format(address1))
nrfjprog.erase(
    erase_action=pynrfjprog.Parameters.EraseAction.ERASE_SECTOR,
    start_address=address1,
    end_address=address1 + 4096,
)

print("Writing word to address {:#x}".format(address1))
nrfjprog.write(address=address1, data=6)

address2 = address1 + (4096 * 2)

print("Erasing sector at address {:#x}".format(address2))
nrfjprog.erase(
    erase_action=pynrfjprog.Parameters.EraseAction.ERASE_SECTOR,
    start_address=address2,
    end_address=address2 + 4096,
)

print("Writing word to address {:#x}".format(address2))
nrfjprog.write(address=address2, data=6)

print("Erasing range with both sectors {:#x}:{:#x}".format(address1, address2 + 4096))
nrfjprog.erase(
    erase_action=pynrfjprog.Parameters.EraseAction.ERASE_SECTOR,
    start_address=address1,
    end_address=address2 + 4096,
)

I write a word to two different flash sectors, and then erase the entire range. Output:

./pynrfjprog_qspi_erase_sectors_test.py
Erasing sector at address 0x12009000
Writing word to address 0x12009000
Erasing sector at address 0x1200b000
Writing word to address 0x1200b000
Erasing range with both sectors 0x12009000:0x1200c000

However, when I read the contents back:

$ nrfjprog --memrd 0x12009000 --w 8 --n 16
0x12009000: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF   |................|
$ nrfjprog --memrd 0x1200b000 --w 8 --n 16
0x1200B000: 06 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF   |................|

Only the first sector is erased.

Is this expected? When I use an address in the onboard nRF52840 flash the multi-sector erase erases all of the sectors.

My Setup