NordicSemiconductor / pynrfjprog

Python wrapper around the nrfjprog dynamic link library (DLL)
Other
75 stars 29 forks source link

lowlevel api sector erase may fail silently #30

Open jmalangoni opened 1 year ago

jmalangoni commented 1 year ago

I have been using your low-level API to reflash devices for some time now, but recently found that sector erase + programming can fail if the device is not first reset and halted. Not sure if this is due to an update in pynrfjprog, jlink dll, or even the firmware running at the time of reprogramming.

The code below will raise pynrfjprog.APIError.APIError: An error was reported by NRFJPROG DLL: -102 JLINKARM_DLL_ERROR from program_file method

with pynrfjprog.LowLevel.API() as api:
    api.connect_to_emu_without_snr()
    #api.sys_reset()
    #api.halt()
    api.erase_file(img_path, pynrfjprog.LowLevel.EraseAction.ERASE_SECTOR)
    #api.sys_reset()
    #api.halt()
    api.program_file(img_path)
    api.disconnect_from_emu()

Uncommenting only the first set of sys_reset and halt commands will fix the issue and result in successful reflashing.

Uncommenting only the second set of sys_reset and halt commands will cause the reflashing to fail silently.

I assume this is due to failure to sector erase before programming, however I was not expecting the failure to be silent.

Post-reflashing verification with an api.verify_file(img_path) does of course catch the issue.

pynrfjprog version 10.19.0 jlink dll version V7.84a