Skip to content

Incorrect usage of return value in flash_file method #237

@TheColector

Description

@TheColector

Hi,
I just found the following code inconsistency compared to what is stated both in DLL API and flash_file code documentation.

In flash_file documentation on return value, it says:

pylink/pylink/jlink.py

Lines 2248 to 2249 in 9a06468

Returns:
Integer value greater than or equal to zero. Has no significance.

Whereas, in code, it retreives the number of bytes written from DLL function called JLINK_DownloadFile - which actually does not return the number of bytes written, it returns either one of 6 status values (< 0 ) when error happens, or returns status ( > 0 ) when everything went OK

pylink/pylink/jlink.py

Lines 2273 to 2278 in 9a06468

# Program the target.
bytes_flashed = self._dll.JLINK_DownloadFile(path.encode(), addr)
if bytes_flashed < 0:
raise errors.JLinkFlashException(bytes_flashed)
return bytes_flashed

Unless I'm interpreting something wrong here, it might be some leftover from flash method implementation:

pylink/pylink/jlink.py

Lines 2224 to 2230 in 9a06468

bytes_flashed = self._dll.JLINKARM_WriteMem(addr, len(data), data)
res = self._dll.JLINKARM_EndDownload()
if res < 0:
raise errors.JLinkEraseException(res)
return bytes_flashed

In this case, it uses different DLL API call and it returns the number of bytes written, so this is correct.
I can make a PR with fix for that, but wanted to ask first if it's really a bug or there is some other reason for behind that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions