PlatformIO Community

Blue Pill + USB Serial

“Blue Pill” plate (STM32F103C8)
VSCode, Platformio (Home 2.0.0, Core 3.6.4)
Simply sketch:

#include <Arduino.h>
void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println("+1");
delay(1000);
}

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

Сompiles, but Serial work not over USB, just two pins Tx, Rx (Expands to: Serial1). After plug-in USB in computer - “Unknown device”.
It happened after upgrade STM32 platform to 5.1.0 version. On v4.5.0 everything workd fine - appeared virtual COM-port over USB.
Unfortunately, even uninstall 5.1 and install 4.5 again - nothing compiling with numerous errors " duplicate ‘inline".

Can I fix this?

I,
i also have a bluepill board. When i connect usb to my win10 notebook i also have “Unknown device” error. I got working serial1, serial2, serial3 but can’t use USB.
Tried both latest stable and upstream platform with same result.
I even tried maple core (with no errors during compiling) but using it my test code don’t work at all.

I modified my bluepill with famous 1,5k resistor in place of 10k wrong one.

There is something wrong or missing?

[env:bluepill_f103c8]
; platform = ststm32          ; latest stable development platform
; platform = ststm32@~4.5.0   ; custom stable development platform
platform = https://github.com/platformio/platform-ststm32.git ; upstream development platform
; board_build.core = maple
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink
build_flags = 
 -D ENABLE_HWSERIAL2
 -D ENABLE_HWSERIAL3
 -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
 -D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED

My test code

#include <Arduino.h>

#define LED_BUILTIN PC13

void setup()
{
 pinMode(LED_BUILTIN, OUTPUT);
 Serial.begin(9600);
 Serial1.begin(9600);  
 Serial2.begin(9600);
 Serial3.begin(9600);
}

void loop()

{
 digitalWrite(LED_BUILTIN, 1);
 Serial1.println("Serial LED OFF");
 Serial.println("Serial zero LED OFF");
 Serial2.println("Serial DUE LED OFF");
 Serial3.println("Serial TRE LED OFF");

 delay(1000);

 digitalWrite(LED_BUILTIN, 0);
 Serial1.println("Serial LED ON");
 Serial.println("Serial zero LED ON");
 Serial2.println("Serial DUE LED ON");
 Serial3.println("Serial TRE LED ON");

 delay(1000);
}

Some bluepill boards are having wrong resistors on the USB lines preventing it from properly working: https://hackaday.io/project/24907-bicyclecompanion/log/61992-bluepill-and-its-annoyances

Either maple should work out-of-the box (with board_build.core = maple) or use the build_flags (and only that) from Difficulty with getting USB serial [USB CDC] working

1 Like

Ok, thank you!

Work for me with this (even using latest stable development platform):

build_flags =
   -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
   -D USBCON
   -D USBD_VID=0x0483
   -D USBD_PID=0x5740
   -D USB_MANUFACTURER="Unknown"
   -D USB_PRODUCT="\"BLUEPILL_F103C8\""
   -D HAL_PCD_MODULE_ENABLED

With this configuration i have errors when compiling (says something missing)

build_flags = 
	-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-D USBCON
	-D USBD_VID=0x0483
	-D USB_MANUFACTURER="Unknown"
	-D USB_PRODUCT="\"BLUEPILL_F103C8\""
	-D HAL_PCD_MODULE_ENABLED

My original post is missing USBD_PID (it’s also very old and was correct, at the time of posting), I’ve corrected it. The post I linked to directly had everything.

1 Like