Skip to main content
Visitor II
November 10, 2021
Question

virtual com problems with STM32L4P5VGT6

  • November 10, 2021
  • 3 replies
  • 1118 views

Hi,

I prototype the use the USB virtual com port on a STM32F407 Discovery board and

it worked without any problem. I then repeated the exercise on our custom board

(STM32L4P5VGT6), the first stage was just transmitting it worked without a

problem. Now adding the exactly the same code for receiving I used on the

STM32F407 board, when the USB cable is plugged in the USB is enumerated

correctly under Windows 10, but I cannot connect to it with my terminal program.

It behaves same with different terminal programs and on different computers.

After a couple minutes Windows 10 reports a problem with the USB device just

plugged in.

The receiver I added is:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)

{

 /* USER CODE BEGIN 6 */

 USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);

 USBD_CDC_ReceivePacket(&hUsbDeviceFS);

 memset (USBrxbuffer, '\0', 64); // clear the buffer

 rxlen = (uint8_t)*Len;

 memcpy(USBrxbuffer, Buf, rxlen); // copy the data to the buffer

 memset(Buf, '\0', rxlen); // clear the Buf also

 USBrxlen = rxlen;

 USBrxflag = true;

 return (USBD_OK);

 /* USER CODE END 6 */

}

The code works fine with STM32F407. I am clearly missing something, any

suggestions will be greatly appreciated. I used the defaults in CubeMX pretty

much, USBD_SELF_POWERED is enabled.

Kind Regards

Mike Zomo

    This topic has been closed for replies.

    3 replies

    Super User
    November 10, 2021

    Search these forums for "CDC_SET_LINE_CODING" or "VCOM". That functionality historically wasn't part of the ST provided USB CDC code. It certainly wasn't the last time I started an L4cxx project ( > 1 year ago). There are several threads that show how to fix this.

    kweisi50Author
    Visitor II
    November 10, 2021

    Hi Bob,

    Thanks for you r reply, I will check it out.

    Kind Regards

    Mike Zomo

    Visitor II
    February 6, 2023

    a) Create a fresh STM32F407 project, then compare that to the working STM32F407 to see all the places the code was modified, maybe something didn't get included in the STM32L4P5VGT6.

    b) Ensure USB Init: MX_USB_DEVICE_Init();

    c) Is USB clock 48MHz?

    d) Patch for VCP, tell the PC what UART config is, even when baudrate not actually used.

    static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)

    {

    /* USER CODE BEGIN 5 */

    // Library modified based on forum response from tsuneo

    // https://community.st.com/s/question/0D50X00009XkgIYSAZ/unable-to-configure-serial-port-error-for-usb-cdc

    switch(cmd)

    {

    // Line coding settings for {115200bps, 1stop, no parity, 8bit}

    // Stores settings requested by the terminal program, preventing connection errors

    static uint8_t lineCoding[7] = {0x00, 0xC2, 0x01, 0x00, 0x00, 0x00, 0x08};

    case CDC_SEND_ENCAPSULATED_COMMAND:

    break;

    case CDC_GET_ENCAPSULATED_RESPONSE:

    break;

    case CDC_SET_COMM_FEATURE:

    break;

    case CDC_GET_COMM_FEATURE:

    break;

    case CDC_CLEAR_COMM_FEATURE:

    break;

    case CDC_SET_LINE_CODING:

    memcpy(lineCoding, pbuf, sizeof(lineCoding)); // Store line coding settings

    break;

    case CDC_GET_LINE_CODING:

    memcpy(pbuf, lineCoding, sizeof(lineCoding)); // Return line coding settings

    break;

    case CDC_SET_CONTROL_LINE_STATE:

    break;

    case CDC_SEND_BREAK:

    break;

    default:

    break;

    }

    return (USBD_OK);

    /* USER CODE END 5 */

    }

    e) Optional: In MX you can also modify:

    • Middleware->USB_DEVICE->Device Descriptor
      •  PRODUCT_STRING
      • MANUFACTURER_STRING

    Paul