pylink
pylink copied to clipboard
nRF5340 flashing issue: Failed to prepare for programming. Could not preserve target memory.
Hi, struggling with flashing nRF5340. If I flash it manually with J-Flash Lite, first NET then APP core, it works fine. I need to flash both cores with no reset between them, NET and APP respectively, because of the readback protection.
jlk = pylink.JLink()
jlk.open(serial_no=int(jlink_sn))
jlk.set_tif(pylink.enums.JLinkInterfaces.SWD)
....
....
jlk.connect(chip_name='nrf5340_xxaa_net', verbose=True)
jlk.flash(binstr_obj1, min_addr1)
jlk.connect(chip_name='nrf5340_xxaa_app', verbose=True)
jlk.flash(binstr_obj2, min_addr2)
first flash is succesfully done, but after second flash I get error: Failed to prepare for programming. Could not preserve target memory.
Any ideas? Thanks!!
Do you have any more logs? Is it possible that the chip is not being properly held in reset?
I'm trying more things to get it working, so here is the only succesful setup for flashing:
- First the manual flash of merged hex (net and app core) is done via nRF Programmer
- Then I can run the script which is
jlk = pylink.JLink()
jlk.open(serial_no=int(jlink_sn))
jlk.set_tif(pylink.enums.JLinkInterfaces.SWD)
# SWDSelect
jlk.coresight_configure()
# SWDWriteDP 1 0x50000000
jlk.coresight_write(reg=1, data=0x50000000, ap=False)
# SWDWriteDP 2 0x020000F0
jlk.coresight_write(reg=2, data=0x020000F0, ap=False)
# SWDReadAP 3
jlk.coresight_read(reg=3, ap=True)
time.sleep(0.5)
# SWDReadAP 3
jlk.coresight_read(reg=3, ap=True)
time.sleep(0.5)
# SWDWriteDP 2 0x02000000
jlk.coresight_write(reg=2, data=0x02000000, ap=False)
# SWDWriteAP 1 1
jlk.coresight_write(reg=1, data=1, ap=True)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
# SWDWriteDP 2 0x03000000
jlk.coresight_write(reg=2, data=0x03000000, ap=False)
# SWDWriteAP 1 1
jlk.coresight_write(reg=1, data=1, ap=True)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
# SWDReadAP 2
jlk.coresight_read(reg=2, ap=True)
time.sleep(0.5)
jlk.connect(chip_name='nrf5340_xxaa_net', verbose=True)
jlk.flash(binstr_obj1, min_addr1)
jlk.connect(chip_name='nrf5340_xxaa_app', verbose=True)
jlk.flash(binstr_obj2, min_addr2)
If the chip is fully erased it fails as described in my first comment - it fails when the second flash is executed (when the app core is being flashed). Let me know if you need other information. Thank you!
PS: the sequence of reading and writing to the DAP registers is basicaly this: https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/allowing-debugger-access-to-an-nrf5340 without that I can not even connect to the target. If this sequence is skipped, I get error:
pylink.errors.JLinkException: Could not find supported CPU. Could not find core in Coresight setup
I would try playing around with the reset strategies here: https://pylink.readthedocs.io/en/latest/pylink.html#pylink.jlink.JLink.set_reset_strategy
It's possible that the core starts running after you flash the first asset, and changing the reset strategy might happen. There's also the set_reset_pin_high() and set_reset_pin_low() APIs where you can manually hold the core in reset while you do your flashing.
Hi, has this been resolved already?