Page 1 of 1

USB virtual com-port for Blue Pill

Posted: Wed Mar 01, 2023 7:47 pm
by ogogon
Colleagues, tell me, please, is it possible now, using stm32 duino, to use a virtual com port via USB in Blue Pill module?
I mean not for programming, but for connecting my program in BP with a computer.

I couldn't find an answer to this question in the FAQ, so I'm asking here.
Thanks in advance for your reply,
Ogogon.

Re: USB virtual com-port for Blue Pill

Posted: Thu Mar 02, 2023 1:11 am
by dannyf
Don't have the answer. But can give you a way to get to it.

1. Does it have the USB pins routed out to the USB connector? I think yes

2. Does it have the right usb signaling? I think the answer is no.

3. Does it have the right software? Only you can answer.

Re: USB virtual com-port for Blue Pill

Posted: Thu Mar 02, 2023 2:07 am
by ogogon
dannyf wrote: Thu Mar 02, 2023 1:11 am Don't have the answer. But can give you a way to get to it.

1. Does it have the USB pins routed out to the USB connector? I think yes

2. Does it have the right usb signaling? I think the answer is no.

3. Does it have the right software? Only you can answer.
I'm sorry, but your answer is very epic, it is even very poetic, but it is completely incomprehensible.
I would say that it is reminiscent of canson from the golden age of the troubadours.
However, alas, the Blue Pill module is by no means a Beautiful Lady...

1. The Blue Pill module has a USB controller, its signals are output to the USB-micro connector and to the common board connector (pins A11 and A12).
2. Why did you decide that this connector does not have the right USB signaling? What do you mean? I have never used this connector, but I know that one way to program the module is through it. That is, the connector is working successfully.
3. I don't really know the answer to my own question. That is why I asked him. And really, I'm not counting on hints and omissions, but on a direct answer to the essence of the issue.

Ogogon.

Re: USB virtual com-port for Blue Pill

Posted: Thu Mar 02, 2023 3:30 am
by ag123
with STM core to use the USB (virtual) com port, you need to compile your sketch with USB (CDC) Serial selected.
then you can use a sketch as like

Code: Select all

void setup() {
	Serial.begin();
	while(!Serial);
}

void loop() {
	println("hello world");
	delay(1000);
}
virtual com port is Window's notion of a 'com:' port that is other than the original RS-232 hardware.
but that practically, a virtual 'com:' need not even have a hardware at the other end, it is a software implementation. (but that is a Windows matter, out of scope )

Re: USB virtual com-port for Blue Pill

Posted: Mon Mar 06, 2023 2:36 am
by ogogon
ag123 wrote: Thu Mar 02, 2023 3:30 am with STM core to use the USB (virtual) com port, you need to compile your sketch with USB (CDC) Serial selected.
then you can use a sketch as like
Thank you very much for the answer!

Did I understand you correctly - if I specify the "USB (CDC) Serial" setting, then I do not need to do anything else?
The compiler itself replace the hardware com port with a USB solution?

But how can I then, in the same program, use the physical com-port if the need arises?
ag123 wrote: Thu Mar 02, 2023 3:30 am

Code: Select all


void setup() {
	Serial.begin();
	while(!Serial);
}
void loop() {
	println("hello world");
	delay(1000);
}
I would like to clarify two points.

1. What does the program line "while(!Serial);"? Is it waiting for the end of port initialization?
2. Isn't it necessary to write "Serial.println("hello world");"?
ag123 wrote: Thu Mar 02, 2023 3:30 am virtual com port is Window's notion of a 'com:' port that is other than the original RS-232 hardware.
but that practically, a virtual 'com:' need not even have a hardware at the other end, it is a software implementation. (but that is a Windows matter, out of scope )
Fortunately, I have never used Microsoft Windows in my life...

Re: USB virtual com-port for Blue Pill

Posted: Mon Mar 06, 2023 6:12 am
by ag123
you can skip that

Code: Select all

while(!Serial);
it waits for the host to connect.

these days practically 'everything' is 'virtual' com ports, in Windows that is. USB isn't RS232 and it doesn't have any of the signals that is used in RS232.
at usb full speeds it is 12 Mbps (but this did not account for all the framing overheads etc) and that due to USB multiplexing, you won't get a straight 12 Mbps, that 12 Mbps is shared by all the devices and hubs connected. so if there is 6 of them (internal root hub, keyboard, mouse, etc), you get at most 12/6 ~ 2 Mbps at best. practically, every unused USB port is counted as well, so if a PC has say 6 of them, 2 Mbps is 'very optimistic'.

this is dramatically different from those 'Uno' style boards as stm32 do *real* USB, not a 'crippled' usb tethered over a usb-uart dongle or chip.
stm32 can be turned into a HID device (keybaord, mouse, joystick, MIDI etc), or just about any USB device (USB mass storage, USB ethernet, USB wifi, etc. ). But it takes one's own technical prowess to get there. The 'default' setup (in stm32duino) only includes mostly USB (CDC) Serial.

as for uart on chip in the stm32. normally, those can be selected from the menu, e.g. to have them as Serial1, Serial2 etc so that Serial can be used for USB (CDC) serial.

Re: USB virtual com-port for Blue Pill

Posted: Mon Mar 06, 2023 4:00 pm
by GonzoG
There is no COM port on STM. COM ports are on PC.
You have USB CDC (using virtual COM port on PC) or UART (not a COM, it's a simple serial interface).

If you enable USB CDC (generic Serial supersede U(S)ART) "Serial" will use USB and U(S)ARTs wall start with Serial1. https://github.com/stm32duino/Arduino_C ... wareserial

If you set CDC (no generic Serial), Serial will use first U(S)ART interface (usually it will be Serial1) and SerialUSB will be for USB CDC.