I have read through so many threads over the last few weeks and have still not been able to resolve this issue.
I am connected to a clone bluepill STM32F103C8 board with 128k using the attached STLINK SWD interface on a Nucleo F411RE development board. I am using 4 lines (3.3v, gnd, SWO, and SWCLK). I read another thread here where the OP had very similar issues to mine and they marked it solved based on wire length, but that is not the issue here. I shortened them to 3 inches and still have the same issue. Again, it works with other methods, just not VSCODE/PLATFORMIO.
Although I can successfully upload to my STM32F103C8 (128k) blue pill clone boards using Arduino IDE v1.88, I cannot using Platformio on VSCODE. I can also successfully communicate with the board using the ST-LINK Utility v4.0.0. I have not tried to upload the firmware using the ST-LINK Utility CLI or the GUI because I do not know how. I will humbly admit that there is a lot I have not looked at and tried, because I do not know where I can find a log of the upload handshake from the Arduino IDE, or what command line parameters to use with the CLI version. I have researched that also, but only today.
If anyone that has solved this can point me in the right direction, I would certainly appreciate it! I want to use VSCODE for ALL my work, and will be happy to put the Arduino IDE behind me. THANKS!
Here is what the ST-LINK Utility says…
16:40:45 : ST-LINK SN : 066CFF545753845187103146
16:40:45 : ST-LINK Firmware version : V2J35M26
16:40:45 : Connected via SWD.
16:40:45 : SWD Frequency = 4,0 MHz.
16:40:45 : Connection mode : Normal.
16:40:45 : Debug in Low Power mode enabled.
16:40:45 : Device ID:0x410
16:40:45 : Device flash Size : 128KBytes
16:40:45 : Device family :STM32F10xx Medium-density
If someone can direct me to where I can read up on how to get the output from the Arduino IDE then I will be happy to include that here as well.
The code I am uploading is a simple blink program.
#include <Arduino.h>
#define ledPin PC13 //13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(800);
digitalWrite(ledPin, LOW);
delay(40);
}
This application works as expected when compiled and uploaded using the Arduino IDE v 1.88. This also compiles without issue in Platformio on VSCode with no issues.
When I try to upload the code in Platformio on VSCode using the icon button (right pointing arrow), this is the output (the tail end of it).
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 4.1% (used 844 bytes from 20480 bytes)
Flash: [== ] 15.3% (used 10016 bytes from 65536 bytes)
.pio\build\genericSTM32F103C8\firmware.elf :
section size addr
.isr_vector 268 134217728
.text 8792 134217996
.rodata 1088 134226788
.init_array 16 134227876
.fini_array 8 134227892
.data 136 536870912
.bss 708 536871048
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
.noinit 0 536871756
Licensed under GNU GPL v2
For bug reports, read
._user_heap_stack 1540 536871756
http://openocd.org/doc/doxygen/bugs.html
.ARM.attributes 41 0
debug_level: 2
.comment 102 0
hla_swd
.debug_frame 1192 0
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Total 13891
Info : clock speed 1000 kHz
<lambda>(["upload"], [".pio\build\genericSTM32F103C8\firmware.elf"])
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Error: open failed
openocd -d2 -s C:\Users\Hop\.platformio\packages\tool-openocd/scripts -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32f1x.cfg -c "program {.pio\build\genericSTM32F103C8\firmware.elf} verify reset; shutdown;"
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked
*** [upload] Error 1
============================================================================================= [FAILED] Took 38.41 seconds =============================================================================================
The terminal process "C:\Users\Hop\.platformio\penv\Scripts\pio.exe 'run', '--verbose', '--target', 'upload', '--environment', 'genericSTM32F103C8'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
EDIT: I forgot to add what my platformio.ini has in it. Here it is.
[env:genericSTM32F103C8]
platform = ststm32
lib_extra_dirs = ~/Documents/Arduino/libraries
board = genericSTM32F103C8
framework = arduino
upload_port = COM4
debug_tool = stlink
upload_protocol = stlink