wuxx / pico-lab

Apache License 2.0
14 stars 2 forks source link

CMD_DAP_SWJ_CLOCK failed / DAP init failed #1

Closed openconcerto closed 2 years ago

openconcerto commented 2 years ago

Hi,

Something goes wrong for SWD programming. It's seems that the DAPLink is not working as expected.

OS : Ubuntu 20.04 (64bits) The installation was done as specified on the github page (ie compiling openocd from the raspberry repository). I tried with 2 different USB cables, and on USB2 and USB3 ports, same results...

So, having only the Pico-PMOD-ExtBoard plugged :

dap_flash_write.sh /opt/pico/pico-examples/blink/blink.bin 
EXT: bin
Open On-Chip Debugger 0.10.0+dev-g18b4c35-dirty (2021-09-30-17:31)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
swd
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 0256
Info : CMSIS-DAP: Serial# = 0700000100430034390000084e50364aa5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Error: CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed.

I tried to add "transport select swd" and "adapter speed 5000" in the cmsis-dap.cfg file, it fails with

Open On-Chip Debugger 0.10.0+dev-g18b4c35-dirty (2021-09-30-17:31)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 0256
Info : CMSIS-DAP: Serial# = 0700000100430034390000084e50364aa5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Error: Sequence 4 not supported
Info : DAP init failed

Running openocd in debug mode gives more interesting information :

Debug: 347 277 arm_dap.c:116 dap_init_all(): Initializing all DAPs ...
Error: 348 309 cmsis_dap_usb.c:935 cmsis_dap_swd_switch_seq(): Sequence 4 not supported
Debug: 349 341 cmsis_dap_usb.c:920 cmsis_dap_swd_switch_seq(): SWD line reset
Debug: 350 389 cmsis_dap_usb.c:728 cmsis_dap_swd_read_process(): SWD ack not OK @ 0 JUNK
Debug: 351 389 adi_v5_swd.c:655 swd_multidrop_select_target(): Failed to select core 0, retrying...
Debug: 352 421 cmsis_dap_usb.c:920 cmsis_dap_swd_switch_seq(): SWD line reset
Debug: 353 469 cmsis_dap_usb.c:728 cmsis_dap_swd_read_process(): SWD ack not OK @ 0 JUNK
Debug: 354 469 adi_v5_swd.c:655 swd_multidrop_select_target(): Failed to select core 0, retrying...
Debug: 355 501 cmsis_dap_usb.c:920 cmsis_dap_swd_switch_seq(): SWD line reset
Debug: 356 549 cmsis_dap_usb.c:728 cmsis_dap_swd_read_process(): SWD ack not OK @ 0 JUNK
Debug: 357 549 adi_v5_swd.c:655 swd_multidrop_select_target(): Failed to select core 0
Info : 358 549 arm_dap.c:337 handle_dap_init(): DAP init failed

Any idea is welcome. Thanks.

wuxx commented 2 years ago

hello, have you tried another pico, the first log seems that the e Pico-PMOD-ExtBoard is good, but it didn't detect the pico (rp2040)

wuxx commented 2 years ago

and do you have another MCU board, this Pico-PMOD-ExtBoard can also debug other ARM Cortex-M series MCU, please reference here https://github.com/wuxx/openocd-toolbox

openconcerto commented 2 years ago

Luckily, I have 5 rpi pico and 3 Pico-PMOD-ExtBoard, so I tried with a new pico and a new board.

