cancel
Showing results for 
Search instead for 
Did you mean: 

How do I determine when Virtual Com Port is closed/opened in my STM32L476 firmware?

arnold_w
Senior

I'm working with the Nucleo-64 development board with an STM32L476 microcontroller and I'm using the USB source code that STM32CubeMX has generated for me. I want to be able to find out when the Virtual Com Port is closed/opened on the PC that the Nucleo-64 board is connected to. I've googled quite a bit, some suggests the condition is (Bool_t)(hUsbDeviceFS.ep0_state == USBD_EP0_STATUS_OUT), others suggest I should evaluate req->wValue inside the CDC_SET_CONTROL_LINE_STATE case statement in CDC_Control_FS. However, none of these methods work reliably for me. Can anybody please help me?

12 REPLIES 12

There seems to be a difference if I use Tera Term instead of my own C# application.

    case CDC_SET_CONTROL_LINE_STATE:
        LOG_STRING("\r\nhUsbDeviceFS.request.wValue: 0x");
        LOG_HEX((uint16_t)hUsbDeviceFS.request.wValue, 4);
        break;
    break;

When I connect in Tera Term, then I get this:

hUsbDeviceFS.request.wValue: 0x0003

When I disconnect in Tera Term, then I get this:

hUsbDeviceFS.request.wValue: 0x0002

However, I'm sure the customers will be disappointed if I ask them to upgrade firmware using Tera Term, where they would have to type in all the firmware bytes manually on the keyboard (or I guess they could speed it up a little by using copy-and-paste, but it's still a bit cumbersome).

> When I connect in Tera Term, then I get this:

> hUsbDeviceFS.request.wValue: 0x0003

> When I disconnect in Tera Term, then I get this:

> hUsbDeviceFS.request.wValue: 0x0002

That's DTR.

How Tera Term handles DTR may depend on its handhake settings. Try to play with handshake in the Serial setup.

You program should be able to change DTR, too.

> ask them to upgrade firmware using Tera Term, where they would have to type in all the firmware bytes manually

A relatively usual way to handle firmware update is using X/Y/ZMODEM, Tera Term speaks them all.

Also, Tera Term is scriptable, read its manual(s).

JW

gbm
Lead III

Then correct your application to handle DTE present correctly - it should set it after connecting/opening serial port and reset before disconnecting/closing serial port.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice