square / pylink

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

argument 3: <class 'TypeError'>: Don't know how to convert parameter 3 when running flash #202

Closed SoftubeBask closed 4 weeks ago

SoftubeBask commented 4 weeks ago

Hello,

Upgraded from 0.11 to the latest (1.2.0) and get the error when trying to flash the target. I've tried to change the parameters but get the same error.

` def on_progress_cb(self, action, progress_string, percentage): if progress_string is not None: print(progress_string)

payload = progress_string.decode('utf-8')

        # message:DataType = DataType(interface=InterfaceEnum.CONTROL, target=TargetEnum.VERTIGO, data=self.create_message("PROGRESS", payload))
        # self.queue.put(message)
        # time.sleep(0.1) # Wait to make sure that this packet is sent alone

def flash_image(self, address, image):
    try:
        interface_swd = 1
        jlink_target = pylink.JLink()
        jlink_target.open()
        jlink_target.oem
        jlink_target.set_tif(interface_swd)

        jlink_target.connect("MIMXRT1021DAG5A", verbose=True, speed=4000)
        jlink_target.reset()
        jlink_target.halt()

        print(address)
        print((int(address, 16)))
        jlink_target.flash(image, (int(address, 16)), on_progress=self.on_progress_cb)
        jlink_target.reset()
        self.logger.write(self, "  - Flashing Done!")`

Raw address is 0x60000000 and converted to int it is 1610612736. What am I missing?

hkpeprah commented 4 weeks ago

Can you post the full traceback?

SoftubeBask commented 4 weeks ago

Sure, here is the traceback:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/hwteam/git/vertigo_hil_client/control_interface.py", line 73, in flash_image
    jlink_target.flash(image, (int(address, 16)), on_progress=self.on_progress_cb)
  File "/home/hwteam/.local/lib/python3.9/site-packages/pylink/jlink.py", line 173, in wrapper
    return func(self, *args, **kwargs)
  File "/home/hwteam/.local/lib/python3.9/site-packages/pylink/jlink.py", line 2202, in flash
    bytes_flashed = self._dll.JLINKARM_WriteMem(addr, len(data), data)
ctypes.ArgumentError: argument 3: <class 'TypeError'>: Don't know how to convert parameter 3
hkpeprah commented 4 weeks ago

The issue seems to be with image, and not the address, as the data is the third argument to WriteMem(). What is the type of image that you pass in here?

        jlink_target.flash(image, (int(address, 16)), on_progress=self.on_progress_cb)
SoftubeBask commented 4 weeks ago

Oh, okay. It's a bytearray

hkpeprah commented 4 weeks ago

Can you try converting it to bytes?

>>> b = bytearray([1, 2, 3])
>>> type(b)
<class 'bytearray'>
>>> b
bytearray(b'\x01\x02\x03')
>>> b = bytes(b)
>>> type(b)
<class 'bytes'>
>>> b
b'\x01\x02\x03'
SoftubeBask commented 4 weeks ago

Tested to convert it to a list and don't get the exception now at least but I am remoting to the computer with the hardware, so i'm not able to confirm that the hardware boots. But whatever it is, it's probably my conversion to list that would be the culprit if there is any issues. Thank you for your speedy help!