Same behaviour... :(

openconcerto commented 2 years ago

I looked at the signals with a logic analyzer, I see activity on SWDIO and SWCLK but I'm not able to decode them.

openconcerto commented 2 years ago

Using a rpi pico with picoprobe, openocd was able to flash the pico with the WSD protocol.

IMHO, there is a bug in the firmware of the Pico-PMOD-ExtBoard.

wuxx commented 2 years ago

eh... lots board already shipped with this firmware... strange..

wuxx commented 2 years ago

have you tried the Pico-PMOD-ExtBoard. with some MCUs like STM32 and others..

wuxx commented 2 years ago

don't know what logic analyzer you use, but if you use fx2lafw based logic analyzer https://github.com/wuxx/nanoDLA the pulseview support SWD protocol

openconcerto commented 2 years ago

I use an AnalogDiscovery2.

Here is the capture that you can view/load/export with their (free) WaveForms software (https://mautic.digilentinc.com/waveforms-download)

=> capture : https://www.openconcerto.org/swd.dwf3logicacq

I have no STM32 card or nanoDLA to go further. From my tests, all I can say is

wuxx commented 2 years ago

Hello, here is my local test, everything is well. tested on raspberry pi, here is the detail log

pi@raspberrypi:~/oss/pico/pico-lab $ cd tools/
pi@raspberrypi:~/oss/pico/pico-lab/tools $ ls
dap_attach.sh      dap_flash_write.sh  dfw     env.sh  rpi_attach.sh      rpi_flash_write.sh  rreset
dap_flash_dump.sh  dap_reset.sh        dreset  rfw     rpi_flash_dump.sh  rpi_reset.sh
pi@raspberrypi:~/oss/pico/pico-lab/tools $ source env.sh
pi@raspberrypi:~/oss/pico/pico-lab/tools $ cd ..
pi@raspberrypi:~/oss/pico/pico-lab $ ls
demo  doc  firmware  LICENSE  README_cn.md  README.md  software  tools
pi@raspberrypi:~/oss/pico/pico-lab $ cd demo/
pi@raspberrypi:~/oss/pico/pico-lab/demo $ ls
blink.bin  breakout_board         hello_serial_io01.uf2    hello_serial_io1617.uf2  pico_ws2812.uf2
blink.uf2  hello_serial_io01.bin  hello_serial_io1617.bin  pico_ws2812.bin          vgademo_board
pi@raspberrypi:~/oss/pico/pico-lab/demo $ dfw blink.bin
EXT: bin
Open On-Chip Debugger 0.10.0+dev-g7c96119-dirty (2021-02-03-19:20)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 0256
Info : CMSIS-DAP: Serial# = 07000001004200354b0000144e4d3434a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : High speed (adapter speed 10000) may be limited by adapter firmware.
Info : clock speed 10000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
Info : RP2040 B0 Flash Probe: 2097152 bytes @10000000, in 512 sectors

target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
Info : Writing 16384 bytes starting at 0x0
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
shutdown command invoked
pi@raspberrypi:~/oss/pico/pico-lab/demo $
wuxx commented 2 years ago

how I connect 4473474b13209f8d300dc73432403e8

wuxx commented 2 years ago

and notice the script dap_flash_write.sh assume you has opneocd installed under /home/pi/oss/pico/openocd, maybe you need to modify the path in dap_flash_write.sh

openconcerto commented 2 years ago

Interesting!

The differences I see :

I try to add adapter speed 10000 in cmsis-dap.cfg, but that's not solving the problem. (of course, dap_flash_write.sh was modified to point to my install folder)

So it could be a problem on the cmsis-dap driver on x64 provided by raspberri via git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1

wuxx commented 2 years ago

yes, it's Raspbian on raspberrypi 3B+, I will also try it on my x64 ubuntu, please wait for a while.

wuxx commented 2 years ago

also try on my x64 ubuntu, it's still ok, openocd (https://github.com/raspberrypi/openocd.git) commit id is 7c96119 detail log

wuxx@ubuntu:~/oss/pico/pico-lab/demo$ uname -a
Linux ubuntu 4.4.0-173-generic #203-Ubuntu SMP Wed Jan 15 02:55:01 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
wuxx@ubuntu:~/oss/pico/pico-lab/demo$ dfw blink.bin
EXT: bin
Open On-Chip Debugger 0.10.0+dev-g7c96119-dirty (2021-10-04-19:26)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 0256
Info : CMSIS-DAP: Serial# = 07000001004200354b0000144e4d3434a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : High speed (adapter speed 10000) may be limited by adapter firmware.
Info : clock speed 10000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
Info : RP2040 B0 Flash Probe: 2097152 bytes @10000000, in 512 sectors

target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
Info : Writing 16384 bytes starting at 0x0
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00
shutdown command invoked
wuxx@ubuntu:~/oss/pico/pico-lab/demo$
openconcerto commented 2 years ago

I decided to investigate a little, I cooked a correct install script :

install-pico.sh.txt

and ran it on a other computer (Ubuntu 20.04 too).

After adding adapter speed 5000 in tcl/interface/cmsis-dap.cfg and modifying the path in dap_flash_write.sh

I was happy to see

 Open On-Chip Debugger 0.10.0+dev-g71510a7-dirty (2021-10-06-17:42)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 5000 kHz

Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 0256
Info : CMSIS-DAP: Serial# = 0700000100390074390000084e50364aa5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333

I will transfer my opencd directory to the other computer for a last check, but I suppose that there is something wrong on the USB stack of the ext-board. That's not the first time I see microcontrolers having issues with some motherboards controllers.

wuxx commented 2 years ago

the source code of debugger is here https://github.com/ARMmbed/DAPLink , already used with many boards, my experience is pretty stable.

openconcerto commented 2 years ago

Some good and bad news.

Bad news :

Good news :

My conclusions :

Thank you for your tests that guided quest of finding a solution.

wuxx commented 2 years ago

ok... maybe a logic analyzer is needed for get the truth, actually the max frequence of SWD clock is about 3MHz on this DAPLink.

wuxx commented 2 years ago

document will update, thanks.

kpishere commented 2 years ago

Hah! Looked this over, found a blog that went on an on about checking the wiring. .... It was the wiring for me. Maybe for you too? A loose dupont connector on ground.

mjcross commented 1 year ago

Mac mini and PicoProbe v.1.0.2 needed adapter speed 1000 (but also seems to work with anything up to 5000). For people using VSCode, instead of modifying tcl/interface/cmsis-dap.cfg it's probably better to use OpenOCDLaunchCommands in your .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            ... other commands ...
            "openOCDLaunchCommands": [
                "adapter speed 3000"
            ],
            ... other commands ...
          }
    ]
}