Cannot upload to STM32 Bluepill board over STLink-V2

Here’s a way to use a single .cfg for both types of mcus:

According to the docs it is possible to add more than one -expected-id argument. So just append this to the command line in stm32f1x.cfg:

swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID -expected-id 0x2ba01477

You can also add this to ‘platformio.ini’.

; set CKS mcu ID for knock off of STM chip
upload_flags = -c set CPUTAPID 0x2ba01477

BTW I have a dozen Blue Pills and the mcu cover appearance does not match the CPUTAPID. With Chinese manufactured BPs you have absolutely no idea of what your getting.

I’m still trying to figure out why USB Serial only work on some of them.

Regards,
John

2 Likes

Related to Flashing Bootloader for BluePill Boards · rogerclarkmelbourne/Arduino_STM32 Wiki · GitHub?

1 Like

maxgerhardt I’ve replaced the 10K with 1.5K on the boards without working USB cdc serial. It doesn’t fix the problem. They still don’t get recognized by the PC.

The few BPs that do work, work fine with 10K. That resistor signals that the USB device(BP) is a USB Full Speed device. I have removed the 10K resistor, leaving it open(infinite resistance) on working boards and they continue to work fine on an old machine running XP, a win7 desktop and a win10 notebook.

I plan to dump the contents of all the registers to learn what might be different. I have working usb serial on stm and cks devices as per their manufacturer ID, not the bogus cover marks.

Thank you very much! It worked perfectly for me!
My .ini file became this in my configurations:

[env:genericSTM32F103C8]
platform = https://github.com/platformio/platform-ststm32.git
board = genericSTM32F103C8
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
upload_protocol = stlink
upload_flags = -c set CPUTAPID 0x2ba01477
1 Like

I implemented all of the above , but still have problems on some combination of stlinkv2 and bluepills. I do however have three ‘golden base lines’ bluepils that work, but only on one PC setup, if you move only the USB cable to another PC, same setup, the ‘golden base lines’ is not golden any more. However they all work perfectly if I use stlink-util from STM, so the question is why not in platformio & openOCD. I first suggested it was a speed problem but it is not, the problem ‘move’ . The standard for platformio is

hla_swd
none separate

I tried to locate the ‘separate’ to change it to hardware reset but cannot find the option anywhere in stm32f1x.cfg.

Indeed the default is

reset_config srst_nogate

I first was under the impression I have the wrong file, but if I change the CPU ID from 0x1b to 0x2b … it does detect it, so do not understand why I have none separate

  1. How does one change this to use hardware reset?

ST stlink-utils only works well with the option hardware reset to connects.
Note : without the hardware mod I could not get ST stlink-utils to operate reliably…

Please update the cfg to cater for both the standard ST32F103 and Chinese ‘copies’ …not sure this works…

swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID -expected-id 0x2ba01477

This would solve a lot of trouble and save time waisted…
Thanks

I tried to read your post many time, but I couldn’t understand what can I do to solve this problem.

I solved the problem by adding the reset line from ST link to the blue-pill. It now works every time without any problem and by adding the CPU ID in the INI file, Thanks, appreciated.