square / pylink

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

Exception "Writing target memory failed" does not get raised. #142

Open pirib opened 2 years ago

pirib commented 2 years ago

Hi,

When I try flashing the target device using JLink commander on linux (e.g. JLinkExe) I get Writing target memory failed error thrown. The issue has already been resolved on my side - I was using the wrong firmware file for the target device.

But when I try to use the same, wrong file in code, no exceptions are raised. The callback function on_progress is also silent throughout the process of "flashing".

try:
    self.jlink.flash_file(path=firmware_file, addr=0, on_progress=callback_func)
    self.logger.info("Flash successful")

except JLinkFlashException as jlinkFlashException:
    self.logger.error(f"Error while flashing the target. Error: {jlinkFlashException}")

except Exception as exception:
    self.logger.error(exception)

Just to clarify, no exceptions are raised whatsoever.

hkpeprah commented 2 years ago

Do you know for sure it is failing? Can you run with verbosity in the logging to see?

import logging

logging.basicConfig(level=logging.DEBUG)
pirib commented 2 years ago

Well, there are two indicators to as of why I think it is failing:

  1. Executing the very same commands using JLink commander results in Writing target memory failed.. Btw, this is the only output from the loadfile command. Connecting, erasing, reading the memory works as expected.
  2. After flashing using the pylink (where no exceptions are raised and on_progress is silent the entire operation) I run the in-house tests, e.g. perform simple communication with the target device, and as expected, it is dead silent.

Here is the log file from running the flash_file(). I redacted some info with potentially sensitive data.


Attempting to flash the target using image ___
DEBUG:pylink.jlink:T74341740 001:536.860   
DEBUG:pylink.jlink:Data:  ___
DEBUG:pylink.jlink:

DEBUG:pylink.jlink:T74341740 001:537.365   
DEBUG:pylink.jlink:CPU_WriteMem(24355 bytes @ 0x0000A000)
DEBUG:pylink.jlink:

DEBUG:pylink.jlink:T74341740 001:629.843   
DEBUG:pylink.jlink:Data:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
DEBUG:pylink.jlink:

DEBUG:pylink.jlink:T74341740 001:630.078   
DEBUG:pylink.jlink:CPU_WriteMem(220 bytes @ 0x0000FF24)
DEBUG:pylink.jlink:

DEBUG:pylink.jlink:T74341740 001:631.536 
DEBUG:pylink.jlink:- 227.232ms returns 0x00

DEBUG:pylink.jlink:T74341740 001:631.685 
DEBUG:pylink.jlink:JLINK_IsOpen()

DEBUG:pylink.jlink:T74341740 001:631.739 
DEBUG:pylink.jlink:- 0.075ms returns 0x01

DEBUG:pylink.jlink:T74341740 001:631.786 
DEBUG:pylink.jlink:JLINK_EMU_IsConnected()

DEBUG:pylink.jlink:T74341740 001:631.828 
DEBUG:pylink.jlink:- 0.062ms returns TRUE

DEBUG:pylink.jlink:T74341740 001:631.873 
DEBUG:pylink.jlink:JLINK_IsOpen()

DEBUG:pylink.jlink:T74341740 001:631.913 
DEBUG:pylink.jlink:- 0.059ms returns 0x01

DEBUG:pylink.jlink:T74341740 001:637.176 
DEBUG:pylink.jlink:JLINK_Close()

DEBUG:pylink.jlink:T74341740 001:637.644   
DEBUG:pylink.jlink:CPU_ReadMem(4 bytes @ 0xE0001000)
DEBUG:pylink.jlink:

Process finished with exit code 0