2 years, 9 months ago.

USBSerial, Disco L476VG, Can't Send.

I'm using this library and mbed-os 5. Running Windows 10. https://developer.mbed.org/teams/ST/code/USBDEVICE/

I am trying to use CN7 on the Disco board for user USBSerial output. I have tried a lot of different things and the issue is always the same. Windows reliably sees the USB port in the device manager as COM5. But my terminal programs (using 3 different methods) cannot actually receive messages sent over the USB link from the mbed program. About one it ten times when I open the COM port to the board, the messages will show up. Once past that initial connection phase (opening COM port), the messages seem to get through. If I close the connection and reopen it, it stops working again. Also, I always seem to be able to send messages from terminal program to the mbed target reliably.

I have tried several versions of mbed os 5, including specifically 5.4.2 which is called out in the latest release of USBDEVICE library. Have tried online compiler and gcc offline in eclipse. The simplest program I can make still exhibits this problem.

For Windows 10 drivers I tried the Mbed Virtual Serial Port driver and USB Serial Device (Microsoft usbser.sys). And they both do the same thing. Is one or the other of these drivers recommended for the USBSerial library?

In the past I have used mbed 2 with a different USBSerial library and it worked fine. But I want to use mbed 5 with rtos features for this project.

Update 1: One problem seems to be when I open the COM port in say TeraTerm. USBCDC.cpp is expecting a bRequest == 0x22 (CDC_SET_CONTROL_LINE_STATE) with wValue == 1 in order to indicate terminal_connected. Monitoring the USB port on my PC, request 0x22 is never sent when a port is opened. It is sent when new device is connected and when port is closed. But when you open a port only requests 0x20 and 0x21 are sent (about ten total). It seems like the USB serial port driver, usbser.sys, is not sending the 0x22 Request that USBCDC library is expecting. Is usbser.sys supposed to send this request? Why isn't it?

Update 2: Tested on Nucleo F401RE board. USBSerial seems to work fine with this board. Problem seems to be specific to L476 board.

Anyone have any ideas?


#include "mbed.h"
#include "USBSerial.h"

DigitalOut led_green(LED1);

USBSerial usb;

int main()
    int i = 0;
    while(1) {
        led_green = !led_green;

1 Answer

2 years, 9 months ago.

Hello Graham,

I'm not sure it will solve the issue but there is an option to open a non blocking connection:

    //USBSerial usb;                                  // connection is blocked when USB is not plugged in
    USBSerial usb(0x1f00, 0x2012, 0x0001,  false);    // connection is not blocked when USB is not plugged in

Yes thanks for the idea, have tried this as well. This does not fix the issue. Even in blocking mode, it successfully unblocks when I plug the USB in. So that hasn't been the issue. The issue is that there is a variable terminal_connected, inside USBSerial.cpp that is not being set when the USB is plugged in. If this variable is not set the putc() function returns without even trying to write the character. If I skip this check inside putc(), I can reliably print characters out the usb as expected. But I am not sure what else I might break if I do this.

posted by Graham S. 27 Jun 2017