Problem with uploading firmware.elf and init failed

Hi guys, I have a trouble, compiling program working pretty well but when i want upload compiled code to my device it returns error. I am using: STM32F103C8 (blue pill) and i tried with libopencm3-blink example. Thanks for help.
I couldn’t find solution on my problem or that one which i found, don’t work.

`Processing bluepill_f103c8 (platform: ststm32; framework: libopencm3; board: bluepill_f103c8)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: docs.platformio dot.org/page/boards/ststm32/bluepill_f103c8 dothtml
PLATFORM: ST STM32 6.1.0 > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:

  • framework-libopencm3 1.1.0
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.190707 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → bit dot ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\bluepill_f103c8\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.0% (used 0 bytes from 20480 bytes)
    Flash: [ ] 1.0% (used 684 bytes from 65536 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, dfu, jlink, mbed, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\bluepill_f103c8\firmware.elf
    xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs. dot html
    debug_level: 1

hla_swd
none separate

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

*** [upload] Error 1`

How is your Blue Pill board connected to your computer? Via USB, via ST-Link or both?

It is connected via USB (USART). Is it okay?

Currently, you are using the default upload method, i.e. ST-Link. See output:

CURRENT: upload_protocol = stlink

If you don’t have an ST-Link adapter, an alternative is to upload code via a USB-to-Serial adapter connected to pins A9 and A10. In order to do so, you need to change the jumpers to set the board to progamming mode and need to add a line to platformio.ini:

upload_tool = dfu

If you have neither an ST-Link adapter nor a USB-to-serial adapter, you will be out of luck. By default, the USB port is only used for powering the board. With the appropriate software, it can be used for software UART. There are even custom bootloaders that will allow to upload firmware via the USB port. But that’s not standard and I’m unsure if it works with any framework other than Arduino.

I strongly recommend to get an ST-Link adapter. It’s by far the fastest and easiest way to upload firmware. And it enables debugging.

Which one should I buy? V2 or V1? Can you link some legit offers? Thanks for help ;))

I don’t think the version matters. Both we will and so will an inexpensive Chinese clone that looks like so:

Hey, thanks for last quick help ;))
I have already bought ST-Link V2 and I have some new troubles. I tried to upload LIBOPENCM3-BLINK and this worked but I got 3 failed uploads and only one success. I would like to know what happens and if it will work in my own programs.

Processing disco_f407vg (platform: ststm32; framework: libopencm3; board: disco_f407vg)
-----------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 6.1.0 > ST STM32F4DISCOVERY
HARDWARE: STM32F407VGT6 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:

  • framework-libopencm3 1.1.0
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.190707 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\disco_f407vg\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.0% (used 0 bytes from 131072 bytes)
    Flash: [ ] 0.1% (used 752 bytes from 1048576 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, jlink, mbed, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\disco_f407vg\firmware.elf
    xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
    Licensed under GNU GPL v2
    For bug reports, read
    OpenOCD: Bug Reporting
    debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Warn : UNEXPECTED idcode: 0x1ba01477
Error: expected 1 of 1: 0x2ba01477
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1
=========================================================== [FAILED] Took 1.00 seconds ===========================================================

Processing disco_l152rb (platform: ststm32; framework: libopencm3; board: disco_l152rb)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 6.1.0 > ST STM32LDISCOVERY
HARDWARE: STM32L152RBT6 32MHz, 16KB RAM, 128KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:

  • framework-libopencm3 1.1.0
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.190707 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\disco_l152rb\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.0% (used 0 bytes from 16384 bytes)
    Flash: [ ] 0.5% (used 604 bytes from 131072 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, jlink, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\disco_l152rb\firmware.elf
    xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
    Licensed under GNU GPL v2
    For bug reports, read
    OpenOCD: Bug Reporting
    debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Warn : UNEXPECTED idcode: 0x1ba01477
Error: expected 1 of 1: 0x2ba01477
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1
=========================================================== [FAILED] Took 1.00 seconds ===========================================================

Processing disco f303vc (platform: ststm32; framework: libopencm3; board: disco_f303vc)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 6.1.0 > ST STM32F3DISCOVERY
HARDWARE: STM32F303VCT6 72MHz, 48KB RAM, 256KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:

  • framework-libopencm3 1.1.0
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.190707 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\disco f303vc\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.0% (used 0 bytes from 49152 bytes)
    Flash: [ ] 0.3% (used 712 bytes from 262144 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, jlink, mbed, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\disco f303vc\firmware.elf
    xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
    Licensed under GNU GPL v2
    For bug reports, read
    OpenOCD: Bug Reporting
    debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Warn : UNEXPECTED idcode: 0x1ba01477
Error: expected 1 of 1: 0x2ba01477
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1
=========================================================== [FAILED] Took 0.93 seconds ===========================================================

Processing genericSTM32F103C8 (platform: ststm32; framework: libopencm3; board: genericSTM32F103C8)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 6.1.0 > STM32F103C8 (20k RAM. 64k Flash)
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:

  • framework-libopencm3 1.1.0
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.190707 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 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: [ ] 0.0% (used 0 bytes from 20480 bytes)
    Flash: [ ] 1.0% (used 684 bytes from 65536 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, dfu, jlink, serial, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\genericSTM32F103C8\firmware.elf
    xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
    Licensed under GNU GPL v2
    For bug reports, read
    OpenOCD: Bug Reporting
    debug_level: 1

hla_swd
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800021c msp: 0x20005000
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
========================================================== [SUCCESS] Took 1.16 seconds ==========================================================

Environment Status Duration


disco_f407vg FAILED 00:00:00.1000
disco_l152rb FAILED 00:00:00.996
disco f303vc FAILED 00:00:00.928
genericSTM32F103C8 SUCCESS 00:00:01.161
===================================================== 3 failed, 1 succeeded in 00:00:04.085 =====================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Main problem looks like this:
Warn : UNEXPECTED idcode: 0x1ba01477
Error: expected 1 of 1: 0x2ba01477
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked


I don’t know what to do this. I tried change stm32f1x.cfg file but it made it worse.

btw. Is it normal in PlaformIO home in category devices i can’t see my st-link adapter?

[I am working on Win 10, my board is connected via ST-Link v2, bluepill]

Thanks!