Skip to main content
Visitor II
August 21, 2020
Question

Problem with USB Virtual Com Port STM32f103c8t6

  • August 21, 2020
  • 6 replies
  • 1421 views

I am trying to send data to the console using the "echo" method.

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

{

 CDC_Transmit_FS(Buf,*Len);

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

 USBD_CDC_ReceivePacket(&hUsbDeviceFS);

 return (USBD_OK);

}

I pass a random value but I see a doubled value in the terminal.

0693W000003Q1RHQA0.png

How can I fix it?

    This topic has been closed for replies.

    6 replies

    AKova.2Author
    Visitor II
    August 21, 2020

    Another terminal program works correctly.

    0693W000003Q25vQAC.png

    Apparently the problem is in the program settings, but in which ones?

    I kind of tried all the settings.

    AKova.2Author
    Visitor II
    August 22, 2020

    If I transfer to the port in this way

    uint8_t str[11] = "Hello STM32";

    void StartDefaultTask(void *argument)

    {

     MX_USB_DEVICE_Init();

     for(;;)

     {

    CDC_Transmit_FS(str,11);

      osDelay(5000);

     }

    }

    it's ok.

    0693W000003Q2ogQAC.png

    I don’t understand anything. Where to look for a problem in the terminal program or in the microcontroller code?

    Graduate II
    August 22, 2020

    Double text is shown because the particular terminal has "local echo" turned on. Typically it should be turned off and only received text should be displayed. Tera Term and Putty are the industry standard and probably the best terminals.

    Also Telnet protocol has an ability to negotiate echoing on remote side:

    https://tools.ietf.org/html/rfc857

    AKova.2Author
    Visitor II
    August 22, 2020

    That is, if I transmit data in this way

    uint8_t str[11] = "Hello STM32";

    void StartDefaultTask(void *argument)

    {

     MX_USB_DEVICE_Init();

     for(;;)

     {

    CDC_Transmit_FS(str,11);

      osDelay(5000);

     }

    }

    then there is no echo in all programs. And if I send data immediately in the receive function (callback)

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

    {

     CDC_Transmit_FS(Buf,*Len);

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

     USBD_CDC_ReceivePacket(&hUsbDeviceFS);

     return (USBD_OK);

    }

    then the echo turns on?

    There is no logic in this.

    Graduate II
    August 22, 2020

    "Local echo" means that the application just printed out the text you sent from the application. And after that it also printed the text it received from the remote device, which in this case is just a mirror.

    AKova.2Author
    Visitor II
    August 22, 2020

    Got it.

    But that wasn't the problem.

    The point is that I am writing a program to transfer data from a controller to a computer via USB. And by chance I wrote the write() function twice in the data transfer procedure. My fault.

    But I was misled by the fact that the Terminal program for some reason printed a single value instead of a double one.

    The problem has been resolved.

    The question is closed