Skip to main content
Explorer
December 10, 2020
Solved

(Solved) Can't transfer specific byte sequence over VCP

  • December 10, 2020
  • 4 replies
  • 1314 views

So far I have been using VCP in my project for about six months with no problems. But today I found it was not able to send a specific 'packet' of bytes.

Here is the SWV printf output from STM32CubeIDE:

Sending 10 bytes

 255

 254

 5

 0

 19

 0

 0

 0

 24

 106

Note the 19, which is the actual main content of the message. The first two bytes are a message header, last two bytes are a checksum.

Now here's what I receive on the computer (Fedora Linux, libserialport)

Read 9 bytes

  255

  254

  5

  0

  0

  0

  0

  24

  106

The 19 is missing. If I change it to 18 or 20 there is no problem, and I cannot find any other numbers which cause a problem, only 19. This is 100% repeatable, not an occasional problem.

I am sending using CDC_Transmit_FS which returns 0 (USBD_OK).

On the computer I'm using sp_nonblocking_read, which returns 9.

Docs for the libserialport function:

https://www.sigrok.org/api/libserialport/0.1.0/a00008.html#gad7fdeeacdef532f44185cc68e166d46b

Any tips for how to investigate this further? If it was a regular serial connection I could use my logic analyzer to look at the tx/rx wires directly, but is that possible with VCP?

    This topic has been closed for replies.
    Best answer by iforce2d

    Thanks for the fast (and correct!) replies.

    For those using libserialport, here is how this problem can be avoided:

    sp_port_config* config;
    sp_new_config( &config );
    sp_get_config( port, config );
     
    sp_set_config_xon_xoff( config, SP_XONXOFF_DISABLED );
    sp_set_config( port, config );

    4 replies

    Super User
    December 10, 2020

    19 = 0x13 is XOFF. You have set software handshake at some layer in Linux...

    JW

    Explorer
    December 10, 2020

    Unix/Linux terminals open by default in a terminal emulation mode, that interprets control characters and escape sequences.

    You need to switch it to "raw" to get all characters.

    Either use a teminal application that supports a raw mode, or modify the tty attributes in your own app, like here for example:https://forum.allaboutcircuits.com/threads/serial-port-terminal-raw-mode-in-c.169317/

    iforce2dAuthorAnswer
    Explorer
    December 10, 2020

    Thanks for the fast (and correct!) replies.

    For those using libserialport, here is how this problem can be avoided:

    sp_port_config* config;
    sp_new_config( &config );
    sp_get_config( port, config );
     
    sp_set_config_xon_xoff( config, SP_XONXOFF_DISABLED );
    sp_set_config( port, config );

    Visitor II
    December 10, 2020

    Hi,

    Can you please mark this question as solved ?

    Best Regards,

    Ons.

    iforce2dAuthor
    Explorer
    December 10, 2020

    I thought I already did (changed the title).

    Is there some other way to mark it that I should use?

    Visitor II
    December 14, 2020

    Hi,

    It is marked as solved now after you selected the answer as best.

    Thank you,

    Ons.