PlatformIO Community

Error while uploading to L475 IoT Discovery

Hello, I’m having trouble uploading even the simplest code to L475 IoT Discovery. A few months ago I was working on some project and everything worked well, even debugging. Today I tried to upload without success.

Indexing .pio\build\disco_l475vg_iot01a\libFrameworkArduino.a
Linking .pio\build\disco_l475vg_iot01a\firmware.elf
Checking size .pio\build\disco_l475vg_iot01a\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.9% (used 868 bytes from 98304 bytes)
Flash: [          ]   1.4% (used 14856 bytes from 1048576 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\disco_l475vg_iot01a\firmware.elf
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

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

*** [upload] Error 1

This is the error I’m getting.

[env:disco_l475vg_iot01a]

platform = ststm32

board = disco_l475vg_iot01a

framework = arduino

This is my platformio.ini

#include <Arduino.h>

void setup()

{

  Serial.begin(9600);

}

void loop()

{

  Serial.println("abc");

  delay(5000);

}

And this is my code.

image

I also tried to reinstall STLink v2 drivers and I guess they installed correctly.

Thanks for any help, because I’m trying to solve this for a few hours now without success. :slightly_smiling_face:

Can you connect to it using STM32CubeProgrammer?

Is the power LED on the board on?

Does it make a difference if you hold the reset button before OpenOCD starts, then release it after the first few lines of OpenOCD output appear?

image

Yes, I can connect with STM32CubeProgrammer, also the power led is on and the led near the USB connector is red, which is good as I remember from ST documentation. Holding the reset button doesn’t make any difference, output from platformio stays the same all the time.

I see 2 possibilities:

  • OpenOCD cannot access the STLink but STM32Programmer can – though unlikely if you’ve cleanly uninstalled the old drivers and installed the current ones through e.g. STM32Programmer or ST-Util
  • PlatformIO gives OpenOCD the wrong reset flags and thus it can’t connect to the chip via SWD.

One more thing: If you erase the flash in STM32CubeProgrammer, does it work thereafter in PlatformIO?

I happen to have the same board and will see what PlatformIO does with it.

I have done full chip erase with STM32CubeProgrammer and after reading memory it’s all FFFF… But platformio still gives the same error. I think it doesn’t even try to program the board because it gives this error straight away after compiling. When I am connecting with STM32CubeProgrammer as soon as I press the “Connect” button the led near the USB port starts blinking red/green and when I try to upload from platformio, not even a single flash.

Can you adapt these commands to your correct username and execute them?

C:\Users\USER\.platformio\packages\tool-openocd\bin\openocd -d2 -s C:\Users\USER\.platformio\packages\tool-openocd/scripts -f board/stm32l4discovery.cfg

(if execution hangs, Ctrl+C after it)

and

C:\Users\USER\.platformio\packages\tool-openocd\bin\openocd -d3 -s C:\Users\USER\.platformio\packages\tool-openocd/scripts -f board/stm32l4discovery.cfg

If OpenOCD can’t find a ST-Link to connect it, it shows up as

Debug: 139 385 stlink_usb.c:2819 stlink_usb_open(): stlink_usb_open
Debug: 140 385 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3744 serial:
Debug: 141 385 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3748 serial:
Debug: 142 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374b serial:
Debug: 143 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374d serial:
Debug: 144 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374e serial:
Debug: 145 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374f serial:
Debug: 146 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3752 serial:
Debug: 147 417 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3753 serial:
Error: 148 432 stlink_usb.c:2848 stlink_usb_open(): open failed

if it can’t connect to the microcontroller through an opened ST-Link, it’ll look different.

Info : 148 438 stlink_usb.c:1098 stlink_usb_version(): STLINK V2J37S7 (API v2) VID:PID 0483:3748
Debug: 149 438 stlink_usb.c:1323 stlink_usb_exit_mode(): MODE: 0x00
Info : 150 501 stlink_usb.c:1134 stlink_usb_check_voltage(): Target voltage: 3.253616
Debug: 151 501 stlink_usb.c:1391 stlink_usb_init_mode(): MODE: 0x01
Debug: 152 501 stlink_usb.c:2606 stlink_dump_speed_map(): Supported clock speeds are:
Debug: 153 501 stlink_usb.c:2609 stlink_dump_speed_map(): 4000 kHz
..
Debug: 165 538 stlink_usb.c:748 stlink_usb_error_check(): STLINK_JTAG_GET_IDCODE_ERROR
Error: 166 538 stlink_usb.c:2959 stlink_usb_open(): init mode failed (unable to connect to the target)

That should show where it failed.

Out of first

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 500 kHz
Error: open failed

Out of second

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
User : 13 2 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 10 options.c:63 configuration_output_handler():
Debug: 15 11 configuration.c:42 add_script_search_dir(): adding C:\Users\kcholody\.platformio\packages\tool-openocd/scripts
Debug: 16 15 options.c:244 add_default_dirs(): bindir=bin
Debug: 17 17 options.c:245 add_default_dirs(): pkgdatadir=
Debug: 18 19 options.c:246 add_default_dirs(): exepath=C:/Users/kcholody/.platformio/packages/tool-openocd/bin
Debug: 19 24 options.c:247 add_default_dirs(): bin2data=../
Debug: 20 26 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholodyadm/AppData/Roaming/OpenOCD
Debug: 21 29 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholody/.platformio/packages/tool-openocd/bin/..//site
Debug: 22 33 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholody/.platformio/packages/tool-openocd/bin/..//scripts
Debug: 23 38 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/board/stm32l4discovery.cfg
Debug: 24 43 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/interface/stlink.cfg
Debug: 25 47 command.c:146 script_debug(): command - adapter driver hla
Debug: 27 49 command.c:146 script_debug(): command - hla_layout stlink
Debug: 29 52 hla_interface.c:242 hl_interface_handle_layout_command(): hl_interface_handle_layout_command
Debug: 30 55 command.c:146 script_debug(): command - hla_device_desc ST-LINK
Debug: 32 57 hla_interface.c:216 hl_interface_handle_device_desc_command(): hl_interface_handle_device_desc_command
Debug: 33 61 command.c:146 script_debug(): command - hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753
Debug: 35 65 command.c:146 script_debug(): command - transport select hla_swd
Debug: 36 70 hla_transport.c:205 hl_swd_transport_select(): hl_swd_transport_select
Debug: 37 73 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/target/stm32l4x.cfg
Debug: 38 77 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/target/swj-dp.tcl
Debug: 39 81 command.c:146 script_debug(): command - transport select
Debug: 40 84 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/mem_helper.tcl
Debug: 41 87 command.c:146 script_debug(): command - add_usage_text mrw address
Debug: 43 89 command.c:1115 help_add_command(): added 'mrw' help text
Debug: 44 91 command.c:146 script_debug(): command - add_help_text mrw Returns value of word in memory.
Debug: 46 94 command.c:1128 help_add_command(): added 'mrw' help text
Debug: 47 96 command.c:146 script_debug(): command - add_usage_text mrh address
Debug: 49 98 command.c:1115 help_add_command(): added 'mrh' help text
Debug: 50 102 command.c:146 script_debug(): command - add_help_text mrh Returns value of halfword in memory.
Debug: 52 106 command.c:1128 help_add_command(): added 'mrh' help text
Debug: 53 108 command.c:146 script_debug(): command - add_usage_text mrb address
Debug: 55 111 command.c:1115 help_add_command(): added 'mrb' help text
Debug: 56 113 command.c:146 script_debug(): command - add_help_text mrb Returns value of byte in memory.
Debug: 58 120 command.c:1128 help_add_command(): added 'mrb' help text
Debug: 59 123 command.c:146 script_debug(): command - add_usage_text mmw address setbits clearbits
Debug: 61 126 command.c:1115 help_add_command(): added 'mmw' help text
Debug: 62 129 command.c:146 script_debug(): command - add_help_text mmw Modify word in memory. new_val = (old_val & ~clearbits) | setbits;
Debug: 64 135 command.c:1128 help_add_command(): added 'mmw' help text
Debug: 65 138 command.c:146 script_debug(): command - transport select
Debug: 66 140 command.c:146 script_debug(): command - transport select
Debug: 67 142 command.c:146 script_debug(): command - transport select
Debug: 68 144 command.c:146 script_debug(): command - swd newdap stm32l4x cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x2ba01477
Debug: 69 149 hla_tcl.c:110 jim_hl_newtap_cmd(): Creating New Tap, Chip: stm32l4x, Tap: cpu, Dotted: stm32l4x.cpu, 8 params
Debug: 70 154 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -irlen
Debug: 71 157 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -ircapture
Debug: 72 159 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -irmask
Debug: 73 161 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -expected-id
Debug: 74 164 core.c:1484 jtag_tap_init(): Created Tap: stm32l4x.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 75 169 command.c:146 script_debug(): command - dap create stm32l4x.dap -chain-position stm32l4x.cpu
Debug: 76 172 command.c:146 script_debug(): command - transport select
Debug: 77 174 command.c:146 script_debug(): command - target create stm32l4x.cpu cortex_m -endian little -dap stm32l4x.dap
Info : 78 179 target.c:5668 target_create(): The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Debug: 79 184 hla_target.c:203 adapter_target_create(): adapter_target_create
Debug: 80 187 hla_target.c:173 adapter_init_arch_info(): adapter_init_arch_info
Debug: 81 190 command.c:375 register_command(): command 'rtt' is already registered in '<global>' context
Debug: 82 195 command.c:146 script_debug(): command - stm32l4x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x8000 -work-area-backup 0
Debug: 83 199 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 84 202 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 85 205 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 86 207 command.c:146 script_debug(): command - flash bank stm32l4x.flash stm32l4x 0 0 0 0 stm32l4x.cpu
Debug: 88 211 tcl.c:1319 handle_flash_bank_command(): 'stm32l4x' driver usage field missing
Debug: 89 213 command.c:146 script_debug(): command - adapter speed 500
Debug: 91 216 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 92 218 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 93 221 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 94 224 command.c:146 script_debug(): command - adapter srst delay 100
Debug: 96 226 command.c:146 script_debug(): command - transport select
Debug: 97 229 command.c:146 script_debug(): command - reset_config srst_nogate
Debug: 99 231 command.c:146 script_debug(): command - transport select
Debug: 100 234 command.c:146 script_debug(): command - stm32l4x.cpu configure -event reset-init
        # CPU comes out of reset with MSI_ON | MSI_RDY | MSI Range 6 (4 MHz).
        # Use MSI 24 MHz clock, compliant even with VOS == 2.
        # 3 WS compliant with VOS == 2 and 24 MHz.
        mww 0x40022000 0x00000103   ;# FLASH_ACR = PRFTBE | 3(Latency)
        mww 0x40021000 0x00000099   ;# RCC_CR = MSI_ON | MSIRGSEL | MSI Range 9
        # Boost JTAG frequency
        adapter speed 4000

Debug: 101 248 command.c:146 script_debug(): command - stm32l4x.cpu configure -event reset-start
        # Reset clock is MSI (4 MHz)
        adapter speed 500

Debug: 102 254 command.c:146 script_debug(): command - stm32l4x.cpu configure -event examine-end
        # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
        mmw 0xE0042004 0x00000007 0

        # Stop watchdog counters during halt
        # DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
        mmw 0xE0042008 0x00001800 0

Debug: 103 265 command.c:146 script_debug(): command - stm32l4x.cpu configure -event trace-config
        # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
        # change this value accordingly to configure trace pins
        # assignment
        mmw 0xE0042004 0x00000020 0

Debug: 104 275 command.c:146 script_debug(): command - reset_config srst_only
User : 106 277 options.c:63 configuration_output_handler(): srst_only separate srst_nogate srst_open_drain connect_deassert_srst
User : 107 281 options.c:63 configuration_output_handler():
Info : 108 284 server.c:311 add_service(): Listening on port 6666 for tcl connections
Info : 109 287 server.c:311 add_service(): Listening on port 4444 for telnet connections
Debug: 110 290 command.c:146 script_debug(): command - init
Debug: 112 292 command.c:146 script_debug(): command - target init
Debug: 114 294 command.c:146 script_debug(): command - target names
Debug: 115 296 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-flash-erase-start
Debug: 116 299 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-flash-erase-start reset init
Debug: 117 304 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-flash-write-end
Debug: 118 307 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-flash-write-end reset halt
Debug: 119 310 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-attach
Debug: 120 313 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-attach halt 1000
Debug: 121 316 target.c:1639 handle_target_init_command(): Initializing targets...
Debug: 122 319 hla_target.c:193 adapter_init_target(): adapter_init_target
Debug: 123 321 semihosting_common.c:99 semihosting_common_init():
Debug: 124 324 hla_interface.c:109 hl_interface_init(): hl_interface_init
Debug: 125 326 hla_layout.c:95 hl_layout_init(): hl_layout_init
Debug: 126 328 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 127 331 core.c:1789 adapter_khz_to_speed(): have interface set up
Debug: 128 333 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 129 337 core.c:1789 adapter_khz_to_speed(): have interface set up
Info : 130 339 core.c:1565 adapter_init(): clock speed 500 kHz
Debug: 131 341 openocd.c:159 handle_init_command(): Debug Adapter init complete
Debug: 132 343 command.c:146 script_debug(): command - transport init
Debug: 134 345 transport.c:229 handle_transport_init(): handle_transport_init
Debug: 135 347 hla_transport.c:156 hl_transport_init(): hl_transport_init
Debug: 136 350 hla_transport.c:173 hl_transport_init(): current transport hla_swd
Debug: 137 353 hla_interface.c:42 hl_interface_open(): hl_interface_open
Debug: 138 355 hla_layout.c:40 hl_layout_open(): hl_layout_open
Debug: 139 357 stlink_usb.c:2819 stlink_usb_open(): stlink_usb_open
Debug: 140 359 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3744 serial:
Debug: 141 362 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3748 serial:
Debug: 142 364 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374b serial:
Debug: 143 369 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374d serial:
Debug: 144 372 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374e serial:
Debug: 145 374 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374f serial:
Debug: 146 377 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3752 serial:
Debug: 147 380 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3753 serial:
Error: 148 404 stlink_usb.c:2848 stlink_usb_open(): open failed
Debug: 149 407 hla_layout.c:47 hl_layout_open(): failed
Debug: 150 408 command.c:628 run_command(): Command 'transport init' failed with error code -4
User : 151 411 command.c:694 command_run_line():
Debug: 152 413 command.c:628 run_command(): Command 'init' failed with error code -4
User : 153 416 command.c:694 command_run_line():
Debug: 154 418 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 155 421 hla_interface.c:117 hl_interface_quit(): hl_interface_quit

And with open connection with STM32CubeProgrammer first

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 500 kHz
Error: open failed

And second

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
User : 13 8 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 12 options.c:63 configuration_output_handler():
Debug: 15 14 configuration.c:42 add_script_search_dir(): adding C:\Users\kcholody\.platformio\packages\tool-openocd/scripts
Debug: 16 17 options.c:244 add_default_dirs(): bindir=bin
Debug: 17 20 options.c:245 add_default_dirs(): pkgdatadir=
Debug: 18 23 options.c:246 add_default_dirs(): exepath=C:/Users/kcholody/.platformio/packages/tool-openocd/bin
Debug: 19 27 options.c:247 add_default_dirs(): bin2data=../
Debug: 20 28 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholodyadm/AppData/Roaming/OpenOCD
Debug: 21 31 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholody/.platformio/packages/tool-openocd/bin/..//site
Debug: 22 37 configuration.c:42 add_script_search_dir(): adding C:/Users/kcholody/.platformio/packages/tool-openocd/bin/..//scripts
Debug: 23 41 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/board/stm32l4discovery.cfg
Debug: 24 45 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/interface/stlink.cfg
Debug: 25 51 command.c:146 script_debug(): command - adapter driver hla
Debug: 27 54 command.c:146 script_debug(): command - hla_layout stlink
Debug: 29 59 hla_interface.c:242 hl_interface_handle_layout_command(): hl_interface_handle_layout_command
Debug: 30 63 command.c:146 script_debug(): command - hla_device_desc ST-LINK
Debug: 32 67 hla_interface.c:216 hl_interface_handle_device_desc_command(): hl_interface_handle_device_desc_command
Debug: 33 72 command.c:146 script_debug(): command - hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753
Debug: 35 77 command.c:146 script_debug(): command - transport select hla_swd
Debug: 36 79 hla_transport.c:205 hl_swd_transport_select(): hl_swd_transport_select
Debug: 37 82 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/target/stm32l4x.cfg
Debug: 38 89 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/target/swj-dp.tcl
Debug: 39 93 command.c:146 script_debug(): command - transport select
Debug: 40 94 configuration.c:97 find_file(): found C:\Users\kcholody\.platformio\packages\tool-openocd/scripts/mem_helper.tcl
Debug: 41 98 command.c:146 script_debug(): command - add_usage_text mrw address
Debug: 43 100 command.c:1115 help_add_command(): added 'mrw' help text
Debug: 44 103 command.c:146 script_debug(): command - add_help_text mrw Returns value of word in memory.
Debug: 46 107 command.c:1128 help_add_command(): added 'mrw' help text
Debug: 47 109 command.c:146 script_debug(): command - add_usage_text mrh address
Debug: 49 112 command.c:1115 help_add_command(): added 'mrh' help text
Debug: 50 115 command.c:146 script_debug(): command - add_help_text mrh Returns value of halfword in memory.
Debug: 52 119 command.c:1128 help_add_command(): added 'mrh' help text
Debug: 53 123 command.c:146 script_debug(): command - add_usage_text mrb address
Debug: 55 126 command.c:1115 help_add_command(): added 'mrb' help text
Debug: 56 127 command.c:146 script_debug(): command - add_help_text mrb Returns value of byte in memory.
Debug: 58 131 command.c:1128 help_add_command(): added 'mrb' help text
Debug: 59 133 command.c:146 script_debug(): command - add_usage_text mmw address setbits clearbits
Debug: 61 135 command.c:1115 help_add_command(): added 'mmw' help text
Debug: 62 140 command.c:146 script_debug(): command - add_help_text mmw Modify word in memory. new_val = (old_val & ~clearbits) | setbits;
Debug: 64 147 command.c:1128 help_add_command(): added 'mmw' help text
Debug: 65 149 command.c:146 script_debug(): command - transport select
Debug: 66 153 command.c:146 script_debug(): command - transport select
Debug: 67 160 command.c:146 script_debug(): command - transport select
Debug: 68 163 command.c:146 script_debug(): command - swd newdap stm32l4x cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x2ba01477
Debug: 69 166 hla_tcl.c:110 jim_hl_newtap_cmd(): Creating New Tap, Chip: stm32l4x, Tap: cpu, Dotted: stm32l4x.cpu, 8 params
Debug: 70 171 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -irlen
Debug: 71 173 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -ircapture
Debug: 72 176 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -irmask
Debug: 73 178 hla_tcl.c:121 jim_hl_newtap_cmd(): Processing option: -expected-id
Debug: 74 181 core.c:1484 jtag_tap_init(): Created Tap: stm32l4x.cpu @ abs position 0, irlen 0, capture: 0x0 mask: 0x0
Debug: 75 184 command.c:146 script_debug(): command - dap create stm32l4x.dap -chain-position stm32l4x.cpu
Debug: 76 189 command.c:146 script_debug(): command - transport select
Debug: 77 192 command.c:146 script_debug(): command - target create stm32l4x.cpu cortex_m -endian little -dap stm32l4x.dap
Info : 78 196 target.c:5668 target_create(): The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Debug: 79 201 hla_target.c:203 adapter_target_create(): adapter_target_create
Debug: 80 206 hla_target.c:173 adapter_init_arch_info(): adapter_init_arch_info
Debug: 81 209 command.c:375 register_command(): command 'rtt' is already registered in '<global>' context
Debug: 82 212 command.c:146 script_debug(): command - stm32l4x.cpu configure -work-area-phys 0x20000000 -work-area-size 0x8000 -work-area-backup 0
Debug: 83 216 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 84 219 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 85 222 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 86 226 command.c:146 script_debug(): command - flash bank stm32l4x.flash stm32l4x 0 0 0 0 stm32l4x.cpu
Debug: 88 229 tcl.c:1319 handle_flash_bank_command(): 'stm32l4x' driver usage field missing
Debug: 89 231 command.c:146 script_debug(): command - adapter speed 500
Debug: 91 233 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 92 235 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 93 240 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 94 243 command.c:146 script_debug(): command - adapter srst delay 100
Debug: 96 246 command.c:146 script_debug(): command - transport select
Debug: 97 248 command.c:146 script_debug(): command - reset_config srst_nogate
Debug: 99 250 command.c:146 script_debug(): command - transport select
Debug: 100 252 command.c:146 script_debug(): command - stm32l4x.cpu configure -event reset-init
        # CPU comes out of reset with MSI_ON | MSI_RDY | MSI Range 6 (4 MHz).
        # Use MSI 24 MHz clock, compliant even with VOS == 2.
        # 3 WS compliant with VOS == 2 and 24 MHz.
        mww 0x40022000 0x00000103   ;# FLASH_ACR = PRFTBE | 3(Latency)
        mww 0x40021000 0x00000099   ;# RCC_CR = MSI_ON | MSIRGSEL | MSI Range 9
        # Boost JTAG frequency
        adapter speed 4000

Debug: 101 267 command.c:146 script_debug(): command - stm32l4x.cpu configure -event reset-start
        # Reset clock is MSI (4 MHz)
        adapter speed 500

Debug: 102 274 command.c:146 script_debug(): command - stm32l4x.cpu configure -event examine-end
        # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
        mmw 0xE0042004 0x00000007 0

        # Stop watchdog counters during halt
        # DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
        mmw 0xE0042008 0x00001800 0

Debug: 103 283 command.c:146 script_debug(): command - stm32l4x.cpu configure -event trace-config
        # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
        # change this value accordingly to configure trace pins
        # assignment
        mmw 0xE0042004 0x00000020 0

Debug: 104 293 command.c:146 script_debug(): command - reset_config srst_only
User : 106 295 options.c:63 configuration_output_handler(): srst_only separate srst_nogate srst_open_drain connect_deassert_srst
User : 107 299 options.c:63 configuration_output_handler():
Info : 108 302 server.c:311 add_service(): Listening on port 6666 for tcl connections
Info : 109 307 server.c:311 add_service(): Listening on port 4444 for telnet connections
Debug: 110 309 command.c:146 script_debug(): command - init
Debug: 112 311 command.c:146 script_debug(): command - target init
Debug: 114 313 command.c:146 script_debug(): command - target names
Debug: 115 315 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-flash-erase-start
Debug: 116 317 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-flash-erase-start reset init
Debug: 117 322 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-flash-write-end
Debug: 118 325 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-flash-write-end reset halt
Debug: 119 328 command.c:146 script_debug(): command - stm32l4x.cpu cget -event gdb-attach
Debug: 120 330 command.c:146 script_debug(): command - stm32l4x.cpu configure -event gdb-attach halt 1000
Debug: 121 333 target.c:1639 handle_target_init_command(): Initializing targets...
Debug: 122 339 hla_target.c:193 adapter_init_target(): adapter_init_target
Debug: 123 342 semihosting_common.c:99 semihosting_common_init():
Debug: 124 344 hla_interface.c:109 hl_interface_init(): hl_interface_init
Debug: 125 346 hla_layout.c:95 hl_layout_init(): hl_layout_init
Debug: 126 348 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 127 352 core.c:1789 adapter_khz_to_speed(): have interface set up
Debug: 128 357 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 129 360 core.c:1789 adapter_khz_to_speed(): have interface set up
Info : 130 364 core.c:1565 adapter_init(): clock speed 500 kHz
Debug: 131 366 openocd.c:159 handle_init_command(): Debug Adapter init complete
Debug: 132 369 command.c:146 script_debug(): command - transport init
Debug: 134 373 transport.c:229 handle_transport_init(): handle_transport_init
Debug: 135 376 hla_transport.c:156 hl_transport_init(): hl_transport_init
Debug: 136 378 hla_transport.c:173 hl_transport_init(): current transport hla_swd
Debug: 137 381 hla_interface.c:42 hl_interface_open(): hl_interface_open
Debug: 138 383 hla_layout.c:40 hl_layout_open(): hl_layout_open
Debug: 139 386 stlink_usb.c:2819 stlink_usb_open(): stlink_usb_open
Debug: 140 389 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3744 serial:
Debug: 141 392 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3748 serial:
Debug: 142 394 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374b serial:
Debug: 143 398 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374d serial:
Debug: 144 401 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374e serial:
Debug: 145 405 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x374f serial:
Debug: 146 407 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3752 serial:
Debug: 147 410 stlink_usb.c:2831 stlink_usb_open(): transport: 4 vid: 0x0483 pid: 0x3753 serial:
Error: 148 434 stlink_usb.c:2848 stlink_usb_open(): open failed
Debug: 149 438 hla_layout.c:47 hl_layout_open(): failed
Debug: 150 441 command.c:628 run_command(): Command 'transport init' failed with error code -4
User : 151 445 command.c:694 command_run_line():
Debug: 152 446 command.c:628 run_command(): Command 'init' failed with error code -4
User : 153 449 command.c:694 command_run_line():
Debug: 154 450 target.c:2172 target_free_all_working_areas_restore(): freeing all working areas
Debug: 155 454 hla_interface.c:117 hl_interface_quit(): hl_interface_quit

Okay so in none of these cases was there even a connection established to the USB Device “ST Link”. It’s not failing on the “connect to chip” part since it’s not even getting there.

The STLink USB device can only be claimed by one program (if special “shared STLink” hacks aren’t used). Having another program open that is attempting to use the STLink or holding some handle to it will definitely cause OpenOCD to not find the device.

As a sanity check, you can also not flash in PlatformIO after you re-logged into your user account and VSCode with PlatformIO is the only active program?

If so, then the only explanation I know and have seen is per (SOLVED) Cannot Upload to STM32F103 "BluePill" using ST Link on Nucleo Board - #27 by maxgerhardt. If STM32CubeProgrammer could access the USB device but OpenOCD cannot, it is as driver issue. Uninstall all ST-Link drivers in the device manager (you might possibly have to uninstall software like ST-Link Utility and STM32CubeProgrammer too) until the ST-Link shows up as an unknown device in the device manager again. From there grab the latest copy of ST-Link Utility and let it install along with the drivers. Now again with all other programs closed, try uploading.

If that still does not work, use https://zadig.akeo.ie/ to load WinUSB (or libusb-win32) drivers for the ST-Link USB device and retry.

grafik