Factory Resetting my Blue Pill

Post here first, or if you can't find a relevant section!
Post Reply
Ooozair
Posts: 7
Joined: Fri Jan 15, 2021 5:24 pm

Factory Resetting my Blue Pill

Post by Ooozair »

Hey everyone, long time Arduino (ATMEGA328P) user, but first time STM32 user.

I picked up some STM32F103C8 Blue Pill's from Amazon, it's day 2 of using these guys. I'm literally a complete beginner, sorry if I ask any questions that seem obvious.

I was able to upload basic blink programs via ST-Link V2 using the arduino IDE and PlatformIO on VScode.

But, I wanted to read data from the Serial Port, so I tried installing the Roger Clark USB driver. I did this through STMCube32, and with an ST-Link V2.

That worked properly- I get the rapid flashing LED to indicate that the USB bootloader is installed. I installed the drivers for Windows, and when I plug into the USB port I see "Maple Serial" in my Device Manager.

Now, I've got problems.
I cannot upload any code to the device via the arduino IDE. I've tried all different upload methods. I see my COM port in the list (which I wasn't able to before). But, it's simply listed as "COM23", no "maple" indicators afterwards. I've tried uploading with all jumpers in different positions- no luck.

Ultimately- my end goal is: Upload programs via PlatformIO using ST-Link v2, but have access to the Serial Monitor vis USB as well. Worst case, I can read serial with a USB to Serial device too, but ideally I can use this USB port

But right now, I can't do anything with the device. Can't upload code, cant seem to figure out how to reset it. I CAN still connect to it via STlink and STMCube32, and can see all of the addresses and data, so I know I can reflash it, but what do I reflash it with? Is there a factory bootloader?. What do I do to get back to square 1 and try this again, back to uploading programs with ST-Link. And then, what steps do I need to take to get this working the way I want?

Thank you so much, I'm really lost at this point, and worried that I've bricked my device :(
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Factory Resetting my Blue Pill

Post by fredbox »

For new users, the recommended path is to use the official STM core. https://github.com/stm32duino/Arduino_Core_STM32

If you installed the Roger/Maple bootloader, your SWD pins used by ST-Link are likely disabled.
Try to upload a blink sketch using the ST-Link. Press reset, click upload, release reset.
For your application, you don't need any bootloader. I normally have both USB and ST-Link connected during development.

In the USB setting, select CDC generic serial. Then you should be able to use Serial.begin() and Serial.print() and it will print to the USB. The advantage to using the CDC serial port is that no special driver is needed.

This is all done with the standard Arduino IDE.

This is probably not the best resource for help with PlatformIO.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Factory Resetting my Blue Pill

Post by ag123 »

ok 1st things 1st.
if you install a sketch using st-linkv2 (e.g. adafruit original) - you don't need a *usb* boot loader. st-link v2 install your sketch (firmware) directly on the device (at 0x8000000)

a first sketch is to blink the led e.g.

Code: Select all

#include <Arduino.h>
bool flag = false;

void setup() {
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
	flag = ~flag;
	digitalWrite(LED_BULTIN, flag);
	delay(1000);
}
if LED_BUILTIN isn't defined you can try #define LED_BUILTIN PC13, that assumes your led is at and mapped on PC13 pin.

if you are using roger's bootloader, the normal way to install a sketch is to simply use a normal usb cable
and try clicking download when the fast blinks starts, select the correct upload method/tool

try getting the blink sketch to work by directly installing via st-link v2 (no additional usb boot loader), select the correct upload method / tool
then you can try the boot loader again using a usb cable. the main purpose of the usb (dfu) boot loader is so that it is possible to install a sketch using a usb cable without a st-link v2
Last edited by ag123 on Fri Jan 15, 2021 8:40 pm, edited 4 times in total.
Ooozair
Posts: 7
Joined: Fri Jan 15, 2021 5:24 pm

Re: Factory Resetting my Blue Pill

Post by Ooozair »

Uploading a blink sketch using ST-Link worked! Thank you for the tips regarding the reset button, I think improper use of that button was leading to me not being able to upload code.

Now I'm able to upload code no problem to the device. Unfortunately, USB serial monitoring still isn't working, but I can use a USB to Serial dongle and read directly from the TX1 and RX1 pins. In the end this will be sufficient.

ST-Link programming was important to me because I intend to put this chip onto my own PCBA, and I'd need access to program the device, and this ST-Link seemed like the best way to accomplish this.

Thanks everyone!
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Factory Resetting my Blue Pill

Post by ag123 »

on rogers (libmaple) core normally if you select the appropriate board (Generic STM32F103C series?)
Serial is usb-serial - it goes to the virtual comm port
Serial1 is uart1 - PA9 tx, PA10 rx- you can connect your usb-uart dongle there
Serial2 is uart2
etc

so

Code: Select all

Serial.println("hello");
would print to your virtual comm port console, this should come to the serial monitor
this (usb-serial) can be faster than typical baud rates e.g. 115200 on uart
usb-serial is really usb-cdc (acm), it is a direct usb-cdc link between the monitor (host) and mcu (e.g. stm32f103cx)
specs is full speed 12 Mbps, but typically, that can't be achieved, if you optimise it e.g. using block transfers etc you may get closer to 1 Mbps

one more hint for rogers (libmaple) core, look in where your core is installed
hardware/Arduino_STM32/STM32F1/STM32F1/boards.txt
build.cpu_flags=
should have
-DSERIAL_USB
for your board
Post Reply

Return to “General discussion”