Error while trying to upload code to BluePIll [SOLVED]

Hi, I’m having problems when loading the code in the BluePill … reading in this forum I found a possible solution provided by @manuelbl that consisted in adding this line ( upload_flags = -c set CPUTAPID 0x2ba01477 ) in the platformio.ini but instead of fixing it, what happens is that I get a different error.

Do you know what to do to solve this problem?

Thanks in advance for the help :slight_smile:


This is my platformio.ini file:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477

This is the output i get:

Uploading .pio/build/bluepill_f103c8/firmware.elf
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-12:31)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

0x2ba01477
hla_swd
none separate

Error: jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Error: mem2array: Read @ 0xe0042004, w=4, cnt=1, failed
Error executing event examine-end on target stm32f1x.cpu:
/Users/Jorge/.platformio/packages/tool-openocd/scripts/mem_helper.tcl:6: Error: 
in procedure 'program' 
in procedure 'ocd_process_reset' 
in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 279
in procedure 'mmw' called at file "/Users/Jorge/.platformio/packages/tool-openocd/scripts/target/stm32f1x.cfg", line 81
in procedure 'mrw' called at file "/Users/Jorge/.platformio/packages/tool-openocd/scripts/mem_helper.tcl", line 36
at file "/Users/Jorge/.platformio/packages/tool-openocd/scripts/mem_helper.tcl", line 6
embedded:startup.tcl:521: Error: ** Unable to reset target **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 558
at file "embedded:startup.tcl", line 521
*** [upload] Error 1
====================================== [FAILED] Took 2.61 seconds ======================================
The terminal process "plat

And you did this because you got an “unexpected ID code, expected 0x1ba01477” error before that?

What marking is on the chip? GD32F103C8T6?

Are you testing this with a blink sketch?

Does it help if you press down the reset button, press the upload button, then release the reset button once OpenOCD has started up? (Timing can be tricky)

Hi @maxgerhardt thanks for your quick answer :))

I am trying to upload a simple blink example. My MCU It supposed to be an original STM32F103C8T6 … but since I bought it at AliExpress … not fully confident about it.

I tried to press reset button before uploading the code but it seem to make no effect.

This was the platformio.ini file that was originally using:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino

And this was the error message that I was obtaining:

CURRENT: upload_protocol = stlink
Uploading .pio/build/bluepill_f103c8/firmware.elf
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-12:31)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
none separate

Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1
====================================== [FAILED] Took 2.62 seconds ======================================
The terminal process "platformio 'run', '--target', 'upload', '--environment', 'bluepill_f103c8'" terminated with exit code: 1.

``

Yes no doubt you got a clone chip which is actually GigaDevice GD32F103C8.

Weird I have a clone chip too and it has no problem being programmed via an STLink with that upload_flags addition.

Could you please try and download STM32CubeProg - STM32CubeProgrammer software for all STM32 - STMicroelectronics (needs STM account) and connect to the chip?

This works even for clone chips (I have a GD32F303CC here)

If it can connect it’s a problem with OpenOCD.

You may e.g. try to a mass-erase on the device (second green icon on the left) and see if that helps.

1 Like

Hi @maxgerhardt

As it failed me when trying to connect with STM32CubeProg and I have more than one unit from the same batch, I have tried with a different unit and I have been able to connect :slight_smile: then I tried with platformOI and the problem was solved … so I guess the problem was the problem was in the MCU … let’s see when the global shortage of semiconductors ends … using bad quality components sucks.

Thank you very much for your help :))