pyocd / pyocd/pyOCD

Unable to connect to STM32F103 with JTAG

Open
#1,722 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
560
Avg merge
1h 41m
Merged PRs (30d)
3

Description

Environment
  • Windows 10 22H2
  • Python 3.12
  • pyOCD 0.36.0
  • DIY CMSIS-DAP v2 probe
  • J-Link V9 probe
  • IAR EWARM 9.5
  • OpenOCD 0.12.0-4
Issue

pyOCD unable to connect to STM32F103 with JTAG, while SWD is working.

To rule out other issues all SW-HW combinations are tested (eg. CMSIS-DAP + OpenOCD in JTAG, J-Link + IAR in SWD, etc).

For both J-Link V9 and CMSIS-DAP probe pyOCD doesn't work in JTAG mode, all other combinations are working.

Error with J-Link:

$ pyocd load --target stm32f103rc -O dap_protocol=jtag -f 1000000 -a 0x20000000 "debug.bin" -v -O reset_type=hw
0000629 I Target type is stm32f103rc [board]
0000657 I DP IDR = 0x00000000 (v0 rev0) [dap]
0005668 C No cores were discovered! [__main__]

Error with CMSIS-DAP:

$ pyocd load --target stm32f103rc -O dap_protocol=jtag -f 1000000 -a 0x20000000 "debug.bin" -v -O reset_type=hw
0000648 I Target type is stm32f103rc [board]
0000741 C Unexpected ACK value (0) returned by probe [__main__]
Log
0000638 D Project directory: C:\Users\M[session]
0000638 D Project directory: C:\Users\M[session]
0000683 D CMSIS-DAP v2 probe 7C6FC9A3A144F536: protocol version 2.1.2 [dap_access_cmsis_dap]
0000685 I Target type is stm32f103rc [board]
0000731 D Running task load_svd [sequencer]
0000731 D Running task pre_connect [sequencer]
0000731 D Running task dp_init [sequencer]
0000731 D Running task lock_probe [sequencer]
0000732 D Running task get_probe_capabilities [sequencer]
0000732 D Running task connect [sequencer]
0000733 D Using JTAG wire protocol [dap]
0000741 D Sending deprecated SWJ sequence to select JTAG [swj]
0000778 D DP IDCODE read failed; resending SWJ sequence (use dormant=False) [dap]
0000778 D Sending deprecated SWJ sequence to select JTAG [swj]
0000779 D DP IDCODE read failed; resending SWJ sequence (use dormant=False) [dap]
0000779 D Sending SWJ sequence to select JTAG ; using dormant state [swj]
0000780 D DP IDCODE read failed; resending SWJ sequence (use dormant=False) [dap]
0000780 D Sending SWJ sequence to select JTAG ; using dormant state [swj]
0000781 D DP IDCODE read failed; resending SWJ sequence (use dormant=False) [dap]
0000781 D uninit session <pyocd.core.session.Session object at 0x000001CCF50B5AF0> [session]
0000782 C Unexpected ACK value (0) returned by probe [__main__]
Traceback (most recent call last):
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\cmsis_dap_probe.py", line 539, in read_dp
    result = self._link.read_reg(reg_id, now=now)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 1086, in read_reg
    return read_reg_cb()
           ^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 1080, in read_reg_cb
    res = transfer.get_result()
          ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 161, in get_result
    self.daplink.flush()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\utility\concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 885, in flush
    self._read_packet()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\utility\concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 1166, in _read_packet
    decoded_data = cmd.decode_data(raw_data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 482, in decode_data
    data = self._decode_transfer_block_data(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 451, in _decode_transfer_block_data
    self._check_response(data[3])
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 374, in _check_response
    raise DAPAccessIntf.TransferError("Unexpected ACK value (%d) returned by probe" % ack)
pyocd.probe.pydapaccess.dap_access_api.DAPAccessIntf.TransferError: Unexpected ACK value (0) returned by probe

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\__main__.py", line 161, in run
    status = cmd.invoke()
             ^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\subcommands\load_cmd.py", line 100, in invoke
    with session:
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\core\session.py", line 415, in __enter__
    self.open()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\core\session.py", line 553, in open
    self._board.init()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\board\board.py", line 143, in init
    self.target.init()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\coresight\coresight_target.py", line 123, in init
    super().init()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\core\soc_target.py", line 174, in init
    seq.invoke()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\utility\sequencer.py", line 213, in invoke
    resultSequence.invoke()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\utility\sequencer.py", line 208, in invoke
    resultSequence = call()
                     ^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\coresight\dap.py", line 467, in _connect
    connector.connect()
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\coresight\dap.py", line 257, in connect
    self._idr = self.read_idr()
                ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\coresight\dap.py", line 286, in read_idr
    dpidr = self._probe.read_dp(DP_IDR, now=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyocd\probe\cmsis_dap_probe.py", line 542, in read_dp
    raise self._convert_exception(error) from error
pyocd.core.exceptions.TransferError: Unexpected ACK value (0) returned by probe
Capture

I've captured the traffic of pyOCD + CMSIS-DAP and OpenOCD + CMSIS-DAP.

Open with DSView :
jtag.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pyocd/coresight/dap.py at connect() and read_idr(), then inspect probe/cmsis_dap_probe.py alongside the jtag.zip capture. Reproduce the pyocd load command and compare its JTAG traffic with the working OpenOCD capture. Done means pyOCD can establish a JTAG connection to the STM32F103 and complete the load operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, embedded-iot
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.