By default, Serial
is the hardware UART (serial) coming out of PA9/PA10.
So, the default expects you to have a USB-to-UART adapter with at least common GND connected and the adapter’s RX connected to the Bluepills PA9 pin (labeled just “A9” on the board).
Of course, you are also able to take advantage of the USB peripheral in the bluepills’s chip. It can open its own USB-CDC interface on the USB port and shows up as a regular serial port on the computer.
To do that, you must
- Configure the compilation flags to enable the USB serial per Difficulty with getting USB serial [USB CDC] working - #6 by maxgerhardt
- Use
SerialUSB
instead ofSerial
in your code just to be sure, per exact code above - Remove the 3.3V connection between the ST-Link and the Bluepill
- Plug in the micro-usb cable into the Bluepill and your computer (it will now get its power via the USB cable with no risk of double-powering)
These configuration flags are also documented in
https://docs.platformio.org/en/latest/platforms/ststm32.html#stm32duino-configuration-system