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?