$npx -y skills add easyzoom/aix-skills --skill openocd-jlink-stlink-debugUse when debugging OpenOCD, J-Link, ST-Link, CMSIS-DAP, probe connection, reset scripts, flash algorithms, GDB attach, semihosting, RTT, or SWD/JTAG failures
| 1 | # OpenOCD J-Link ST-Link Debug |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to debug probe sessions by separating physical wiring, probe |
| 6 | firmware, target voltage, reset strategy, transport, target script, flash |
| 7 | algorithm, and GDB behavior. Probe failures are often reset or adapter issues. |
| 8 | |
| 9 | ## When To Use |
| 10 | |
| 11 | Use this skill when: |
| 12 | |
| 13 | - The user cannot connect, halt, reset, flash, erase, verify, or attach with |
| 14 | OpenOCD, J-Link, ST-Link, CMSIS-DAP, pyOCD, or GDB. |
| 15 | - The issue involves SWD/JTAG wiring, adapter speed, reset config, target |
| 16 | scripts, flash loaders, protected devices, semihosting, RTT, or multicore. |
| 17 | - The same firmware behaves differently under debugger and standalone boot. |
| 18 | |
| 19 | Do not use this skill for application fault analysis after a stable debug |
| 20 | session exists. Use the architecture-specific debug skill then. For flash |
| 21 | download failures focused on erase/program/verify, use `mcu-flashing-debug`. |
| 22 | |
| 23 | ## First Questions |
| 24 | |
| 25 | Ask for: |
| 26 | |
| 27 | - Probe model, firmware version, debugger tool, target MCU/SoC, board, and OS. |
| 28 | - Wiring: `VTref`, GND, `SWDIO`/`TMS`, `SWCLK`/`TCK`, `nRST`/`SRST`, `SWO`, and |
| 29 | power ownership. |
| 30 | - Exact command, the `-f interface/*.cfg` and `-f target/*.cfg` scripts, |
| 31 | `adapter speed`, `transport select`, and full log. |
| 32 | - Reset mode, boot pins, readout protection (STM32 `RDP`), low-power state, and |
| 33 | external flash. |
| 34 | - Whether connect-under-reset, halt-after-reset, or attach-to-running is needed. |
| 35 | |
| 36 | ## Launch Reference |
| 37 | |
| 38 | - ST-Link: `openocd -f interface/stlink.cfg -f target/stm32f4x.cfg` |
| 39 | (`stlink.cfg` is the `hla` driver; use `target/stm32f1x.cfg`, |
| 40 | `stm32h7x.cfg`, `nrf52.cfg` etc. for other parts). |
| 41 | - J-Link: `openocd -f interface/jlink.cfg -c "transport select swd" -f target/stm32f4x.cfg`. |
| 42 | - CMSIS-DAP/DAPLink: `openocd -f interface/cmsis-dap.cfg -c "transport select swd" -f target/stm32f1x.cfg`. |
| 43 | - Force JTAG instead of SWD: `-c "transport select jtag"` (note `stlink.cfg` |
| 44 | `hla` only supports `hla_swd`/`hla_jtag`). |
| 45 | - Set speed before target script: `-c "adapter speed 1000"` (kHz; deprecated |
| 46 | alias `adapter_khz`). Pick a probe by serial with `-c "adapter serial <SN>"` |
| 47 | (older: `hla_serial`). |
| 48 | - Default TCP ports: GDB `3333`, Telnet monitor `4444`, Tcl `6666`. |
| 49 | |
| 50 | ## Debug Workflow |
| 51 | |
| 52 | 1. Prove physical connection. |
| 53 | Check `VTref`, ground, cable length, pinout, `SRST` line, and whether the |
| 54 | probe powers or only senses the target. In the log confirm a valid |
| 55 | `SWD DPIDR 0x2ba01477` (Cortex-M3/M4) or JTAG `IDCODE`, not a zero/failed |
| 56 | read (`SWD DPIDR 0x00000000` / `Error connecting DP: cannot read IDR`). |
| 57 | |
| 58 | 1. Lower the adapter speed. |
| 59 | Start with `adapter speed 480` or lower, then raise only after IDCODE, halt, |
| 60 | reset, and `mdw` reads are stable. |
| 61 | |
| 62 | 1. Pick the right reset strategy. |
| 63 | In the target/board cfg set `reset_config`, e.g. `srst_only srst_nogate` |
| 64 | for connect-under-reset, or `none separate`. Then use |
| 65 | `reset halt` / `reset init` / `reset run`. Add `-c "reset_config |
| 66 | connect_assert_srst"` for locked or fast-sleeping parts. |
| 67 | |
| 68 | 1. Validate target scripts. |
| 69 | Confirm `transport select`, chip family cfg, TAP/DAP IDs (`-expected-id` on |
| 70 | `jtag newtap`/`swj_newdap`, `-dp-id` for SWD multidrop), `flash bank`, and |
| 71 | `_TARGETNAME`/work-area RAM. List cores with `targets`. |
| 72 | |
| 73 | 1. Separate attach from flash. |
| 74 | Enter the monitor with `telnet localhost 4444`, then `init` and `reset halt`. |
| 75 | Read state with `targets`, `reg`, `mdw 0x08000000 4`, `mdh`, `mdb`; write with |
| 76 | `mww 0x40021000 0x01`. Only then flash: |
| 77 | `program firmware.elf verify reset` or |
| 78 | `flash write_image erase firmware.bin 0x08000000` / |
| 79 | `flash erase_sector 0 0 last` / `flash info 0`. `resume` to run, |
| 80 | `dump_image out.bin 0x08000000 0x10000` to read back. |
| 81 | |
| 82 | 1. Add extras last. |
| 83 | Enable `arm semihosting enable`, SWO/`tpiu`, or RTT only after the base debug |
| 84 | path is reliable (see RTT And Semihosting). |
| 85 | |
| 86 | ## GDB Attach |
| 87 | |
| 88 | ```text |
| 89 | arm-none-eabi-gdb firmware.elf |
| 90 | (gdb) target extended-remote localhost:3333 |
| 91 | (gdb) monitor reset halt |
| 92 | (gdb) load |
| 93 | (gdb) monitor reg |
| 94 | (gdb) continue |
| 95 | ``` |
| 96 | |
| 97 | Use `target remote` for a single-session attach, `target extended-remote` to |
| 98 | allow reconnect. `monitor <cmd>` forwards any OpenOCD command (e.g. |
| 99 | `monitor reset init`, `monitor flash write_image erase firmware.bin`). |
| 100 | |
| 101 | ## RTT And Semihosting |
| 102 | |
| 103 | - Semihosting: after halt run `arm semihosting enable` (optionally |
| 104 | `arm semihosting_fileio enable`); `printf`/`puts` output appears on the |
| 105 | OpenOCD console once the firmware links `libnosys`/semihosting stubs. |
| 106 | - RTT: `rtt setup 0x20000000 2048 "SEGGER RTT"` then `rtt start`; expose a |
| 107 | channel with `rtt server start 9090 0` and read it via |
| 108 | `telnet localhost 9090`. Use `rtt channels` to confirm the control block was |
| 109 | found. The ID string defaults to `"SEGGER RTT"`. |
| 110 | |
| 111 | ## Common Failures |
| 112 | |
| 113 | - `VTref` is missing, so `Error: target v |