Problems with UART on mbed framework

Hello there, I have a project that flashes fine from the mbed online compiler on my STM32L4 and F4 nucleo boards.
I wanted to move to using the PIO ide.
My config that Im running:
Windows 7
PIO ide v0.16.1
VSCode 1.24.1 (the current latest version)

One of the things that does not work from my project is the UART.
I can build and flash simple blinky programs just fine. so I know my setup is fine.

But as soon as I add this line,

Serial pc(USBTX, USBRX);

to a simple program it stops working entirely. But it it builds fine with no errors and uploads just fine as well. Just the application breaks.
I’ve added a pic of my output.
Any help on this problem would be greatly appreciated


What platformio.ini do you have exactly and what exact code are you running (minimal example)?

My platformio.ini file looks like this:
platform = ststm32
board = nucleo_l476rg
framework = mbed
upload_protocol = stlink

The following code does not run in PIO but runs from mbed online:

#include "mbed.h"

// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity


DigitalOut myled(LED1);

int main()
    int i = 1;
    pc.printf("Hello World !\n");
    while(1) {
        pc.printf("This program runs since %d seconds.\n", i++);
        myled = !myled;

Also, if I remove the serial related stuff it works fine. Even just leaving the line:
breaks the code as mentioned before.

This code looks perfectly fine to and I’m using the same type of code. Can you download HTerm.exe and open your COM-port to 9600 baud and see if really nothing arrives? HTerm - der-hammer

Hi, an update, I’ve tried a few terminal programs to no avail. I have it working now but a bit of confusion on my part.
So it seems this line:
upload_protocol = stlink
Allows me to upload. I had newly added that line when I posted my platformio.ini above and still had some problems for a while after making the change. But it started working after that. My relief and joy from getting something working out of this overshadows my slight frustration over why the mbed upload protocol doesn’t work, so I won’t complain too much.

So if anyone’s having trouble flashing mbed programs using PIO. Maybe substituting
upload_protocol = mbed for upload_protocol = stlink will help you as well.