Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add API to write peripheral register of target system #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions pylink/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,87 @@ def memory_write64(self, addr, data, zone=None):
words.append((long_word >> 32) & bitmask) # First 32-bits
return self.memory_write32(addr, words, zone=zone)

@connection_required
def peripheral_write8(self, addr, value):
"""Writes byte to peripheral register of target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
value (int): the value to write to the register

Returns:
The value written to the register.

Raises:
JLinkException: on write error.
"""
res = self._dll.JLINKARM_WriteU8(addr, value)
if res != 0:
raise errors.JLinkWriteException('Error writing to %d' % addr)
return value

@connection_required
def peripheral_write16(self, addr, value):
"""Writes half-word to peripheral register of target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
value (int): the value to write to the register

Returns:
The value written to the register.

Raises:
JLinkException: on write error.
"""
res = self._dll.JLINKARM_WriteU16(addr, value)
if res != 0:
raise errors.JLinkWriteException('Error writing to %d' % addr)
return value

@connection_required
def peripheral_write32(self, addr, value):
"""Writes word to peripheral register of target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
value (int): the value to write to the register

Returns:
The value written to the register.

Raises:
JLinkException: on write error.
"""
res = self._dll.JLINKARM_WriteU32(addr, value)
if res != 0:
raise errors.JLinkWriteException('Error writing to %d' % addr)
return value

@connection_required
def peripheral_write64(self, addr, value):
"""Writes long word to peripheral register of target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
value (long): the value to write to the register

Returns:
The value written to the register.

Raises:
JLinkException: on write error.
"""
self._dll.JLINKARM_WriteU64.argtypes = [ctypes.c_uint32, ctypes.c_uint64]
tianxiaoMCU marked this conversation as resolved.
Show resolved Hide resolved
res = self._dll.JLINKARM_WriteU64(addr, value)
if res != 0:
raise errors.JLinkWriteException('Error writing to %d' % addr)
return value

@connection_required
def register_read(self, register_index):
"""Reads the value from the given register.
Expand Down