Start OpenOCD with interface and target scripts using -f
Start OpenOCD 0.12 with an adapter script and a target script, as -f interface/stlink.cfg -f target/stm32f4x.cfg, and read what its startup log tells you.
OpenOCD knows nothing about your hardware until you give it two scripts: one for the debug adapter and one for the chip. Each -f option runs a configuration file, searched in the install's scripts folder, and order matters because the target script expects the adapter to be selected already. This is the invocation from the OpenOCD manual's configuration chapter for a Nucleo or Discovery board with an on-board ST-LINK.
openocd -f interface/stlink.cfg -f target/stm32f4x.cfgOpen On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : STLINK V2J37S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.250000
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connectionsThree lines are worth reading each time. The target voltage proves the board is powered and the probe sees it. The processor line proves the SWD link reached the core. The last line gives the port GDB will use. If you see Error: init mode failed (unable to connect to the target), the usual causes are a wrong target script, no power or a chip stuck in a low-power state.
Version, serial number and voltage differ per setup. Use -c "init; reset halt" after the scripts to run a command at startup, and -c "shutdown" to run one-shot scripts.