diff --git a/pyocd/probe/stlink_probe.py b/pyocd/probe/stlink_probe.py index 4eb36e2cd..c603add1c 100644 --- a/pyocd/probe/stlink_probe.py +++ b/pyocd/probe/stlink_probe.py @@ -329,8 +329,8 @@ def read_memory_block8(self, addr: int, size: int, **attrs: Any) -> Sequence[int res = [] # read leading unaligned bytes - unaligned_count = addr & 3 - if (size > 0) and (unaligned_count > 0): + unaligned_count = 3 & (4 - (addr & 3)) + if (size > unaligned_count > 0): res += self._link.read_mem8(addr, unaligned_count, self._apsel, csw) size -= unaligned_count addr += unaligned_count @@ -355,8 +355,8 @@ def write_memory_block8(self, addr: int, data: Sequence[int], **attrs: Any) -> N idx = 0 # write leading unaligned bytes - unaligned_count = addr & 3 - if (size > 0) and (unaligned_count > 0): + unaligned_count = 3 & (4 - (addr & 3)) + if (size > unaligned_count > 0): self._link.write_mem8(addr, data[:unaligned_count], self._apsel, csw) size -= unaligned_count addr += unaligned_count