Stm32 OpenOCD init failed STM32F103RCT6

I have STM32F103RCT6

STM32F103RCT6 connect to st-link v2 jtag

platformio.ini:

[env:genericSTM32F103RC]
platform = ststm32
board = genericSTM32F103RC
framework = stm32cube
lib_ldf_mode = chain+ 
build_flags = 
    -IInc
    -IMiddlewares/Third_Party/FatFs/src/drivers
    -Og 
    -ggdb
    -DCORE_DEBUG_LEVEL=1
build_unflags = -Os

lib_deps = 
    Middlewares/Third_Party/FatFs

upload_protocol = stlink ;-jtag

result:

Uploading .pio\build\genericSTM32F103RC\firmware.elf
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
debug_level: 1

hla_swd
Error: open failed
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1

What could be the reason?
The download succeeds in the arduinoIDE. So the problem isn’t the board.
I made a pio update, it didn’t help.

1 Like

How is your board connected to your computer? With a USB cable only? Or do you additionally have a USB-to-serial converter or an ST-Link adapter?

The default upload method for the chosen board is st-link. But the error message indicates that you probably don’t have an ST-Link adapter connected.

What upload method have you used with the Arduino IDE?

Sure you’ve installed STSW-LINK009 - ST-LINK, ST-LINK/V2, ST-LINK/V2-1, STLINK-V3 USB driver signed for Windows7, Windows8, Windows10 - STMicroelectronics for the driver?

My programmer st-link v2 jtag - connect.

ArduinoIDE:
изображение

The connection is:
USB cable - > st-link 2 - jtag - > ribbon cable - > STM32.
Also powered for STM32: USB - > STM32

This ^ ^ ^ option works in ArduinoIDE.

Drivers are installed. Programmable in ArduinoIDE. Defined as COM port.

Ok that looks good.

Still, OpenOCD isn’t able to open the STLink adapter.

Can you connect to the target chip with the ST-Link Utility tool that I’ve posted above? Should look like

if it works.

I’m assuming you are using Windows to run PlatformIO.

OpenOCD (used by PlatformIO) uses the WinUSB interface to access the ST-Link while the STM32 Cube Programmer (used by the Arduino IDE) might possibly use custom STM drivers. So drivers could be a problem.

Can you install Zadig (https://zadig.akeo.ie/), check List All Devices in the Options menu and then select the STM32 STLink from the main drop-down.

  • Does it appear once as “STM32 STLink” or twice as “STM32 STLink (Interface x)”?
  • What is the USB ID? Is it 0483-3748?
  • What is the driver (left gray text field, not the white text field) for it or for the two of them?

ST-Link Utility tool:

and Zadig:
2021-02-23_153430

Did I do it right?
Maybe something needs to be updated?

It all looks ok.

Are you still getting the same error:

hla_swd
Error: open failed

If so, have you made sure that all other tools accessing the ST-Link are closed (ST-Link Utility, any serial monitor etc.)?

The only time I’ve seen this situation where it works in one tool but not another is when the drivers are outdated.

Yes. All utilities and programs are closed.

I removed the drivers and programs and installed the stm32cubeprog package.

It didn’t help.

Can I make in platformio as in arduino? (OCD to STM32 Cube Programmer)

What exactly do you mean? Use the STM32 command line tools to upload the firmware (Arduino IDE approach) instead of OpenOCD (PlatformIO approach)?

I had an issue similar to this. Turns out that openocd can run into issues when not run as root. To be able to run as root, adding a udev rules file seemed to solve the problem for me

https://forgge.github.io/theCore/guides/running-openocd-without-sudo.html