Difficulty with getting USB serial [USB CDC] working

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

1 Like