When I saw a Bluepill board for under two dollars, I simply couldn’t resist. I had to buy it even though I knew it was a clone so there were bound to be some issues eventually.
The first problem surprisingly wasn’t an issue with the board, but rather with the programmer / debugger I bought for working with it. It was sold as an ST-Link v2, so having no clue what to look out for, I just bought it. Well, turns out it was just an USB-to-TTL converter. That would probably be fine for programming the chip using its serial boot capability (I was still going to send a refund request as the description was clearly wrong), but my code wouldn’t run anyway, so unless I wanted to try to troubleshoot a problem I’ve never seen before on platform I’ve never used before, I had to get a debbuger to see what’s wrong.
Looking back, it is possible I didn’t notice the generated .bin files and tried to upload the .elf binary (thinking it would use the ELF section addresses to figure out where to flash the code). I’m pretty sure the flash utility didn’t complain (and actually printed success messages) though, which is odd given that the ELF binary is bigger than the chip’s flash.
A month had passed and the real(-ish) ST-Link v2 had finally arrived. I connected it to the board, plugged it into the USB port on my computer and ran st-probe. To my surprise, it recognized both the debbuger and the chip just fine, so I went ahead and tried to upload a PlatformIO example Blink project (the hello world program of Arduino world, the blinking LED) and finally ran into another issue.
OpenOCD (the flashing / debugging utility used by PlatformIO) complained about wrong
coreid - it expected to find a value of
0x1ba01477, but the chip reported
0x2ba01477. Given that the difference was just one hexadecimal digit, I was pretty sure this would be just a matter of forcing the software to accept the different
coreid and flash anyway.
Funnily enough, after a short Google search, I found out that I was correct for once. The solution was to add an
upload-flags variable to the target definition in
platformio.ini. The complete definition:
[env:bluepill_f103c8] platform = ststm32 framework = arduino board = bluepill_f103c8 upload_flags = -c set CPUTAPID 0x2ba01477
After this change, the board’s built-in LED started blinking, so I was all set to start writing my own code for the board.