PlatformIO Community

OpenOCD init failed for STM32F103C8 in CLion

I am trying to run simple sketch on STM32F103C8 board in CLion IDE on MAC. I am using USB only and got:

/Users/ton/.platformio/penv/bin/platformio -c clion run --target upload -e genericSTM32F103C8
Processing genericSTM32F103C8 (platform: ststm32; board: genericSTM32F103C8; framework: arduino)

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103C8.html
PLATFORM: ST STM32 (15.4.1) > STM32F103C8 (20k RAM. 64k Flash)
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 @ 4.20200.220530 (2.2.0) 
 - framework-cmsis @ 2.50700.210515 (5.7.0) 
 - tool-dfuutil @ 1.11.0 
 - tool-openocd @ 2.1100.211028 (11.0) 
 - tool-stm32duino @ 1.0.1 
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio/build/genericSTM32F103C8/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.0% (used 828 bytes from 20480 bytes)
Flash: [==        ]  18.8% (used 12296 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio/build/genericSTM32F103C8/firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-17-00:18)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

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

*** [upload] Error 1
 [FAILED] Took 8.42 seconds 

Process finished with exit code 1

Looks like I need STLink, but is it possible to configure without it?

So you don’t actually have a ST-Link connected to your board?

Did you previously upload to the board via the USB DFU method? (Which is only possible if it has the Maple USB bootloader on it).

Otherwise you can use the upload_protocol = serial method with an external USB-serial adapter on the USART pins and the device in bootloader mode (boot0 pin setting). See ST Community and https://www.st.com/resource/en/application_note/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf page 77.