While I wanted to upload/debug a new HAL Eclipse System Workbench for STM32 project on my STM32F103 it showed the following message:

OpenOCD child process termination

Wrong device detected


Wrong device detected
  Open On-Chip Debugger 0.10.0-dev-00302-gc211ca5-dirty (2017-07-03-10:41)
  Licensed under GNU GPL v2
  For bug reports, read
  none separate
  Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
  adapter speed: 950 kHz
  adapter_nsrst_delay: 100
  Info : clock speed 950 kHz
  Info : STLINK v2 JTAG v27 API v2 SWIM v6 VID 0x0483 PID 0x3748
  Info : vid/pid are not identical: 0x0483/0x374B 0x0483/0x3748
  Info : using stlink api v2
  Info : Target voltage: 3.236436
  Error: init mode failed (unable to connect to the target)
  in procedure 'init' 
  in procedure 'ocd_bouncer'

This happens regularly, what I normally do is startup up STLink utility, and select Target/connect. This shows sometimes an error:

Can not connect to target!
If you're trying to connect to an STMW1xx device, please select
Normal or HotPlug mode from Target->Settings menu.
If you're trying to connect a low frequency application, please select
a lower SWD Frequency mode from Target->Settings menu.

Since both do not apply, I remove the USB STLink stick (V2, cheap one) and USB for power to the STM and try again, mostly it works. I close the ST Link utility and continue with Eclipse. This takes normally a few minutes and is annoying, but at least I can continue.

However, now I keep getting the ST Link message and cannot get rid of it (also restarted my computer).

If I try ST-LINK/Firmware Update from the ST-Link utility (to check if I can get connection to the ST Link itself), and press Device Connect, I get:

ST-Link is not in the DFU mode.
Please restart it

I don't know how to 'restart' it, but removing the ST Link from the USB and reinserting does not help.

I also tried another ST-Link, but it has the same behavior.

Than I tried another STM32, that worked. However, as soon as I tried to upload the program via Eclipse, it works once, when retrying, I get the same problems as above and now I have both of my STM's not working anymore. The program is not special, and worked before.

How to restore the connection with Eclipse so I can upload programs for debugging again?


  • I tried to put BOOT0 to 1 (3V), I could get once connection with ST link, I erased it. I could even debug after uploading, but just once. Than the problems started as before.
  • Also, suddenly, the ST Link utility crashes when trying to connect.
  • When I put BOOT0 to 0 again, and keep pressing the reset button, select erase memory from the ST Link utility and release the reset button, I could erase it. This makes it possible again to upload a program via Eclipse. However, after the first initial breakpoint stepping further, I get continuous the following error:

    Error: JTAG failure: -4

  • 1
    \$\begingroup\$ Go to St-Link Utility, Target -> Settings and under Mode select Connect under reset, it helped me when I lost connection with my STM32F429I-DISCO. After that try to connect, if it works go CTRL+E (Erase chip), after it is done, close ST Utility, and try to download your program to ST device, it should work now. \$\endgroup\$
    – Laki
    Commented Sep 3, 2017 at 10:17
  • \$\begingroup\$ @Zola: good comment, however, that's already the current setting (I also needed to change this in order to get it working before). Also, Reset Mode is in Hardware Reset mode (but afaik this is default), SWD is on 4.0 MHz. \$\endgroup\$ Commented Sep 3, 2017 at 10:22

2 Answers 2


It seems that in the HAL project the SYS / Debug was not set to Serial Wire (this is not default).

However, the first time it was possible to debug, but not afterwards anymore. The reason is that the JTAG/SWDIO is disabled during the application. When it is disabled, even a connection is hard to make.

What worked:

  • Set BOOT0 to 1
  • Keep Reset button pressed
  • Remove / Erase Chip
  • Restart debugging

I faced exactly same problem.This happens because jtag is disabled inside the code we generate from CubeMX software. Solution: remove the blow lines inside stm32f1xx_hal_msp.c file : __HAL_AFIO_REMAP_SWJ_DISABLE();

  • \$\begingroup\$ So far I always set the debugger option to 'connection under reset', or away from it (don't have the tool here) and works fine too. But very occasionally I need to perform the steps from my answer. I will check yours too next time I can't get connection. \$\endgroup\$ Commented Jul 20, 2018 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.