i did something like that with the 'old' 'rogers core'
https://github.com/rogerclarkmelbourne/ ... -w-signals
I made it listen for commands as well, using a "+++" (pause for 1/2 second) escape sequence.
if there is no pause before the next char, I assumed it is data.
works pretty well from a serial monitor
I actually once flashed updated a esp8266 AT rom doing just that with my 'blue pill uart dongle'
my guess is it is likely possible to port that to stm32 core. A catch is I hooked a usb callback to process usb requests.
e.g. things like setting baud rate etc. This is so that baud rates, line discipline (e.g. 8 N 1) can be passed from the serial monitor app directly to the uart.
one needs to figure out where to patch that same hook with the 'official' STM core.
--
as for USB CDC serial, you can try selecting that from the menu.
I think Serial would likely be replaced with USB CDC serial. Note that there are some complications as I think some stm32 soc has 2 usb interfaces, the default may go to the 'main' usb interface that is used for DFU updates.
An important concept is USB (CDC) serial is *not a uart*, baud rates etc don't apply, it is simply data at full speed 12 Mbps, but that it is multiplexed by the host, and pretty much every device gets a 1 ms time slice to 'talk' round-robin, again managed by the host via polling. The more devices on the bus (including the hubs (some are 'hidden')), the worse is the fragmented time slice, and hence lower multiplexed bandwidth available to your device. I tend to see about 1.x Mbps on my PC maximum.
then for the rest of uart ports they would likely need to be accessed from different names Serial1, Serial2, ... SerialLP1 etc