Skip to content

Commit

Permalink
Switch to read-write-modify flashing.
Browse files Browse the repository at this point in the history
This enables programming the chip without having to erase the entire contents.
Instead, JLink will erase where needed while retaining the data that's within
the same sectors but outside of the specified write area.

Closes square#154, square#148
  • Loading branch information
denravonska committed Nov 25, 2022
1 parent 1959f98 commit 8cc7759
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pylink/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,9 +2192,18 @@ def flash(self, data, addr, on_progress=None, power_on=False, flags=0):
except errors.JLinkException:
pass

res = self.flash_write(addr, data, flags=flags)
# Perform read-modify-write operation.
res = self._dll.JLINKARM_BeginDownload(flags=flags)
if res < 0:
raise errors.JLinkEraseException(res)

return res
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

@connection_required
def flash_file(self, path, addr, on_progress=None, power_on=False):
Expand Down
5 changes: 4 additions & 1 deletion pylink/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class Library(object):
'JLINK_SWD_StoreRaw',
'JLINK_SWD_SyncBits',
'JLINK_SWD_SyncBytes',
'JLINK_SetFlashProgProgressCallback'
'JLINK_SetFlashProgProgressCallback',
'JLINKARM_BeginDownload',
'JLINKARM_EndDownload',
'JLINKARM_WriteMem'
]

# On Linux and macOS, represents the library file name prefix
Expand Down

0 comments on commit 8cc7759

Please sign in to comment.