Configuring USB Serial For Marlin 2.0 and STM32F4

Please try a minimal Arduino sketch with USB serial first, as Marlin is huge and modifications to it might interfere with something else.

PIO knows 4 boards with the exact STM32F407VGT6 MCU already, I think you want to start from there ( black_f407vg, disco_f407vg, genericSTM32F407VGT6, diymore_f407vgt).

E.g., as platformio.ini:

[env:black_f407vg]
platform = ststm32
board = black_f407vg
framework = arduino
; uncomment to change upload protocol from stlink to dfu if needed
;upload_protocol = dfu
build_flags = 
	-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
	-D USBCON
	-D USBD_VID=0x0483
	-D USBD_PID=0x0003
	-D USB_MANUFACTURER="Unknown"
	-D USB_PRODUCT="\"black_f407vg\""
	-D HAL_PCD_MODULE_ENABLED

src\main.cpp

#include <Arduino.h>

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

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