Unable to upload code to stm32f411ceu6 via stlink

hello, i am unable to upload code to my stm32, i am using vscode and platformio and using stlink to connect the stm32 to my computer. Weirdly I was able to upload it the first time i plugged it in, but when i wanted to upload another bit of code it was unable to do it and spat out this error:
Warn : Cannot identify target as a STM32 family.
Error: auto_probe failed
embedded:startup.tcl:521: Error: ** Programming Failed **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 586
at file “embedded:startup.tcl”, line 521
*** [upload] Error 1

when I click the upload button this pops up on the bottom right of the screen too:
command ‘platformio-ide.upload’ was not found

not sure if it is important but the C13 LED on the stm32 stopped flashing after i uploaded the code too, it was blinking slowly before i uploaded anything but now it doesnt light up. any help would be greatly appreciated as i have been troubleshooting other problems and I would just like to sit down and get to coding lmfao. Thanks

What other extensions do you have installed in VSCode?

You’ve also connected the reset line between the STLink and the target bord?

other than platformio i have tabine and the synthwave color theme installed. also no i have not connected the reset pin to the stlink

Make sure you’ve switched to the right project using the new project selector (introduced since last version).

Can you connect the NRST line properly, then use “Build” and “Advanced → Verbose Uplaod” and upload the logs of the latter?

sorry, where is the advanced tab? i can only see these

See link I’ve posted before. It’s a project task in the PIO sidebar for the environment you’re working in.

ah! thanks! here is what it spat out:
PLATFORM: ST STM32 (8.1.0) > STM32F411CE (128k RAM. 512k Flash)
HARDWARE: STM32F411CE 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:

  • framework-arduinoststm32 4.10900.200819 (1.9.0)
  • framework-cmsis 2.50501.200527 (5.5.1)
  • tool-dfuutil 1.9.200310
  • tool-openocd 2.1000.200630 (10.0)
  • tool-stm32duino 1.0.2
  • toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 10 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    MethodWrapper([“checkprogsize”], [“.pio\build\genericSTM32F411CE\firmware.elf”])
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.7% (used 892 bytes from 131072 bytes)
    Flash: [ ] 2.7% (used 14116 bytes from 524288 bytes)
    .pio\build\genericSTM32F411CE\firmware.elf :

section size addr

.isr_vector 408 134217728

.text 12708 134218136

.rodata 1256 134230844

.ARM 8 134232100

.init_array 16 134232108

.fini_array 8 134232124

.data 152 536870912

.bss 740 536871064

.noinit 0 536871804

._user_heap_stack 1540 536871804

.ARM.attributes 48 0

.comment 102 0

.debug_frame 1320 0

Total 18306
([“upload”], [“.pio\build\genericSTM32F411CE\firmware.elf”])
AVAILABLE: blackmagic, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
openocd -d2 -s C:\Users\jonat.platformio\packages\tool-openocd/scripts -f interface/stlink.cfg -c “transport select hla_swd” -f target/stm32f4x.cfg -c “program {.pio\build\genericSTM32F411CE\firmware.elf} verify reset; shutdown;”
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
http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.139652
Info : stm32f4x.cpu: hardware has 0 breakpoints, 2 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x20020000 pc: 0x20020000 msp: 0x20020000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
** Programming Started **
Info : device id = 0x20020000
Warn : Cannot identify target as a STM32 family.
Error: auto_probe failed
embedded:startup.tcl:521: Error: ** Programming Failed **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 586
at file “embedded:startup.tcl”, line 521
*** [upload] Error 1

There are literally 0 google results for that.

Also the high clock speed seems weird.

What’s the exact platformio.ini?

Does something change when you do the following: Hold down the reset button, click on the upload button, when OpenOCD text shows up, release the reset button. The timing might be tricky though so give it a few tries.

this is what is in platformio.ini:
[env:genericSTM32F411CE]
platform = ststm32
board = genericSTM32F411CE
framework = arduino
upload_protocol = stlink
when i do what you said, it said it was a success but it said this(it looks different from the first time i uploaded):
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
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000de4 msp: 0x20020000
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

The upload worked. Then there seems to either be a problem with the reset line not being triggered properly or your firmware code messes with the SWD port.

What’s the exact code you’re running on it?

Is the firmware now reflashable again without holding reset?

this is the code i am running on it:

#include <Arduino.h>
const int PIN_RED = PA4;
const int PIN_GREEN = PA5;
const int PIN_BLUE = PA6;
void setup() {
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_GREEN, OUTPUT);
  pinMode(PIN_BLUE, OUTPUT);
}
void loop() {
  analogWrite(PIN_RED, 255);
  delay(1000);
  analogWrite(PIN_GREEN, 255);
delay(1000);
  analogWrite(PIN_BLUE, 255);
 delay(1000); 
  // put your main code here, to run repeatedly:
}

also no, i can’t get a successful upload without holding down reset

Yeah that code shouldn’t be able to cause such failure. The SWD pins are PA13 and P14 and you’re not using those.

Assuming you have NRST connected between the adapter and the target board, it’s weird.

Try different reset configuration commands for OpenOCD. Add to the platformio.ini

upload_command = $PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd $UPLOAD_FLAGS -c "program {$SOURCE} verify reset; shutdown;"
upload_flags =
    -d2 
    -s 
    $PROJECT_PACKAGES_DIR/tool-openocd/scripts 
    -f 
    interface/stlink.cfg 
    -c
    transport select hla_swd
    -f 
    target/stm32f4x.cfg
    -c
    reset_config none separate

And for the last line, try different values from STM32 + VS Code + mbed upload issue: Error: libusb_open() failed with LIBUSB_ERROR_ACCESS Error: open failed - #12 by maxgerhardt.

Hold up. My bad, I overlooked that. The version is old, from August last year. Current one is 12.0.0.

Please first update your Platform via PIO Home → Platforms → Updates or via a CLI and pio platform update ststm32

Then try and rebuild the firmware and upload it once via the reset-button trick, then retry if it still needs that.

If that didn’t help, you can try different reset configs per above.

hmm it still spits out the same error even after updating, i will try what you listed above, thanks for the help!! at least i now know a way of getting code uploaded!