pyswd icon indicating copy to clipboard operation
pyswd copied to clipboard

Command failure on certain versions

Open schneidersoft opened this issue 1 year ago • 0 comments

I have noticed that some stlinkv2 versions do not work as expected I use the following python code:

import swd

dev = swd.Swd()
print(dev.get_version().str)
print(dev.get_target_voltage())
print(dev.get_idcode())

cm = swd.CortexM(dev)

cm.halt()
cm.reset()
cm.run()

print(cm.get_reg('PC'))

And get the following output:

$ python3 swdtest.py 
ST-Link/V2 V2J38S7
3.23
463475831
Traceback (most recent call last):
  File "swdtest.py", line 14, in <module>
    print(cm.get_reg('PC'))
  File "/usr/local/lib/python3.8/dist-packages/swd/cortexm.py", line 61, in get_reg
    return self._swd.get_reg(CortexM._get_reg_index(reg))
  File "/usr/local/lib/python3.8/dist-packages/swd/swd.py", line 58, in get_reg
    return self._drv.get_reg(register)
  File "/usr/local/lib/python3.8/dist-packages/swd/stlink/__init__.py", line 251, in get_reg
    _check_status(status)
  File "/usr/local/lib/python3.8/dist-packages/swd/stlink/__init__.py", line 56, in _check_status
    raise StlinkException(_com.StlinkCom.STATUS.MESSAGES[status])
swd.stlink.StlinkException: Command error

With a different stlinkv2

$ python3 swdtest.py 
ST-Link/V2 V2J33S7
3.23
463475831
0

schneidersoft avatar Mar 19 '23 09:03 schneidersoft