pyswd
pyswd copied to clipboard
Command failure on certain versions
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