Cannot upload program on stm32 using stlink-v2

Hii,

I want to upload program on nucleo-l476rg using stlink-v2 programmer, Arduino framework and PlatformIO IDE. Program is not uploaded.
This is Platfromio.ini:
[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = arduino
lib_deps =
arduino-libraries/SD@^1.3.0
sstaub/Ticker@^4.4.0
STM32RTC
ArduCAM
upload_protocol = stlink

I get following error:
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
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: target voltage may be too low for reliable debugging
Error: timed out while waiting for target halted
embedded:startup.tcl:1516: Error: ** Unable to reset target **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1553
at file “embedded:startup.tcl”, line 1516
*** [upload] Error 1

How to solve the above error?

Hi @sana_m and welcome to the PlatformIO Forum!

When posting code or logs, please use the pre-formatted text feature.
This increases the readability of your post and the likelihood that someone help you.

Thank you very much.

I want to upload program on nucleo-l476rg using stlink-v2 programmer, Arduino framework and PlatformIO IDE. Program is not uploaded.
This is Platfromio.ini:

[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = arduino
lib_deps =
  arduino-libraries/SD@^1.3.0
  sstaub/Ticker@^4.4.0
  STM32RTC
  ArduCAM
upload_protocol = stlink

I get following error:

xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
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

[stm32l4x.cpu] halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x08006158 msp: 0x20018000
Error: timed out while waiting for target halted
embedded:startup.tcl:1516: Error: ** Unable to reset target **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 1553
at file "embedded:startup.tcl", line 1516
*** [upload] Error 1
1 Like

Please create a new project that doesn’t use any libraries and just does a blinky as src/main.cpp. Check if you can upload again.

If needed, hold down the RESET button of the Nucleo before uploading, then press upload, then release the button after openocd has started up.

Failure to upload can occur for example because the sketch you upload is immediately crashing or uses the SWD pins (PA13 and PA14 I think).