Difficulty with getting USB serial [USB CDC] working

Can you link said Blackpill F411 board?

PlatformIO already supports a board with a STM32F411CE chip: 96Boards Neonkey — PlatformIO latest documentation.

I have the STM32F411 Core Board WeAct V2.0

1 Like

This board was added in the latest Arduino-STM32 release 16 days ago in version 1.9.0 as “STM32F411CE WeAct Black Pill” (GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino), the latest for PlatformIO is 1.8.0 however (Releases · platformio/platform-ststm32 · GitHub).

You can either wait a bit until PlatformIO updates its packages or follow workarounds like using upstream stm32 arduino core · Issue #389 · platformio/platform-ststm32 · GitHub in order to get compilation working. You’d also need a new custom board. So I’d rather recommand waiting a bit or using the Arduino IDE in the meantime.

That’s true, Arduino IDE got the 1.9 update and only then the board was available.
Thanks for the help.
:+1:

Hi , i have some problem with PIO USB serial Programming . after change boot loader i can just programing with Arduino IDE , here is my board configuration . and all the time i have some error
PORT

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = hid
upload_port = /dev/cu.usbmodem14C01

thx

  1. This seems different from what’s being discussed in this topic (transmitting serial data from an STM32 Arduino board via the USB serial)
  2. please open a new topic with the full error message

I have the same problem, usb serial not working with bluepill.

It compiles fine and the serial port shows on the PC but no data is sent.

It works fine with maple core.

Here’s the platformio.ini:

[env:STM32F103C8]
platform = ststm32
board = genericSTM32F103C8 ; 64K
; board = genericSTM32F103CB ; 128K
; board_build.core = maple
framework = arduino
upload_protocol = stlink
debug_tool = stlink

build_flags = 
  -ggdb
  -D USBCON
  -D USBD_USE_CDC

SOLUTION FOR CS32F103 (So that this MCU can upload sketcks and activate the serial monitor by USB):

[env:bluepill_f103c8_128k]
platform = ststm32
framework = arduino
board = bluepill_f103c8_128k
upload_protocol = stlink
upload_flags = -c set CPUTAPID 0x2ba01477
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
3 Likes

I started recently to use stm32duino and platformio for fast prototyping on small projects.
This solution allowed me add USB/serial support on my devices. :+1:

IMPORTANT NOTE: To receive data on PC I needed to enable DTR signal (Data Terminal Ready). Handshaking (flow control) does not need to be activated.

1 Like

Hi there, I’m trying to get serial monitor communication with blackpill stm32f411 via the USB cable, but I don’t know how to proceed, is there a ‘how to’ guide for that?
this is my current platformio.ini:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = arduino
upload_protocol = dfu

what else do I need to add?
thanks in advance

Have you not tried adding

build_flags = 
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D USBCON
monitor_dtr = 1

and SerialUSB.begin(); in the code?

1 Like

Thanks a lot, just tried that,
after uploading I click on the platformio serial monitor icon and I get this:

> Executing task: platformio device monitor <

--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters

--- Available ports:
---  1: /dev/cu.Bluetooth-Incoming-Port 'n/a'
---  2: /dev/cu.MacBookProdeManuelDiego 'n/a'
---  3: /dev/cu.serial0      'n/a'
--- Enter port index or full name: 3
--- forcing DTR active
--- Miniterm on /dev/cu.serial0  9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

I selected option 3, don’t see any message there. I have this in the loop:

SerialUSB.println("Hello!");
  delay(1000);

Maybe you’re running into `while (!Serial);` hangs on Swan R5 with `CDC (generic 'Serial' supercede U(S)ART)` · Issue #1672 · stm32duino/Arduino_Core_STM32 · GitHub. Try adding SerialUSB.dtr(false); at then end of setup() code. Also try removing monitor_dtr = 1 if that still does not work.

Continuing the discussion from Difficulty with getting USB serial [USB CDC] working:

I’ve tried that but no luck at the moment, was expecting a new port to appear in the ‘Available ports’ list of the serial monitor, is that what should happen?
I’m pretty lost to be honest,
Board is al Weact blackpill stm32f411, this is the sketch:

void setup() {
  SerialUSB.begin(9600);
  pinMode(PC13, OUTPUT);
  // SerialUSB.dtr(false);
}
void loop() {
  SerialUSB.println("Hello!");
  digitalWrite(PC13, HIGH);
  delay(1000);
  digitalWrite(PC13, LOW);
  delay(1000);
}

and this is the platformio.ini file:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = arduino
upload_protocol = dfu
build_flags = 
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D USBCON
monitor_dtr = 1

Indeed, but your previous list with

Made it seem like cu.serial0 was a new port?

Does the PC13 LED blink?

Does the same code work in the Arduino IDE?

3: /dev/cu.serial0 'n/a' is always there, same as the 1 & 2 ones,
the code is uploaded correctly and yes, the led blinks, plus I have already made some stuff with this board,
with the Arduino IDE I can’t upload anything to these boards

And youI’re definitely using this core? GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino

yes, I added that to Arduino, I have all stm32 boards listed etc but I couldn’t install the stm32cube programmer, so Arduino says “STM32CubeProgrammer not found (STM32_Programmer_CLI).”

It might be your operating system’s problem
In linux you need to load cdc-acm kernel module.
please check this link,
https://wiki.archlinux.org/title/arduino

I found a solution, thanks too all the above shares, actually.

Working:
DFU Upload
USB Serial
“Serial” automatically routed to USBSerial
TX/RX

Not Working:
After DFU Upload, I have to plug out and reinsert USB in order to see the virtual serial.

Notes:
Its not the regular Blackpill, its a custom board but should work with others having STM32F411xx at least or STM32F4xx hopefully.

[platformio.ini]
[env:genericSTM32F411CC]
platform = ststm32
board = genericSTM32F411CC
board_build.mcu = stm32f411ccu6
board_build.f_cpu = 108000000L
framework = arduino
upload_protocol = dfu
monitor_dtr = 1
monitor_port= COM19 ; needed. Cause after upload, my serial wasn’t getting enumerated untill I replug the USB connector.

build_flags =
-w
; enable USB serial
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USBD_PID=0x5740 ;copied from a device built using arduino
-D USBD_VID=0x0483
-D USB_MANUFACTURER=“STMicroelectronics”
-D USB_PRODUCT=“"STM Serial"” ; has no effect, apparantly