Blue Pill serial via stm core does not appear to work

Hi, I'm using ST Core for the Blue pill. I use a stlink v2 to upload the sketch (I use arduino IDE). My sketch is here:


void setup() {
  Serial.begin(9600);
  Serial.println("ciao");
  delay(3000);
}
void loop() { }

Ofc I use the USB as a serial and my arduino ide can recognize the blue pill in the serial monitor when I connect it.
But it prints nothing.
Please do bear in mind that I have confirmed that the sketches can be uploaded and executed successfully (many times) but never needed serial support.
I also have the following sketch settings:

Board part number -> Blue Pill
U(S)ART support -> Enabled (generic Serial)
USB Support -> CDC (generic serial supersedes USART)
USB Speed -> Low/Full
Optimize -> smallest
Debug symbols -> no symbols
C Runtime -> Newlib Nano (default)

How can I diagnose and solve this?
Thanks

I believe that with USB support enabled, it will be the USB CDC connection that is called "Serial", and you'll have to find a different name for the USART Serial (probably "Serial1" ?)

Hello, and thanks for your answer!
Sorry for the newbieness, but I don't understand: isn't the USB CDC serial the one that prints in the serial monitor? I thought it was that way...

Ah. I misunderstood.
Insert a loop after your Serial.begin() - USB ports take some time to initialize:

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    delay(1);  // wait for USB to enumerate
  }
  Serial.println("ciao");
  delay(3000);
}

that's it. Very helpful, thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.