STM32F103 Bluepill said upload is finished but program won't run

Hi I have been using Arduino IDE to program bluepill (STM32F103) using Roger Clarke’s repo GitHub - rogerclarkmelbourne/Arduino_STM32: Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards and it compiles, program fine with a ST-Link V2 dongle.

However when I switch to PlatformIO I cannot get the program to work, it saids upload is fine but the program appears not working in the MCU. (It is just a blinking sketch). Here is the output that saids it successfully programmed with openocd

Checking size .pio\build\genericSTM32F103CB\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.3% (used 1076 bytes from 20480 bytes)
Flash: [=         ]   5.4% (used 7032 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\genericSTM32F103CB\firmware.elf
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
debug_level: 1

[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080001a4 msp: 0x20005000
** Programming Started **
Warn : Adding extra erase range, 0x08001c9c .. 0x08001fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

I tried both configurations, the first one is - from what I heard - is official ST STM32duino library.

platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink
board_build.core = maple

The second one is Roger Clarke’s implementation.

platform = ststm32
board = genericSTM32F103CB
framework = arduino
debug_tool = stlink
upload_protocol = stlink
;upload_flags = -c set CPUTAPID 0x2ba01477

Both does not work. Going back to Arduino IDE it programs fine. For example in Arduino IDE:

Sketch uses 12916 bytes (19%) of program storage space. Maximum is 65536 bytes.
Global variables use 2064 bytes (10%) of dynamic memory, leaving 18416 bytes for local variables. Maximum is 20480 bytes.
STM32 ST-LINK CLI v3.3.0.0
STM32 ST-LINK Command Line Interface

ST-LINK Firmware version: V2J37S7 (Need Update)
Connected via SWD.
SWD Frequency = 4000K.
Target voltage = 3.3 V
Connection mode: Normal
Reset mode: Software reset
Device ID: 0x410 
Device flash Size: 64 Kbytes
Device family: STM32F10xx Medium-density

Loading file...
Flash Programming:
  File : C:\XXXXXXXXXX\arduino-sketch-91D7BEE80E204XXXXXXXXXXXXXX\sketch_jul11a.ino.bin
  Address : 0x08000000
Memory programming...
�������������������������������������������������� 0%
 0%����������������������������� 59%��������������������� 100%
Memory programmed in 1s and 0ms.
Programming Complete.

MCU Reset.

Application started.

What else can I do to help diagnose the cause? I am complete noob on bootloader and flashing to flash/ram but i am willing to learn.


Here is the code, FYI I have a LED at PA5 and I have also tried PC13 both does not work in PlatformIO but working in Arduino IDE.


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PA5, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PA5, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(PA5, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second

I have similar problem with him but mine works in Arduino IDE and is using PC13 as internal LED.

Just FYI Program uploaded but seems not running

So did you sanity check with the regular STM32 core, not the maple one? Your code can be the same.

platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink

Hi thanks for the reply! it is the same apparently. One thing I have noticed is in arduino IDE the def of e.g. PA5 is 5 but in platformio it is (((((0xC) + 1) + 1) +1) +1) + 1) as is 197?

I tried replace PA5 to int 5 it is the same, no blinking of the ide



Are you comparing apples to apples? The Arduino IDE with the core version 2.7.1 as well as PlatformIO with the latest platform-ststm32 and the above platformio.ini?

What is the text on the chip of your bluepill exactly? STM32F103C8? CB? C6?

The ST-Link is capable of debugging, too. Start a debug session in the Debug sidebar with a click on the Play button next to “PIO Debug”. Does it reach main()? Does it reach loop()? Does it hang up in some function? What is the call stack when you let it run and then press the pause button?

Hello, It successfully reaches loop() and doesn’t seems to hang up on some function.

The chip is C8T6 and I believe it is a legit one

I also spotted on a wrong config on [env:genericSTM32F103CB] it should be [env:genericSTM32F103C8] but it does not many any difference at all… hmm

So why are you blinking PA5 when the LED is on PC13?

Because I was reading this post and he said the internal LED pin in his bluepill is PB2 not PC13 and that is his reason for not working. So to isolate this I put a LED on PA5.

What if you upload

#include <Arduino.h>
#define LED PC13
void setup() {
  pinMode(LED, OUTPUT);

void loop() {
  digitalWrite(LED, HIGH);
  digitalWrite(LED, LOW);

with PlatformIO?

Yes it is working now! PC13 works now!!!

So what happen to PA5, not working still with PA5 hmmm…

PA13 have pin number 32 but why PA5 have hex value?

Or is there another way to define A5 pin on C8T6 in this environment?

“A5” is PA5. They just omit the P on the silk screen of the bluepill PCB to save space.

If you have an LED connected to PA5 and it didn’t blink, then check the polarity of the LED and the value of the resistor.

1 Like

Thanks it is working now, the resistor pops itself out so it opened circuit.

PlatformIO is more “bare metal” programming indeed… Frustrating at first but hopefully gets easier once one get used to it. Now I need USB COM port access for serial monitor, probably look for some article on how to do that :confused:

Every ST-Link V2 I’ve seen includes pins for UART RX and TX. When using genericSTM32F103C8, you will have the regular Serial object at TX = PA2. Hook that up to the ST-Link’s “RX” and you can print and use the serial monitor as normal.

Otherwise, to actiavte the USB CDC serial, you can also add

build_flags =

as documented. So, you can still flash (and debug!) via the ST-Link and just additionally connect a micro-USB to the bluepill to get the USB serial. (Careful to only use one source of power, e.g., the 3.3V pin of the STLink or the microUSB cbale).

And finally, you can use the Maple core and the USB bootloader still as normal. Note that Maple is severelly outdated by now, so I don’t recommend using it. E.g., flash via the ST-Link (flash address 0x8000000, start of flash). Then, use only the micro USB cable to the Bluepill and set upload_protocol = dfu in the platformio.ini. Upload and USB serial should now be via USB. You will not be able to debug with just the USB cable though.

Understood! thank you I shall use

build_flags =

for now :smiley: