square / pylink

Python Library for device debugging/programming via J-Link
https://pylink.readthedocs.io/en/latest/
Other
346 stars 127 forks source link

erase() and flash_file functions are not working #135

Open Dave5217 opened 2 years ago

Dave5217 commented 2 years ago

I am trying to automate the erasing and reflashing of a chip but none of them are working. Here is my code:

import pylink import time

error = '' file = 'example.bin' jlink = pylink.JLink()

jlink.open(serial_no=601011318) jlink.set_tif(1)

try: jlink.connect('CORTEX-M0', 4000) jlink.erase() sleep(5) jlink.flash_file(file,0x0)

except error: print('Couldn't do it')

finally: jlink.close()

The erase function doesn't erase the chip but throws no exception. The flash_flie function throws the following exception: JLinkFlashException: Could not write target memory.

hkpeprah commented 2 years ago

You likely need to stop the core before flashing it using: .halt().

Dave5217 commented 2 years ago

I saw that the method checks if the core is halted and halts it if it's not, but anyway I tried to stop the core first and got the same exception

hkpeprah commented 2 years ago

Hm, usually an error like that happens if the device isn't stopped, or if it has to be reset in a special mode (see here for troubleshooting ideas). If you run with verbosity enabled, you should be able to see more logs that should point to where the issue is (e.g. "Failed to Stop Core").