Virtual COM failing with pyserial/Linux, but working otherwise
Question: I am using Virtual COM Port (VCP) example code from
<http://blog.memsme.com/stm32f4-virtual-com-port-2/> on STM32F4 Discovery
Board to have USB VCP. This code is originally by ST and used by many other
people in their projects

Communication with the STM32F4 over VCP works fine from Windows. In Linux
(Ubuntu 12.04 x86), if I send data to the port with

    
    
    echo "aasfg" > /dev/ttyACM0
    

then, the MCU gets the data and everything works fine. I can receive the
continuous data stream with

    
    
    cat /dev/ttyACM0
    

However, if I send data with the simple Python script that uses pySerial

    
    
    import serial
    sercom = serial.Serial('/dev/ttyACM0')
    sercom.write('asdf')
    

then I stop receiving data with the _cat_ command, and following _cat_
commands also don't receive any data. The MCU is constantly executing some USB
interrupt routines, never returning to execute actual application code. I can
receive data from VCP again after re-plugging the device.

The STM32 USB VCP code is probably not perfect, but it is used by many other
people in many projects so it should be good enough. I am not able to debug
that code. I suspect that sending data with pySerial does something with the
port that the VCP driver (either on STM32 or PC) does not like and I would
like to track it down and hopefully still use pySerial.

I executed

    
    
    stty --file=/dev/ttyACM0 -a
    

before and after pyserial broke the communication. After breaking the VCP with
pyserial, setting _-clocal_ became _clocal_ and setting _min = 1_ became _min
= 0_. Are these relevant in VCP communication and could they hint how to fix
VCP with pySerial?


Answer: The serial port was actually fine. As I mentioned, the pySerial call changed
the port parameters. The param _min = 0_ meant that _cat /dev/ttyACM0_
returned immediately, reconfiguring to _min = 1_ with _stty_ made cat blocking
and outputted the data as before.

