5 months ago.

ST's USBSerial, Issue on Windows. Disco L476G

Question is related to the USB Serial library from ST for mbed. Compiled in System Workbench and GCC.

This is really spotty on my Windows 10 machine. The board is always recognized as a virtual serial port, but only about half of the time can I actually receive printf messages over USB. The other half of the time I get nothing. It can be working in TeraTerm and I disconnect and reconnect and I no longer get messages.

Is this an issue with the Windows 10 driver? Is there a Correct driver to use for the virtual serial port?

I tried it on another machine with ubuntu 17.04 and I can see the printf messages 100% of the time as I disconnect/reconnect.


Question relating to:

A world leader in providing the semiconductor solutions that make a positive contribution to people’s lives, both today and in the future.
Comment on this question

1 Answer

5 months ago.


For Windows 10, be sure that your DISCO FW version is 2.28.18


I feel like maybe my question was not understood. I am not asking about the mbed or STLink interface. I am asking about the USB interface on the target micro itself running in USBSerial mode.

/* ----- Includes ----- */
#include "mbed.h"
#include "rtos.h"

#include "USBSerial.h"

USBSerial usb_serial;

/* ----- Main ----- */
int main() {
    int i = 0;

    usb_serial.printf("--- START ---\r\n");

    /* ----- Main Thread Loop ----- */
    while (1) {

        usb_serial.printf("USB out. %d\r\n",i);
        printf("Reg printf out. \r\n");


I upgraded the STLink firmware as suggested, but there was no difference. Windows driver is USB Serial Device usbser.sys 10.0.14393.0

For reference I compiled an old project with #define MBED_LIBRARY_VERSION 118 , and USBSerial library from that era. This works as expected on Windows 10 with printfs always getting through. This is a nucleo_F401RE board. This was the USBDevice code version. I'm starting a large project, don't really want to go back to mbed 2.

Other thoughts? Thanks.

posted by Graham S. 19 May 2017

Maybe have a look there:

posted by Jerome Coutant 19 May 2017

I tried that mbed serial driver, same issue. Tried different cables, different ports. Installed a windows update. Issue is still there.

posted by Graham S. 19 May 2017

Running in Debug, the problem is in USBSerial.cpp. Value of terminal_connected is not following connection to PC terminal, causing _putc to return without even trying to send. When it detects terminal_connected it works as intended, but it is not always detecting the terminal connection.

int USBSerial::_putc(int c) {
    if (!terminal_connected)
        return 0;
    send((uint8_t *)&c, 1);
    return 1;

Then inside USBCDC.cpp using breakpoints inside USBCallback_request(void), its clear that teriminal_connected is not being set as it should. Negotiating the connection with windows is, more often than not, failing somehow. The callback function is called on every connect or disconnect but there is a logic problem somewhere.

posted by Graham S. 19 May 2017

For the record, I have something that is working now, but I don't exactly know why. System Workbench 1.14, mbed-os-5.4 #8d21974, USBDevice #4:50ec00A

It started working when I changed compiler optimization from -O0 to -01.

posted by Graham S. 22 May 2017

To post an answer, please log in.