PlatformIO Community

Difficulty with getting USB serial [USB CDC] working

I can not seem to get USB serial [USB CDC] working on either a STM 32 Bluepill or Nucleo F767ZI. I can get the USB CDC to workly using the STCUBEMX and TrueStudio tool chain on both devices but not under arduino ststm32. I have tried with latest standard STM32 package and the developmental package on GIT [changing the platform = line].

I have added build flags in Platformio.ini (for the Nucleo F767ZI):

build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE

I get the same results with/without these flags, when I plug in the USB, I get no response on the windows PC with the Nucleo board and a USB device unrecognized error on BluePill.

I am not sure what I am missing here. Can someone help me out?

Thanks,

Tom

I will also add that using the Arduino IDE, I immediately got the Serial over USB [USB CDC] to work on the STM32 Bluepill. How do I get this to work under the PlatformIO IDE?

Tom

What exact platformio.ini are you using for the bluebill board? It might use the Maple core and not the STM32 core, which needs different flag.s

This is the contents of my platformio.ini:

[env:bluepill_f103c8]
platform = ststm
board = bluepill_f103c8
framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_FULLMODE

I also tried with:
platform = https://github.com/platformio/platform-ststm32.git

Actually I found a typo in the previous message:

Platformio is:

[env:bluepill_f103c8]
platform = https://github.com/platformio/platform-ststm32.git
board = bluepill_f103c8
framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED

I also tried without success:

build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE

PlatformIO’s build script for activating USB serial support seems really broken right now. It’s missnig needed flags like USBD_VID, USB_MANUFACTURER, USB_PRODUCT, USBCON and HAL_PCD_MODULE_ENABLED.

Regarding high-speed (HS) mode: The bluepill only supports the lesser Full-Speeed (FS) standard. Activating PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED will cause it to try HS which it doesn’t have, and PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE will cause it to put its HS peripheral into FS mode, which it doesn’t even have in the first place, so both macros must be omitted.

Can you test on your bluepill if this works? Baud rate for the CDC should be 115200.

main.cpp

#include <Arduino.h>

void setup(){
	//activate USB CDC driver
	SerialUSB.begin();
}

void loop() {
	SerialUSB.println("Hello world");
	delay(1000);
}

platformio.ini

[env:bluepill_f103c8]
platform = https://github.com/platformio/platform-ststm32.git
board = bluepill_f103c8
framework = arduino
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
3 Likes

Yes, that new configuration for platformio.org fixed the problem. Thanks! I hope that the original build script will get corrected at some point.

Tom

1 Like

The same problem seem to appear when using the original “Roger Melbourne” (derived from leaflabs)-core.

When using this in platformio.ini:

board_build.core = maple

the same thing seems to happen. The bluepill’s USB does not change from “bootloader” to “serial port”.
A funny detail: if you disable the libUSB device (maple 003) in the device manager and reactivate it after that, then the board activates the virtual serial port.

1 Like